public static BacktraceException Push(Exception inner, BacktraceFrame frame, Interpreter interpreter) { if (inner is BacktraceException) { ((BacktraceException)inner).Frames.Add(frame); return (BacktraceException)inner; } return new BacktraceException(inner, frame, interpreter); }
//......................................................................... public Closure(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerInterpreter = interpreter; InnerLocation = loc; ArgSpecs specs = AnalyzeArgSpec((Cons)args.First, env, loc); //create an env expanded by params in which to analyze body IEnvironment env2 = new Environment(specs.Parameters, null, env); InnerArgsSpecs = specs; InnerBody = interpreter.Analyze(new Cons(interpreter.BLOCK, args.Rest), env2, loc); InnerEnvironment = env; }
public static Package DefinePackage(string name, Interpreter interpreter) { if (interpreter == null) Error.Fatal(new ArgumentNullException("interpreter"), typeof(Package)); PackageProvider pp = interpreter.PackageProvider; Package p = pp.GetPackage(name); if (p == null) { p = new Package(interpreter, name, pp); pp.RegisterPackage(p); } return p; }
public Package(Interpreter interpreter, string name, PackageProvider pp) { if (interpreter == null) Error.Critical(new ArgumentNullException("interpreter"), typeof(Package)); if (name == null) Error.Critical(new ArgumentNullException("name"), typeof(Package)); InnerName = name; InnerPackageProvider = pp ?? new PackageProvider(); InnerInterpreter = interpreter; InnerExternalTable = new SymbolTable(this, InnerInterpreter.TypeResolver); InnerInternalTable = new SymbolTable(this, InnerInterpreter.TypeResolver); }
//......................................................................... public ApplyExpression(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerLocation = loc; InnerInterpreter = interpreter; InnerFExpression = interpreter.Analyze(args.First, env, loc); if (InnerFExpression is IVariable) { InnerFSymbol = ((IVariable)InnerFExpression).Symbol; } Int32 len = Cons.GetLength(args.Rest); InnerArgsExpressions = new IExpression[len]; args = args.Rest; for (Int32 i = 0; i < InnerArgsExpressions.Length; i++, args = args.Rest) { InnerArgsExpressions[i] = interpreter.Analyze(args.First, env, loc); } }
protected virtual void InitializeInterpreter(Interpreter intpr) { intpr.Load(new LocTextReader("inline", new StringReader(global::Front.Lisp.Resources.boot))); }
protected Hashtable InnerMacroTable = new Hashtable(); // TODO Это надо вынести куда-то, чтобы лиспом можно было рулить! #endregion Fields #region Constructors //......................................................................... public Reader(Interpreter interpreter) { InnerInterpreter = interpreter; MacroTable.Add('(', new ReaderMacro(new Function(ReadList), true)); MacroTable.Add(')', new ReaderMacro(new Function(ReadEndDelimiter), true)); MacroTable.Add('[', new ReaderMacro(new Function(ReadVector), true)); MacroTable.Add(']', new ReaderMacro(new Function(ReadEndDelimiter), true)); MacroTable.Add('"', new ReaderMacro(new Function(ReadString), true)); MacroTable.Add('\'', new ReaderMacro(new Function(ReadQuote), true)); MacroTable.Add('`', new ReaderMacro(new Function(ReadBackQuote), true)); MacroTable.Add(',', new ReaderMacro(new Function(ReadUnquote), true)); //no func since read directly implements MacroTable.Add(';', new ReaderMacro(null, true)); MacroTable.Add('#', new ReaderMacro(null, true)); }
public static void InternAll(Interpreter interpreter) { interpreter.InternAndExport("not", new Function(not)); interpreter.InternAndExport("to-bool", new Function(to_bool)); interpreter.InternAndExport("nil?", new Function(nilp)); interpreter.InternAndExport("symbol?", new Function(symbolp)); interpreter.InternAndExport("eqv?", new Function(eqv)); interpreter.InternAndExport("eql?", new Function(eql)); interpreter.InternAndExport("cons", new Function(cons)); interpreter.InternAndExport("cons?", new Function(consp)); interpreter.InternAndExport("atom?", new Function(atomp)); interpreter.InternAndExport("first", new Function(first)); interpreter.InternAndExport("rest", new Function(rest)); interpreter.InternAndExport("set-first", new Function(setfirst)); interpreter.InternAndExport("set-rest", new Function(setrest)); interpreter.InternAndExport("second", new Function(second)); interpreter.InternAndExport("third", new Function(third)); interpreter.InternAndExport("fourth", new Function(fourth)); interpreter.InternAndExport("reverse", new Function(reverse)); interpreter.InternAndExport("list?", new Function(listp)); interpreter.InternAndExport("len", new Function(listlength)); interpreter.InternAndExport("nth", new Function(nth)); interpreter.InternAndExport("nth-rest", new Function(nthrest)); interpreter.InternAndExport("append", new Function(append)); interpreter.InternAndExport("concat!", new Function(concat_d)); interpreter.InternAndExport("type-of", new Function(type_of)); interpreter.InternAndExport("is?", new Function(isp)); interpreter.InternAndExport("even?", new Function(evenp)); interpreter.InternAndExport("macroexpand-1", new Function(macroexpand_1)); interpreter.InternAndExport("vector", new Function(vector)); interpreter.InternAndExport("vector-of", new Function(vector_of)); interpreter.InternAndExport("throw", new Function(throwfun)); interpreter.InternAndExport("try-catch-finally", new Function(try_catch_finally)); interpreter.InternAndExport("<i", new Function(lti)); interpreter.InternAndExport("addi", new Function(addints)); BinOp addop = new BinOp(); addop.AddMethod(typeof(Int32), typeof(Int32), new Function(addints)); addop.AddMethod(typeof(Int32), typeof(Object), new Function(addobjs)); addop.AddMethod(typeof(Object), typeof(Object), new Function(addobjs)); interpreter.InternAndExport("add", addop); BinOp subtractop = new BinOp(); subtractop.AddMethod(typeof(Int32), typeof(Int32), new Function(subtractints)); subtractop.AddMethod(typeof(Int32), typeof(Object), new Function(subtractobjs)); subtractop.AddMethod(typeof(Object), typeof(Object), new Function(subtractobjs)); interpreter.InternAndExport("subtract", subtractop); BinOp multiplyop = new BinOp(); multiplyop.AddMethod(typeof(Int32), typeof(Int32), new Function(multiplyints)); multiplyop.AddMethod(typeof(Int32), typeof(Object), new Function(multiplyobjs)); multiplyop.AddMethod(typeof(Object), typeof(Object), new Function(multiplyobjs)); interpreter.InternAndExport("multiply", multiplyop); BinOp divideop = new BinOp(); divideop.AddMethod(typeof(Int32), typeof(Int32), new Function(divideints)); divideop.AddMethod(typeof(Int32), typeof(Object), new Function(divideobjs)); divideop.AddMethod(typeof(Object), typeof(Object), new Function(divideobjs)); interpreter.InternAndExport("divide", divideop); BinOp modop = new BinOp(); modop.AddMethod(typeof(Int32), typeof(Int32), new Function(modints)); interpreter.InternAndExport("mod", modop); BinOp compareop = new BinOp(); compareop.AddMethod(typeof(Int32), typeof(Int32), new Function(subtractints)); compareop.AddMethod(typeof(Int32), typeof(Object), new Function(compareobjs)); compareop.AddMethod(typeof(Object), typeof(Object), new Function(compareobjs)); interpreter.InternAndExport("compare", compareop); BinOp bitorop = new BinOp(); bitorop.AddMethod(typeof(Enum), typeof(Enum), new Function(bitorenum)); bitorop.AddMethod(typeof(Object), typeof(Object), new Function(bitor)); interpreter.InternAndExport("bit-or", bitorop); BinOp bitandop = new BinOp(); bitandop.AddMethod(typeof(Enum), typeof(Enum), new Function(bitandenum)); bitandop.AddMethod(typeof(Object), typeof(Object), new Function(bitand)); interpreter.InternAndExport("bit-and", bitandop); BinOp bitxorop = new BinOp(); bitxorop.AddMethod(typeof(Enum), typeof(Enum), new Function(bitxorenum)); bitxorop.AddMethod(typeof(Object), typeof(Object), new Function(bitxor)); interpreter.InternAndExport("bit-xor", bitxorop); SimpleGenericFunction bitnotgf = new SimpleGenericFunction(); bitnotgf.AddMethod(typeof(Enum), new Function(bitnotenum)); bitnotgf.AddMethod(typeof(Object), new Function(bitnot)); interpreter.InternAndExport("bit-not", bitnotgf); SimpleGenericFunction get_enum_gf = new SimpleGenericFunction(); get_enum_gf.AddMethod(typeof(IEnumerator), new Function(get_enum_IEnumerator)); get_enum_gf.AddMethod(typeof(IEnumerable), new Function(get_enum_IEnumerable)); get_enum_gf.AddMethod(null, new Function(get_enum_nil)); interpreter.InternAndExport("get-enum", get_enum_gf); SimpleGenericFunction strgf = new SimpleGenericFunction(); strgf.AddMethod(null, new Function(strnil)); strgf.AddMethod(typeof(Object), new Function(strobj)); interpreter.InternAndExport("str", strgf); }
//......................................................................... public Package(Interpreter interpreter, string name) : this(interpreter, name, null) { }
//......................................................................... public IfExpression(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerLocation = loc; InnerInterpreter = interpreter; Int32 len = Cons.GetLength(args); if (len < 2 || len > 3) throw new LispException("Wrong number of args for if"); InnerTestExpression = interpreter.Analyze(args.First, env, loc); InnerTrueExpression = interpreter.Analyze(Cons.GetSecond(args), env, loc); if (len == 3) InnerFalseExpression = interpreter.Analyze(Cons.GetThird(args), env, loc); else InnerFalseExpression = new QuoteExpr(null); }
//......................................................................... public BacktraceException(Exception inner, BacktraceFrame frame, Interpreter interpreter) : base(inner.Message, inner) { InnerFrames.Add(frame); InnerInterpreter = interpreter; }
//......................................................................... public WhileExpression(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerLocation = loc; InnerInterpreter = interpreter; InnerTest = interpreter.Analyze(args.First, env, loc); InnerBody = interpreter.Analyze(new Cons(interpreter.BLOCK, args.Rest), env, loc); }
//......................................................................... public SetExpression(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerLocation = loc; InnerInterpreter = interpreter; Int32 len = Cons.GetLength(args); if (len != 2) throw new LispException("Wrong number of args for set"); InnerVar = (IVariable)interpreter.Analyze(args.First, env, loc); InnerValue = interpreter.Analyze(Cons.GetSecond(args), env, loc); }
//......................................................................... public OrExpression(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerLocation = loc; InnerInterpreter = interpreter; InnerExpressions = new IExpression[Cons.GetLength(args)]; for (Int32 i = 0; i < InnerExpressions.Length; i++, args = args.Rest) { InnerExpressions[i] = interpreter.Analyze(args.First, env, loc); } }
//......................................................................... protected override bool OnInitialize(IServiceProvider sp) { bool result = base.OnInitialize(sp); if (result) { InnerInterpreter = new Interpreter(); InitializeInterpreter(InnerInterpreter); } return result; }
//......................................................................... public Macro(Cons args, IEnvironment env, Interpreter interpreter, Location loc) : base(args, env, interpreter, loc) { }
//......................................................................... public DynamicLet(Cons args, IEnvironment env, Interpreter interpreter, Location loc) { InnerLocation = loc; InnerInterpreter = interpreter; Cons bindlist = (Cons)args.First; Int32 blen = Cons.GetLength(bindlist); if ((blen % 2) != 0) { //odd throw new LispException("Odd number of args in dynamic-let binding list"); } InnerBinds = new BindPair[blen / 2]; for (int i = 0; i < InnerBinds.Length; i++) { InnerBinds[i].DynamicVar = (DynamicVar)interpreter.Analyze(bindlist.First, env, loc); bindlist = bindlist.Rest; InnerBinds[i].Expression = interpreter.Analyze(bindlist.First, env, loc); bindlist = bindlist.Rest; } InnerBody = interpreter.Analyze(new Cons(interpreter.BLOCK, args.Rest), env, loc); }