/// <summary>Performs set-up behaviour shared by multiple /// constructors</summary> private void initialise() { var s = new LocalScope(); scope.scope = s; majorScope = s; s.AddMethod("print(_)", new DelegateMethod1Ctx(Print)); s.AddLocalDef("true", GraceBoolean.True); s.AddLocalDef("false", GraceBoolean.False); s.AddMethod("_base_while_do(_,_)", new DelegateMethodReq(BaseWhileDo)); s.AddMethod("_base_try_catch_finally(_,_)", new DelegateMethodReq(BaseTryCatchFinally)); s.AddMethod("_base_try_catch_finally(_,_,_)", new DelegateMethodReq(BaseTryCatchFinally)); s.AddMethod("_base_try_catch_finally(_,_,_,_)", new DelegateMethodReq(BaseTryCatchFinally)); s.AddMethod("_base_try_catch_finally(_,_,_,_,_)", new DelegateMethodReq(BaseTryCatchFinally)); s.AddMethod("_base_try_catch_finally(_,_,_,_,_,_)", new DelegateMethodReq(BaseTryCatchFinally)); s.AddMethod("_base_try_catch_finally(_,_,_,_,_,_,_)", new DelegateMethodReq(BaseTryCatchFinally)); s.AddMethod("Exception", new ConstantMethod( new GraceExceptionKind("Exception"))); }
private static void configureInterpreter(Interpreter interp, UserObject obj, LocalScope localScope) { interp.LoadPrelude(); interp.Extend(obj); localScope.AddLocalDef("self", obj); localScope.AddLocalDef("LAST", GraceObject.Done); interp.ExtendMinor(localScope); }
private static int runLines(Interpreter interp, IEnumerable <string> lines) { var ls = new LocalScope("code-inner"); var obj = new UserObject(); interp.Extend(obj); ls.AddLocalDef("self", obj); interp.ExtendMinor(ls); var memo = interp.Memorise(); bool unfinished; GraceObject result; foreach (var line in lines) { int r = REPL.RunLine(interp, obj, memo, line, out unfinished, out result); if (r != 0) { return(r); } if (unfinished) { return(1); } } return(0); }
private static bool conditionsMet( string l, Dictionary <string, string> data ) { var interpreter = new Interpreter(); interpreter.LoadPrelude(); var ls = new LocalScope(); foreach (var k in data.Keys) { switch (k) { case "method": case "type": case "class": case "object": case "def": case "var": case "dialect": case "import": case "return": case "is": case "where": ls.AddLocalDef(k + "_", GraceString.Create(data[k])); break; default: ls.AddLocalDef(k, GraceString.Create(data[k])); break; } } interpreter.Extend(ls); while (l.StartsWith("|[")) { int end = l.IndexOf("]|"); var condition = l.Substring(2, end - 2); if (!conditionMet(condition, data, interpreter)) { return(false); } l = l.Substring(end + 2); } return(true); }