public override void Execute(Runtime runtime, Runtime.Thread thread) { if (!runtime.SetVar(runtime.globals, this.name, thread.PopValue())) { Runtime.RaiseRuntimeError(thread, this.span, "unknown global `" + this.name + "`"); } }
public override void Execute(Runtime runtime, Runtime.Thread thread) { var args = new object[this.argumentNum]; for (var i = 0; i < this.argumentNum; i++) { args[this.argumentNum - 1 - i] = thread.PopValue(); } var target = thread.PopValue(); var targetFunc = target as Runtime.Function; if (targetFunc != null) { if (targetFunc.parameterNames.Count != this.argumentNum) { Runtime.RaiseRuntimeError(thread, this.span, "expected " + targetFunc.parameterNames.Count + " argument(s)"); } thread.PushFrame(targetFunc); for (var i = 0; i < this.argumentNum; i++) { thread.CurrentFrame().locals.Add(targetFunc.parameterNames[i], args[i]); } return; } var targetExternal = target as Runtime.ExternalFunction; if (targetExternal != null) { try { thread.PushValue(targetExternal.Invoke(args)); } catch (System.Exception e) { Runtime.RaiseRuntimeError(thread, this.span, "external function error:\n\n" + e.Message + "\n\n" + e.StackTrace); } return; } Runtime.RaiseRuntimeError(thread, this.span, "object cannot be called as function"); }
public override void Execute(Runtime runtime, Runtime.Thread thread) { var obj = new Runtime.Object(); for (var i = 0; i < fieldNames.Count; i++) { obj.fields[fieldNames[fieldNames.Count - 1 - i]] = thread.PopValue(); } thread.PushValue(obj); }
public override void Execute(Runtime runtime, Runtime.Thread thread) { var value = thread.PopValue(); var target = thread.PopValue(); if (target == null) { Runtime.RaiseRuntimeError(thread, this.span, "field access on null value"); } var obj = target; while (obj != null) { Dictionary <string, object> fields; if (obj is Runtime.Object) { fields = ((Runtime.Object)obj).fields; } else { break; } object setFunc; if (fields.TryGetValue("set:" + this.fieldName, out setFunc)) { if (setFunc is Runtime.Function) { var f = (Runtime.Function)setFunc; thread.PushFrame(f); thread.CurrentFrame().locals.Add(f.parameterNames[0], target); thread.CurrentFrame().locals.Add(f.parameterNames[1], value); } else { thread.PushValue(((Runtime.ExternalFunction)setFunc).Invoke(new object[] { target, value })); } return; } if (fields.ContainsKey(this.fieldName)) { fields[this.fieldName] = value; return; } if (obj is Runtime.Object) { obj = ((Runtime.Object)obj).proto; } else { break; } } Runtime.RaiseRuntimeError(thread, this.span, "unknown field `" + this.fieldName + "`"); }
public override void Execute(Runtime runtime, Runtime.Thread thread) { var target = thread.PopValue(); if (target == null) { Runtime.RaiseRuntimeError(thread, this.span, "field access on null value"); } var obj = target; while (obj != null) { Dictionary <string, object> fields; if (obj is double) { fields = runtime.doubleMethods; } else if (obj is bool) { fields = runtime.boolMethods; } else if (obj is string) { fields = runtime.stringMethods; } else if (obj is Runtime.Object) { fields = ((Runtime.Object)obj).fields; } else { break; } object getFunc; if (!this.duplicateTargetAfter && fields.TryGetValue("get:" + this.fieldName, out getFunc)) { if (getFunc is Runtime.Function) { var f = (Runtime.Function)getFunc; thread.PushFrame(f); thread.CurrentFrame().locals.Add(f.parameterNames[0], target); } else { thread.PushValue(((Runtime.ExternalFunction)getFunc).Invoke(new object[] { target })); } return; } object value; if (fields.TryGetValue(this.fieldName, out value)) { thread.PushValue(value); if (this.duplicateTargetAfter) { thread.PushValue(target); } return; } if (obj is Runtime.Object) { obj = ((Runtime.Object)obj).proto; } else { break; } } Runtime.RaiseRuntimeError(thread, this.span, "unknown field `" + this.fieldName + "`"); }
public override void Execute(Runtime runtime, Runtime.Thread thread) { thread.PopValue(); }