Ejemplo n.º 1
0
Archivo: Program.cs Proyecto: hww/lbvm
        public object Run(params object[] parameters)
        {
            var envStack = new EnvironmentStack();
            envStack.PushNew(); // Global env
            envStack.Set(Symbol.fromString("sys:args"), new Variable(CliToVm(parameters)));

            int ip = 0;
            var valueStack = new ValueStack();
            var callStack = new CallStack();

            for (var current = Statements[ip]; !(current is EndStatement); current = Statements[ip])
            {
                //System.Diagnostics.Debug.Print("0x" + ip.ToString("x4") + ": " + current);
                current.Execute(ref ip, valueStack, envStack, callStack);
            }

            if (envStack.Count() == 0) throw new exceptions.RuntimeException("Bad program: Global environment deleted!");
            if (envStack.Count() > 1) throw new exceptions.RuntimeException("Bad program: Environment stack not cleaned up");
            if (callStack.Count() > 1) throw new exceptions.RuntimeException("Bad program: Call stack not cleaned up");
            if (valueStack.Count() == 0) throw new exceptions.RuntimeException("Bad program: Value stack empty after running");
            if (valueStack.Count() > 1) throw new exceptions.RuntimeException("Bad program: Value stack not cleaned up");
            return valueStack.Pop();
        }
Ejemplo n.º 2
0
 internal override void Execute(ref int ip, ValueStack valueStack, EnvironmentStack envStack, CallStack callStack)
 {
     envStack.Set(Symbol, new Variable());
     ip += Length;
 }
Ejemplo n.º 3
0
 internal override void Execute(ref int ip, ValueStack valueStack, EnvironmentStack envStack, CallStack callStack)
 {
     object o = valueStack.Pop();
     if (o is Variable) envStack.Set(Symbol, (Variable)o); // Link to variable, e.g. in Closure
     else
     {
         if (envStack.HasVariable(Symbol))
             envStack.Get(Symbol).SetValue(o);
         else
             envStack.Set(Symbol, new Variable(o));
     }
     ip += Length;
 }