public object Execute() { ExecutionContext context = this.block.CreateContext(this.machine, this.arguments); this.interpreter = new Interpreter(context); return this.interpreter.Execute(); }
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); }
public object ExecuteInInterpreter(Interpreter interpreter, IObject self, object[] args) { interpreter.PushContext(new ExecutionContext(interpreter.Machine, self, this, args)); return interpreter; }
protected override object DoesNotUnderstand(Interpreter interpreter, IObject self, string msgname, object[] args) { return this.DoesNotUnderstand(interpreter.Machine, self, msgname, args); }
public virtual object ExecuteInInterpreter(Interpreter interpreter, object[] args) { interpreter.PushContext(this.CreateContext(interpreter.Machine, args)); return interpreter; }
public virtual object ExecuteMethod(Interpreter interpreter, IMethod method, object[] arguments) { return method.ExecuteInInterpreter(interpreter, this, arguments); }
public override object ExecuteMethod(Interpreter interpreter, IMethod method, object[] arguments) { Message message = new Message(interpreter.Machine, method, arguments); this.queue.PostMessage(message); return null; // TODO what to return? }
public object ExecuteMethod(Interpreter interpreter, IMethod method, object[] arguments) { return this.obj.ExecuteMethod(interpreter, method, arguments); }
public static object SendMessage(Interpreter interpreter, object obj, string msgname, object[] args) { if (obj == null) return SendNativeMessage(interpreter.Machine, obj, msgname, args); NativeBehavior behavior = interpreter.Machine.GetNativeBehavior(obj.GetType()); if (behavior != null) { IMethod mth = behavior.GetInstanceMethod(msgname); if (mth != null) return mth.ExecuteNativeInInterpreter(interpreter, obj, args); } string mthname = msgname; int p = msgname.IndexOf(":"); if (p > 0) mthname = msgname.Substring(0, p); else mthname = msgname; if (obj is Type) { if (msgname == "new" || msgname.StartsWith("new:")) return NewObject((Type)obj, args); } if (obj is IList) { behavior = interpreter.Machine.GetNativeBehavior(typeof(IList)); IMethod mth = behavior.GetInstanceMethod(msgname); if (mth != null) return mth.ExecuteNativeInInterpreter(interpreter, obj, args); } if (obj is IEnumerable) { behavior = interpreter.Machine.GetNativeBehavior(typeof(IEnumerable)); IMethod mth = behavior.GetInstanceMethod(msgname); if (mth != null) return mth.ExecuteNativeInInterpreter(interpreter, obj, args); } // TODO how to use doesNotUnderstand in native behavior // mth = behavior.GetInstanceMethod("doesNotUnderstand:with:"); // if (mth != null) // return mth.ExecuteNative(obj, new object[] { msgname, args }); return SendNativeMessage(interpreter.Machine, obj, mthname, args); }
public object SendMessageToObject(IObject self, Interpreter interpreter, string msgname, object[] args) { IMethod mth = this.GetInstanceMethod(msgname); // TODO refactor self == null, it could be all in SendMessageToNilObject if (mth != null) return self.ExecuteMethod(interpreter, mth, args); mth = this.GetInstanceMethod("doesNotUnderstand:with:"); if (mth != null) return self.ExecuteMethod(interpreter, mth, new object[] { msgname, args }); return DotNetObject.SendMessage(interpreter.Machine, self, msgname, args); }
public object ExecuteNativeInInterpreter(Interpreter interpreter, object self, object[] args) { throw new NotImplementedException(); }
public object ExecuteInInterpreter(Interpreter interpreter, IObject self, object[] args) { return this.DoesNotUnderstand(interpreter, self, (string)args[0], (object[])args[1]); }
protected virtual object DoesNotUnderstand(Interpreter interpreter, IObject self, string msgname, object[] args) { if (interpreter.Machine.HostMachine != null) { IBehavior behavior = interpreter.Machine.HostMachine.GetAssociatedBehavior(self.Behavior); if (behavior != null) { IMethod method = behavior.GetInstanceMethod(msgname); if (method != null) return method.ExecuteInInterpreter(interpreter, self, args); method = behavior.GetInstanceMethod(this.Name); if (method != null) return method.ExecuteInInterpreter(interpreter, self, new object[] { msgname, args }); } } return DotNetObject.SendMessage(interpreter.Machine, self, msgname, args); }
public object SendMessage(object obj, string msgname, object[] args, Interpreter interpreter) { if (this.debug) { if (obj == null) Trace.Write("UndefinedObject"); else if ((obj as IObject) == null) Trace.Write(obj.GetType().FullName); else { IObject io = (IObject)obj; if (io.Behavior is IMetaClass) { IClass cls = ((IMetaClass)io.Behavior).ClassInstance; if (cls == null) Trace.Write("meta"); else Trace.Write(cls.Name); Trace.Write(" class"); } else Trace.Write(((IClass)io.Behavior).Name); } Trace.Write(">>"); Trace.WriteLine(msgname); } if (obj == null) return this.nilclass.SendMessageToNilObject(this, msgname, args); IObject iobj = obj as IObject; if (iobj != null) if (interpreter == null) return iobj.Behavior.SendMessageToObject(iobj, this, msgname, args); else return iobj.Behavior.SendMessageToObject(iobj, interpreter, msgname, args); if (interpreter != null) return DotNetObject.SendMessage(interpreter, obj, msgname, args); return DotNetObject.SendMessage(this, obj, msgname, args); }
public object ExecuteInInterpreter(Interpreter interpreter, IObject self, object[] args) { return this.Execute(interpreter.Machine, self, args); }
public object ExecuteNativeInInterpreter(Interpreter interpreter, object self, object[] args) { return this.nativeFunction(interpreter.Machine, self, args); }