Exemplo n.º 1
0
        protected static string inspect(LithpPrimitive value)
        {
            if (value.LithpType() == LithpType.LIST)
            {
                LithpList list = (LithpList)value;
                if (list.Count > MaxDebugArrayLength)
                {
                    return("[" + list.Count.ToString() + " elements]");
                }
            }
            if (value.LithpType() == LithpType.DICT)
            {
                LithpDict dict = (LithpDict)value;
                if (dict.Keys.Count > MaxDebugArrayLength)
                {
                    return("{Dict:" + dict.Keys.Count.ToString() + " elements}");
                }
            }
            string result = value.ToLiteral();

            if (result.Length > MaxDebugLen)
            {
                result = "(" + value.LithpType().ToString() + ": too large to display)";
            }
            return(result);
        }
Exemplo n.º 2
0
 protected static LithpPrimitive getIfResult(LithpPrimitive value)
 {
     if (value.LithpType() == LithpType.OPCHAIN)
     {
         return(((LithpOpChain)value).CallImmediate());
     }
     return(value);
 }
Exemplo n.º 3
0
 protected static bool compareEqual(LithpPrimitive a, LithpPrimitive b)
 {
     if ((object)a == null || (object)b == null)
     {
         return((object)a == null && (object)b == null);
     }
     b = b.Cast(a.LithpType());
     return(a.compareEqual(b));
 }
Exemplo n.º 4
0
        public static LithpPrimitive Call(LithpList parameters, LithpOpChain state,
                                          LithpInterpreter interp)
        {
            LithpPrimitive def       = parameters[0];
            LithpList      defParams = (LithpList)Tail(LithpList.New(parameters), state, interp);

            switch (def.LithpType())
            {
            case LithpType.FN_NATIVE:
                return(((LithpFunctionDefinitionNative)def).Invoke(defParams, state, interp));

            case LithpType.FN:
                return(((LithpFunctionDefinition)def).Invoke(defParams, state, interp));

            case LithpType.ATOM:
            case LithpType.STRING:
                string strName = def.ToString();
                ILithpFunctionDefinition search;
                if ((object)state.Closure.TopMost != null && state.Closure.TopMost.IsDefined(strName))
                {
                    search = (ILithpFunctionDefinition)state.Closure.TopMost[strName];
                }
                else if (state.Closure.IsDefined(strName))
                {
                    search = (ILithpFunctionDefinition)state.Closure[strName];
                }
                else
                {
                    string arityStar = strName + "/*";
                    if ((object)state.Closure.TopMost != null && state.Closure.TopMost.IsDefined(arityStar))
                    {
                        search = (ILithpFunctionDefinition)state.Closure.TopMost[arityStar];
                    }
                    else if (state.Closure.IsDefined(arityStar))
                    {
                        search = (ILithpFunctionDefinition)state.Closure[arityStar];
                    }
                    else
                    {
                        throw new MissingMethodException();
                    }
                }
                return(search.Invoke(defParams, state, interp));

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 5
0
        private ILithpPrimitive resolve(ILithpPrimitive current, LithpOpChain chain)
        {
            switch (current.LithpType())
            {
            case LithpType.LITERAL:
                return(((LithpLiteral)current).Value);

            case LithpType.ATOM:
            case LithpType.DICT:
            case LithpType.INTEGER:
            case LithpType.LIST:
            case LithpType.STRING:
            case LithpType.FN:
            case LithpType.FN_NATIVE:
            case LithpType.OPCHAIN:
                return(current);

            case LithpType.FUNCTIONCALL:
                LithpFunctionCall call     = (LithpFunctionCall)current;
                LithpList         resolved = ResolveParameters(call, chain);
                LithpPrimitive    value    = InvokeResolved(call, resolved, chain);
                if (value.LithpType() == LithpType.OPCHAIN)
                {
                    LithpOpChain subchain = (LithpOpChain)value;
                    if (subchain.IsImmediate)
                    {
                        value = this.Run(new LithpOpChain(chain, subchain));
                    }
                }
                return(value);

            case LithpType.VAR:
                // TODO: Could just lookup the value now
                LithpVariableReference v = (LithpVariableReference)current;
                return(new LithpString(v.Name));

            default:
                throw new NotImplementedException();
            }
        }