public override bool compareEqual(LithpPrimitive other) { // TODO: Find better way to do this LithpString otherString = (LithpString)other; return(Value == otherString.Value); }
public void Set(string name, LithpPrimitive value) { if (!TrySet(name, value)) { SetImmediate(name, value); } }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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(); } }
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(); } }
public override bool compareEqual(LithpPrimitive other) { LithpFloat iOther = (LithpFloat)other; return(value == iOther.value); }
protected override LithpPrimitive operatorPlus(LithpPrimitive other) { return(Value + other.ToString()); }
protected override LithpPrimitive operatorBinaryXor(LithpPrimitive other) { LithpInteger iOther = (LithpInteger)other.Cast(LithpBlunt.LithpType.INTEGER); return(new LithpInteger(value ^ iOther.value)); }
public virtual bool compareEqual(LithpPrimitive other) { return(false); }
protected override LithpPrimitive operatorMultiply(LithpPrimitive other) { LithpInteger iOther = (LithpInteger)other; return(new LithpInteger(value * iOther.value)); }
protected virtual bool compareMoreThan(LithpPrimitive other) { return(false); }
protected virtual LithpPrimitive operatorDivide(LithpPrimitive other) { throw new NotImplementedException(); }
protected override bool compareLessThan(LithpPrimitive other) { LithpInteger iOther = (LithpInteger)other; return(value < iOther.value); }
protected override LithpPrimitive operatorDivide(LithpPrimitive other) { LithpInteger iOther = (LithpInteger)other; return(new LithpInteger(value / iOther.value)); }
protected override LithpPrimitive operatorMultiply(LithpPrimitive other) { LithpFloat iOther = (LithpFloat)other; return(new LithpFloat(value * iOther.value)); }
public void SetImmediate(string name, LithpPrimitive value) { closure[name] = value; }
public override bool compareEqual(LithpPrimitive other) { LithpAtom otherAtom = (LithpAtom)other; return(Id == otherAtom.Id); }
protected override bool compareMoreThan(LithpPrimitive other) { LithpFloat iOther = (LithpFloat)other; return(value > iOther.value); }
protected override LithpPrimitive operatorDivide(LithpPrimitive other) { LithpFloat iOther = (LithpFloat)other; return(new LithpFloat(value / iOther.value)); }