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

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

            return(state.Closure.Get(name));
        }
        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);
        }
Exemple #5
0
 protected static LithpPrimitive getIfResult(LithpPrimitive value)
 {
     if (value.LithpType() == LithpType.OPCHAIN)
     {
         return(((LithpOpChain)value).CallImmediate());
     }
     return(value);
 }
 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));
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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();
            }
        }
Exemple #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);
     }
 }
        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();
            }
        }
Exemple #15
0
        public override bool compareEqual(LithpPrimitive other)
        {
            LithpFloat iOther = (LithpFloat)other;

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

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

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

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

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

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

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

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

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