Пример #1
0
        private static Maybe <IList <Token> > TokenizeParam(EAParser p, IParamNode param)
        {
            switch (param.Type)
            {
            case ParamType.STRING:
                Token     input = ((StringNode)param).MyToken;
                Tokenizer t     = new Tokenizer();
                return(new Just <IList <Token> >(new List <Token>(t.TokenizeLine(input.Content, input.FileName, input.LineNumber, input.ColumnNumber))));

            case ParamType.MACRO:
                try
                {
                    IList <Token> myBody = new List <Token>(((MacroInvocationNode)param).ExpandMacro());
                    return(new Just <IList <Token> >(myBody));
                }
                catch (KeyNotFoundException)
                {
                    MacroInvocationNode asMacro = (MacroInvocationNode)param;
                    p.Error(asMacro.MyLocation, "Undefined macro: " + asMacro.Name);
                }
                break;

            case ParamType.LIST:
                ListNode n = (ListNode)param;
                return(new Just <IList <Token> >(new List <Token>(n.ToTokens())));

            case ParamType.ATOM:
                return(new Just <IList <Token> >(new List <Token>(((IAtomNode)param).ToTokens())));
            }
            return(new Nothing <IList <Token> >());
        }
Пример #2
0
 public bool Fits(IParamNode input)
 {
     if (input.Type == ParamType.LIST)
     {
         ListNode n = (ListNode)input;
         return(n.NumCoords <= numCoords);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        public void Set(byte[] data, IParamNode input)
        {
            IList <IAtomNode> interior = ((ListNode)input).Interior;

            int bitsPerAtom = Length / numCoords;
            int count       = 0;

            foreach (IAtomNode a in interior)
            {
                data.SetBits(Position + count, bitsPerAtom, a.CoerceInt());
                count += bitsPerAtom;
            }

            // NOTE: do we need this? a unit will always start filled with zeroes,
            // Setting zeroes here only matters if the code has overlapping parameters

            if (count != Length)
            {
                data.SetBits(Position + count, Length - count, 0);
            }
        }
Пример #4
0
 public bool Fits(IParamNode input)
 {
     return(input.Type == ParamType.ATOM);
 }
Пример #5
0
 public void Set(byte[] data, IParamNode input)
 {
     Set(data, input.AsAtom().FromJust.CoerceInt());
 }
Пример #6
0
 public static IParamNode Simplify(this IParamNode n)
 {
     return(n.SimplifyExpressions((Exception e) => { }));
 }