예제 #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
파일: Machine.cs 프로젝트: rwaldron/magpie
 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
파일: Machine.cs 프로젝트: rwaldron/magpie
        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
파일: Machine.cs 프로젝트: rwaldron/magpie
 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>();
 }