Esempio n. 1
0
        public override bool compareEqual(LithpPrimitive other)
        {
            // TODO: Find better way to do this
            LithpString otherString = (LithpString)other;

            return(Value == otherString.Value);
        }
Esempio n. 2
0
 public void Set(string name, LithpPrimitive value)
 {
     if (!TrySet(name, value))
     {
         SetImmediate(name, value);
     }
 }
Esempio n. 3
0
        public static LithpPrimitive Get(LithpList parameters, LithpOpChain state,
                                         LithpInterpreter interp)
        {
            LithpPrimitive name = CallBuiltin(Head, state, interp, parameters);

            return(state.Closure.Get(name));
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 protected static LithpPrimitive getIfResult(LithpPrimitive value)
 {
     if (value.LithpType() == LithpType.OPCHAIN)
     {
         return(((LithpOpChain)value).CallImmediate());
     }
     return(value);
 }
Esempio n. 6
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));
 }
Esempio n. 7
0
        public static LithpPrimitive DictSet(LithpList parameters, LithpOpChain state,
                                             LithpInterpreter interp)
        {
            LithpDict      dict  = (LithpDict)parameters[0];
            LithpString    key   = (LithpString)parameters[1].Cast(LithpType.STRING);
            LithpPrimitive value = parameters[2];

            dict[key] = value;
            return(dict);
        }
Esempio n. 8
0
        public static LithpPrimitive IndexSet(LithpList parameters, LithpOpChain state,
                                              LithpInterpreter interp)
        {
            LithpList      list  = (LithpList)parameters[0];
            LithpInteger   index = (LithpInteger)parameters[1];
            LithpPrimitive value = parameters[2];

            list[index] = value;
            return(list);
        }
Esempio n. 9
0
        public static LithpPrimitive Set(LithpList parameters, LithpOpChain state,
                                         LithpInterpreter interp)
        {
            LithpPrimitive name  = CallBuiltin(Head, state, interp, parameters);
            LithpList      tail  = (LithpList)CallBuiltin(Tail, state, interp, parameters);
            LithpPrimitive value = CallBuiltin(Head, state, interp, tail);

            state.Closure.Set(name, value);
            return(value);
        }
Esempio n. 10
0
        public static LithpPrimitive Print(LithpList parameters, LithpOpChain state,
                                           LithpInterpreter interp)
        {
            LithpPrimitive result = ApplyAction((A, B, X, Y) =>
            {
                return(A.ToString() + " " + B.ToString());
            }, parameters, state, interp);

            Console.WriteLine(result.ToString());
            return(LithpAtom.Nil);
        }
Esempio n. 11
0
        protected static LithpPrimitive ApplyAction(LithpAction action, LithpList list,
                                                    LithpOpChain state, LithpInterpreter interp)
        {
            LithpPrimitive value = CallBuiltin(Head, state, interp, list);
            LithpList      tail  = (LithpList)CallBuiltin(Tail, state, interp, list);

            foreach (var x in tail)
            {
                value = action(value, x, state, interp);
            }
            return(value);
        }
Esempio n. 12
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();
            }
        }
Esempio n. 13
0
 public bool TrySet(string name, LithpPrimitive value)
 {
     if (IsDefined(name))
     {
         SetImmediate(name, value);
         return(true);
     }
     else if (Parent)
     {
         return(Parent.TrySet(name, value));
     }
     else
     {
         return(false);
     }
 }
Esempio n. 14
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();
            }
        }
Esempio n. 15
0
        public override bool compareEqual(LithpPrimitive other)
        {
            LithpFloat iOther = (LithpFloat)other;

            return(value == iOther.value);
        }
Esempio n. 16
0
 protected override LithpPrimitive operatorPlus(LithpPrimitive other)
 {
     return(Value + other.ToString());
 }
Esempio n. 17
0
        protected override LithpPrimitive operatorBinaryXor(LithpPrimitive other)
        {
            LithpInteger iOther = (LithpInteger)other.Cast(LithpBlunt.LithpType.INTEGER);

            return(new LithpInteger(value ^ iOther.value));
        }
Esempio n. 18
0
 public virtual bool compareEqual(LithpPrimitive other)
 {
     return(false);
 }
Esempio n. 19
0
        protected override LithpPrimitive operatorMultiply(LithpPrimitive other)
        {
            LithpInteger iOther = (LithpInteger)other;

            return(new LithpInteger(value * iOther.value));
        }
Esempio n. 20
0
 protected virtual bool compareMoreThan(LithpPrimitive other)
 {
     return(false);
 }
Esempio n. 21
0
 protected virtual LithpPrimitive operatorDivide(LithpPrimitive other)
 {
     throw new NotImplementedException();
 }
Esempio n. 22
0
        protected override bool compareLessThan(LithpPrimitive other)
        {
            LithpInteger iOther = (LithpInteger)other;

            return(value < iOther.value);
        }
Esempio n. 23
0
        protected override LithpPrimitive operatorDivide(LithpPrimitive other)
        {
            LithpInteger iOther = (LithpInteger)other;

            return(new LithpInteger(value / iOther.value));
        }
Esempio n. 24
0
        protected override LithpPrimitive operatorMultiply(LithpPrimitive other)
        {
            LithpFloat iOther = (LithpFloat)other;

            return(new LithpFloat(value * iOther.value));
        }
Esempio n. 25
0
 public void SetImmediate(string name, LithpPrimitive value)
 {
     closure[name] = value;
 }
Esempio n. 26
0
        public override bool compareEqual(LithpPrimitive other)
        {
            LithpAtom otherAtom = (LithpAtom)other;

            return(Id == otherAtom.Id);
        }
Esempio n. 27
0
        protected override bool compareMoreThan(LithpPrimitive other)
        {
            LithpFloat iOther = (LithpFloat)other;

            return(value > iOther.value);
        }
Esempio n. 28
0
        protected override LithpPrimitive operatorDivide(LithpPrimitive other)
        {
            LithpFloat iOther = (LithpFloat)other;

            return(new LithpFloat(value / iOther.value));
        }