示例#1
0
        public static void Run(string code)
        {
            var exe         = Compiler.CCompiler.Compile(code);
            var interpreter = new CInterpreter(exe);

            interpreter.Reset("main");
            interpreter.Run();
        }
示例#2
0
        public static object Eval(string expression, string?includeCode = "")
        {
            var codeToCompile = (includeCode ?? "") + @"
auto __evalResult = " + expression + @";
void start() {
    __cinit();
}
";
            var exe           = Compiler.CCompiler.Compile(codeToCompile);
            var global        = exe.Globals.First(x => x.Name == "__evalResult");
            var interpreter   = new Interpreter.CInterpreter(exe);

            interpreter.Reset("start");
            interpreter.Run();

            var globalType   = global.VariableType;
            var resultValues = new Value[globalType.NumValues];

            Array.Copy(interpreter.Stack, global.StackOffset, resultValues, 0, resultValues.Length);

            return(globalType.GetClrValue(resultValues, exe.MachineInfo));
        }