コード例 #1
0
 internal BacktraceException(Exception inner,
     BacktraceFrame frame,Interpreter interpreter)
     : base(inner.Message,inner)
 {
     frames.Add(frame);
     this.interpreter = interpreter;
 }
コード例 #2
0
 internal 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);
 }
コード例 #3
0
        internal Closure(Cons args, Env env, Interpreter interpreter, Loc loc)
        {
            this.interpreter = interpreter;
            this.loc = loc;
            ArgSpecs specs = analyzeArgSpec((Cons)args.first, env, loc);
            //create an env expanded by params in which to analyze body
            Env env2 = new Env(specs.parameters, null, env);

            this.argSpecs = specs;
            this.body = interpreter.analyze(new Cons(interpreter.BLOCK, args.rest), env2, loc);
            this.env = env;
        }
コード例 #4
0
 internal ApplyExpression(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     fexpr = interpreter.analyze(args.first, env, loc);
     if (fexpr is IVar)
     {
         fsym = ((IVar)fexpr).getSymbol();
     }
     Int32 len = Cons.Length(args.rest);
     argexprs = new IExpression[len];
     args = args.rest;
     for (Int32 i = 0; i < argexprs.Length; i++, args = args.rest)
     {
         argexprs[i] = interpreter.analyze(args.first, env, loc);
     }
 }
コード例 #5
0
 internal Macro(Cons args, Env env, Interpreter interpreter, Loc loc)
     : base(args, env, interpreter, loc)
 {
 }
コード例 #6
0
 internal Reader(Interpreter interpreter)
 {
     this.interpreter = 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));
 }
コード例 #7
0
        internal static void internAll(Interpreter interpreter)
        {
            interpreter.Intern("not", new Function(not));
            interpreter.Intern("to-bool", new Function(to_bool));
            interpreter.Intern("nil?", new Function(nilp));
            interpreter.Intern("symbol?", new Function(symbolp));
            interpreter.Intern("eqv?", new Function(eqv));
            interpreter.Intern("eql?", new Function(eql));
            interpreter.Intern("cons", new Function(cons));
            interpreter.Intern("cons?", new Function(consp));
            interpreter.Intern("atom?", new Function(atomp));
            interpreter.Intern("first", new Function(first));
            interpreter.Intern("rest", new Function(rest));
            interpreter.Intern("set-first", new Function(setfirst));
            interpreter.Intern("set-rest", new Function(setrest));
            interpreter.Intern("second", new Function(second));
            interpreter.Intern("third", new Function(third));
            interpreter.Intern("fourth", new Function(fourth));
            interpreter.Intern("reverse", new Function(reverse));
            interpreter.Intern("list?", new Function(listp));
            interpreter.Intern("len", new Function(listlength));
            interpreter.Intern("nth", new Function(nth));
            interpreter.Intern("nth-rest", new Function(nthrest));
            interpreter.Intern("append", new Function(append));
            interpreter.Intern("concat!", new Function(concat_d));
            interpreter.Intern("type-of", new Function(type_of));
            interpreter.Intern("is?", new Function(isp));
            interpreter.Intern("even?", new Function(evenp));
            interpreter.Intern("gensym", new Function(gensym));
            interpreter.Intern("macroexpand-1", new Function(macroexpand_1));
            interpreter.Intern("vector", new Function(vector));
            interpreter.Intern("vector-of", new Function(vector_of));
            interpreter.Intern("throw", new Function(throwfun));
            interpreter.Intern("try-catch-finally", new Function(try_catch_finally));

            interpreter.Intern("<i", new Function(lti));
            interpreter.Intern("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.Intern("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.Intern("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.Intern("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.Intern("divide", divideop);

            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.Intern("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.Intern("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.Intern("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.Intern("bit-xor", bitxorop);

            GenericFunction bitnotgf = new GenericFunction();
            bitnotgf.AddMethod(typeof(Enum), new Function(bitnotenum));
            bitnotgf.AddMethod(typeof(Object), new Function(bitnot));
            interpreter.Intern("bit-not", bitnotgf);

            GenericFunction get_enum_gf = new GenericFunction();
            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.Intern("get-enum", get_enum_gf);

            GenericFunction strgf = new GenericFunction();
            strgf.AddMethod(null, new Function(strnil));
            strgf.AddMethod(typeof(Object), new Function(strobj));
            interpreter.Intern("str", strgf);

            //interpreter.Intern("pr",new GenericFunction());
        }
コード例 #8
0
 public DotConsole()
 {
     minterpreter = new Interpreter();
     minterpreter.LoadFile("boot.lisp");
 }
コード例 #9
0
 internal WhileExpression(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     this.test = interpreter.analyze(args.first, env, loc);
     this.body = interpreter.analyze(new Cons(interpreter.BLOCK, args.rest), env, loc);
 }
コード例 #10
0
 internal SetExpression(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     Int32 len = Cons.Length(args);
     if (len != 2)
         throw new Exception("Wrong number of args for set");
     var = (IVar)interpreter.analyze(args.first, env, loc);
     val = interpreter.analyze(Cons.Second(args), env, loc);
 }
コード例 #11
0
 internal OrExpression(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     exprs = new IExpression[Cons.Length(args)];
     for (Int32 i = 0; i < exprs.Length; i++, args = args.rest)
     {
         exprs[i] = interpreter.analyze(args.first, env, loc);
     }
 }
コード例 #12
0
 internal IfExpression(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     Int32 len = Cons.Length(args);
     if (len < 2 || len > 3)
         throw new Exception("Wrong number of args for if");
     test = interpreter.analyze(args.first, env, loc);
     brtrue = interpreter.analyze(Cons.Second(args), env, loc);
     if (len == 3)
         brfalse = interpreter.analyze(Cons.Third(args), env, loc);
     else
         brfalse = new QuoteExpr(null);
 }
コード例 #13
0
 internal DynamicLet(Cons args, Env env, Interpreter interpreter, Loc loc)
 {
     this.loc = loc;
     this.interpreter = interpreter;
     Cons bindlist = (Cons)args.first;
     Int32 blen = Cons.Length(bindlist);
     if ((blen % 2) != 0)	//odd
     {
         throw new Exception("Odd number of args in dynamic-let binding list");
     }
     binds = new BindPair[blen / 2];
     for (int i = 0; i < binds.Length; i++)
     {
         binds[i].dvar = (DynamicVar)interpreter.analyze(bindlist.first, env, loc);
         bindlist = bindlist.rest;
         binds[i].expr = interpreter.analyze(bindlist.first, env, loc);
         bindlist = bindlist.rest;
     }
     this.body = interpreter.analyze(new Cons(interpreter.BLOCK, args.rest), env, loc);
 }