public object Eval(object form) { ScriptSource scriptSource = Engine.CreateScriptSourceFromString("<internal>"); Expression expr = Generator.Eval(GetLanguageContext(), form); LambdaExpression ast = Expression.Lambda(expr); ast = new GlobalLookupRewriter().RewriteLambda(ast); ScriptCode code = new ScriptCode(ast, GetSourceUnit(scriptSource)); return code.Run(); }
/// <summary> /// Executes against a specified scope and reports errors to the given error sink. /// </summary> public object Execute(Scope scope, ErrorSink errorSink) { ContractUtils.RequiresNotNull(scope, "scope"); ScriptCode compiledCode = Compile(_language.GetCompilerOptions(scope), errorSink); if (compiledCode == null) { throw new SyntaxErrorException(); } return(compiledCode.Run(scope)); }
internal object CompileAndRun(Scope/*!*/ globalScope, ScriptCode/*!*/ code, bool tryEvaluate) { long ts1 = Stopwatch.GetTimestamp(); code.EnsureCompiled(); long ts2 = Stopwatch.GetTimestamp(); Interlocked.Add(ref _ILGenerationTimeTicks, ts2 - ts1); return code.Run(globalScope); }
internal object CompileAndRun(Scope globalScope, ScriptCode/*!*/ code) { return globalScope != null ? code.Run(globalScope) : code.Run(); }
internal Scope Execute(Scope globalScope, ScriptCode/*!*/ code) { if (globalScope == null || code.LanguageContext != _context) { if (globalScope == null) { globalScope = code.CreateScope(); } if (code.SourceUnit.Path != null) { LoadedScripts[Platform.GetFullPath(code.SourceUnit.Path)] = globalScope; } code.Run(globalScope); return globalScope; } else { code.Run(globalScope); return null; } }
private void AstLocations1() { // DumpExpression uses private reflection: if (_driver.PartialTrust) return; var sourceUnit = Context.CreateSnippet(@" def add a,b a + b end add 1, 1 add 'foo', 'bar' ", SourceCodeKind.Expression); var options = new RubyCompilerOptions(); var parser = new Parser(); var tokens = new List<KeyValuePair<SourceSpan, Tokens>>(); parser.TokenSink = (token, span) => { tokens.Add(new KeyValuePair<SourceSpan, Tokens>(span, token)); }; var ast = parser.Parse(sourceUnit, options, Context.RuntimeErrorSink); const int Id = 0x12345678; var lambda = CallSiteTracer.Transform<DlrMainCallTarget>(ast, sourceUnit, options, Id); var code = new ScriptCode(lambda, sourceUnit); var locations = new List<int>(); CallSiteTracer.Register((context, args, result, id, location) => { locations.Add(location); Debug.Assert(id == Id); Debug.Assert(location > 0); //Console.WriteLine("-- {0} ---------", location); //Console.WriteLine(this); //Console.WriteLine(AstUtils.DumpExpression(result.Restrictions.ToExpression())); //Console.WriteLine(); //Console.WriteLine(AstUtils.DumpExpression(result.Expression)); //Console.WriteLine("----------------"); }); code.Run(); Debug.Assert(locations.Count == 4 && locations[0] == 31 && locations[1] == 19 && locations[2] == 41 && locations[3] == 19); }
private static object LoadFromPushbackReader(ScriptSource scriptSource, TextReader pbr, bool addPrint) { object ret = null; object eofVal = new object(); object form; while ((form = LispReader.read(pbr, false, eofVal, false)) != eofVal) { LambdaExpression ast = Generator.Generate(form, addPrint); ast = new GlobalLookupRewriter().RewriteLambda(ast); ScriptCode code = new ScriptCode(ast, GetSourceUnit(scriptSource)); ret = code.Run(); } return ret; }
public TotemModule InitializeModule(string fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options) { moduleContext.InitializeBuiltins(); moduleContext.Features = options; if ((options & ModuleOptions.Initialize) != 0) { scriptCode.Run(moduleContext.GlobalScope); } return moduleContext.Module; }