public void import_module_remove_by_name() { var @input = @" %(mymod.add(1.0f, 2)) "; var parsed = ExpressionParser.Parse(input); var comp = new RegenCompiler(); var mod = new RegenModule("mymod", new MyModule()); comp.AddModule(mod); comp.Compile(parsed).Trim('\n', '\r', ' ', '\t', '\0').All(char.IsDigit).Should().BeTrue(); comp.RemoveModule("mymod"); new Action(() => { comp.Compile(ExpressionParser.Parse(input)); }) .Should().Throw <ExpressionCompileException>().Where(e => e.InnerException.Message.Contains("variable with the name 'mymod'")); }
/// <summary> /// Runs the following code: return new Interperter(code, code).Run().Variables; /// </summary> /// <param name="code">The input code to compile</param> /// <param name="variables">Optional variables to be passed to the interperter</param> /// <param name="modules">The modules to include into the interpreter</param> public override Dictionary <string, object> UnpackedVariables(string code, Dictionary <string, object> variables = null, params RegenModule[] modules) { var parsed = ExpressionParser.Parse(code, variables); var comp = new RegenCompiler(modules); var output = comp.Compile(parsed); Debug(output, comp.Context.Variables); return(comp.Context.Variables.ToDictionary(kv => kv.Key, kv => kv.Value is Data d ? d.Value : kv.Value)); }
/// <summary> /// Runs the following code: return new Interperter(code, code).Run().Variables; /// </summary> /// <param name="code">The input code to compile</param> /// <param name="variables">Optional variables to be passed to the interperter</param> /// <param name="modules">The modules to include into the interpreter</param> public override (ParsedCode ParsedCode, string Output) Compile(string code, Dictionary <string, object> variables = null, params RegenModule[] modules) { var parsed = ExpressionParser.Parse(code, variables); var comp = new RegenCompiler(modules); var output = comp.Compile(parsed); Debug(output, comp.Context.Variables); return(parsed, output); }
public void import_module_via_add() { var @input = @" %(mymod.add(1.0f, 2)) "; var parsed = ExpressionParser.Parse(input); var comp = new RegenCompiler(new RegenModule("mymod", new MyModule())); var output = comp.Compile(parsed); output.Trim('\n', '\r', ' ', '\t', '\0').All(char.IsDigit).Should().BeTrue(); }
public static CodeFrame CompileFrame(CodeFrame frame, string code) { var compiler = new RegenCompiler(); //todo modules here? var parsedCode = ExpressionParser.Parse(frame.Input); LoadGlobals(compiler); //handle globals var globals = CodeFrame.CreateGlobals(code); foreach (var globalFrame in globals) { compiler.CompileGlobal(globalFrame.Input); } frame.Output = compiler.Compile(parsedCode); return(frame); }