Esempio n. 1
0
 public void CreateAndInvokeAgentUsingInterpreter()
 {
     Machine machine = new Machine();
     Block block = new Block();
     AjTalk.Language.ExecutionContext context = new AjTalk.Language.ExecutionContext(machine, null, block, null);
     Interpreter interpreter = new Interpreter(context);
     ManualResetEvent handle = new ManualResetEvent(false);
     bool executed = false;
     AgentObject agent = new AgentObject();
     agent.ExecuteMethod(
         interpreter,
         new FunctionalMethod((x, y, args) =>
         {
             executed = true;
             return handle.Set();
         }),
     null);
     handle.WaitOne();
     Assert.IsTrue(executed);
 }
Esempio n. 2
0
        private static void DoSetGlobalVariable(ExecutionContext context)
        {
            context.InstructionPointer++;
            byte arg = context.Block.ByteCodes[context.InstructionPointer];
            string name = context.Block.GetGlobalName(arg);
            object value = context.Pop();

            if (context.Self != null)
                context.Self.Behavior.Scope.SetValue(name, value);
            else
                context.Machine.CurrentEnvironment.SetValue(name, value);

            context.LastReceiver = value;
            context.Push(value);
        }
Esempio n. 3
0
 private static void DoSetArgument(ExecutionContext context)
 {
     context.InstructionPointer++;
     byte arg = context.Block.ByteCodes[context.InstructionPointer];
     var value = context.Pop();
     context.SetArgument(arg, value);
     context.LastReceiver = null;
 }
Esempio n. 4
0
 private static void DoGetDotNetType(ExecutionContext context)
 {
     context.InstructionPointer++;
     byte arg = context.Block.ByteCodes[context.InstructionPointer];
     context.Push(TypeUtilities.AsType(context.Block.GetGlobalName(arg)));
 }
Esempio n. 5
0
 private static void DoGetConstant(ExecutionContext context)
 {
     context.InstructionPointer++;
     byte arg = context.Block.ByteCodes[context.InstructionPointer];
     context.Push(context.Block.GetConstant(arg));
 }
Esempio n. 6
0
        private static void DoGetClass(ExecutionContext context)
        {
            object value = context.Pop();
            context.LastReceiver = value;

            if (value == null)
            {
                context.Push(context.Machine.UndefinedObjectClass);
                return;
            }

            IObject iobj = value as IObject;

            if (iobj != null)
            {
                context.Push(iobj.Behavior);
                return;
            }

            var behavior = context.Machine.GetNativeBehavior(value.GetType());

            if (behavior != null)
            {
                context.Push(behavior);
                return;
            }

            context.Push(value.GetType());
        }
Esempio n. 7
0
        private static void DoGetBlock(ExecutionContext context)
        {
            context.InstructionPointer++;
            byte arg = context.Block.ByteCodes[context.InstructionPointer];

            Block newblock = (Block)context.Block.GetConstant(arg);

            newblock = newblock.Clone(context);

            context.Push(newblock);
        }
Esempio n. 8
0
 private static void DoBasicSize(ExecutionContext context)
 {
     IIndexedObject indexedObj = (IIndexedObject)context.Pop();
     context.LastReceiver = indexedObj;
     context.Push(indexedObj.BasicSize);
 }
Esempio n. 9
0
 public void ReturnToContext(ExecutionContext retcontext, object retvalue)
 {
     this.context = retcontext;
     this.context.Push(retvalue);
 }
Esempio n. 10
0
 public void PushContext(ExecutionContext newcontext)
 {
     newcontext.Sender = this.context;
     this.context = newcontext;
 }
Esempio n. 11
0
 public void PopContext(object retvalue)
 {
     this.context = this.context.Sender;
     this.context.Push(retvalue);
 }
Esempio n. 12
0
 public Interpreter(ExecutionContext context)
 {
     this.context = context;
 }
Esempio n. 13
0
        public Block Clone(ExecutionContext closure)
        {
            Block newblock = (Block)this.MemberwiseClone();

            newblock.closure = closure;
            return newblock;
        }