示例#1
0
        public void Compile()
        {
            if (mBytecode != null)
            {
                throw new InvalidOperationException("Can only compile a script once.");
            }

            var compiler = new Compiler(mForeign);

            compiler.FunctionStarted = mDebug.StartFunction;

            // add the source files
            foreach (var sourceFile in GetSourceFiles(mPath))
            {
                compiler.AddSourceFile(sourceFile);
            }

            using (var stream = new MemoryStream())
            {
                // compile the code
                mErrors = compiler.Compile(stream);

                // bail if there were compile errors
                if (mErrors.Count > 0)
                {
                    return;
                }

                mBytecode = new Magpie.Interpreter.BytecodeFile(stream.ToArray());
            }
        }
示例#2
0
 public Value Interpret(BytecodeFile file, DebugInfo debug, string argument)
 {
     if (file.FindFunction("Main String") != -1)
     {
         return Interpret(file, debug, "Main String", new Value(argument));
     }
     else
     {
         // no main that takes a string, so look for one with no string
         return Interpret(file, debug, "Main ()", null);
     }
 }
示例#3
0
 public Value Interpret(BytecodeFile file, DebugInfo debug, string argument)
 {
     if (file.FindFunction("Main String") != -1)
     {
         return(Interpret(file, debug, "Main String", new Value(argument)));
     }
     else
     {
         // no main that takes a string, so look for one with no string
         return(Interpret(file, debug, "Main ()", null));
     }
 }
示例#4
0
        public Value Interpret(BytecodeFile file, DebugInfo debug, string function, Value argument)
        {
            mFile = file;
            mDebug = debug;

            int functionOffset = file.FindFunction(function);

            if (argument != null)
            {
                // push the argument
                Push(argument);

                Push(functionOffset);
                Call(1, false);
            }
            else
            {
                Push(functionOffset);
                Call(0, false);
            }

            return Interpret();
        }
示例#5
0
        public Value Interpret(BytecodeFile file, DebugInfo debug, string function, Value argument)
        {
            mFile  = file;
            mDebug = debug;

            int functionOffset = file.FindFunction(function);

            if (argument != null)
            {
                // push the argument
                Push(argument);

                Push(functionOffset);
                Call(1, false);
            }
            else
            {
                Push(functionOffset);
                Call(0, false);
            }

            return(Interpret());
        }
示例#6
0
文件: Script.cs 项目: rwaldron/magpie
        public void Compile()
        {
            if (mBytecode != null) throw new InvalidOperationException("Can only compile a script once.");

            var compiler = new Compiler(mForeign);

            compiler.FunctionStarted = mDebug.StartFunction;

            // add the source files
            foreach (var sourceFile in GetSourceFiles(mPath))
            {
                compiler.AddSourceFile(sourceFile);
            }

            using (var stream = new MemoryStream())
            {
                // compile the code
                mErrors = compiler.Compile(stream);

                // bail if there were compile errors
                if (mErrors.Count > 0) return;

                mBytecode = new Magpie.Interpreter.BytecodeFile(stream.ToArray());
            }
        }
示例#7
0
文件: Script.cs 项目: rwaldron/magpie
 public Script(byte[] bytecode)
 {
     mBytecode = new Magpie.Interpreter.BytecodeFile(bytecode);
     mErrors = new List<CompileError>();
 }
示例#8
0
 public Value Interpret(BytecodeFile file)
 {
     return Interpret(file, null, String.Empty);
 }
示例#9
0
 public Value Interpret(BytecodeFile file)
 {
     return(Interpret(file, null, String.Empty));
 }
示例#10
0
 public Script(byte[] bytecode)
 {
     mBytecode = new Magpie.Interpreter.BytecodeFile(bytecode);
     mErrors   = new List <CompileError>();
 }