示例#1
0
 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 + "`");
     }
 }
示例#2
0
 public override void Execute(Runtime runtime, Runtime.Thread thread)
 {
     if (!runtime.DelVar(thread.CurrentFrame().locals, this.name))
     {
         Runtime.RaiseRuntimeError(thread, this.span, "unknown local `" + this.name + "`");
     }
 }
示例#3
0
 public override void Execute(Runtime runtime, Runtime.Thread thread)
 {
     if (!runtime.NewVar(runtime.globals, this.name))
     {
         Runtime.RaiseRuntimeError(thread, this.span, "duplicate global `" + this.name + "`");
     }
 }
示例#4
0
            public override void Execute(Runtime runtime, Runtime.Thread thread)
            {
                object value;

                if (!runtime.GetVar(runtime.globals, this.name, out value))
                {
                    Runtime.RaiseRuntimeError(thread, this.span, "unknown global `" + this.name + "`");
                }

                thread.PushValue(value);
            }
示例#5
0
            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);
            }
示例#6
0
            public override void Execute(Runtime runtime, Runtime.Thread thread)
            {
                var cond = thread.stackData[thread.stackData.Count - 1];

                thread.stackData.RemoveAt(thread.stackData.Count - 1);

                if (cond is bool && (bool)cond)
                {
                    thread.CurrentFrame().Goto(destinationIfTrue);
                }
                else
                {
                    thread.CurrentFrame().Goto(destinationIfFalse);
                }
            }
示例#7
0
            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");
            }
示例#8
0
 public override void Execute(Runtime runtime, Runtime.Thread thread)
 {
     thread.CurrentFrame().Goto(destination);
 }
示例#9
0
 public override void Execute(Runtime runtime, Runtime.Thread thread)
 {
     thread.PopFrame();
 }
示例#10
0
            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 + "`");
            }
示例#11
0
 public override void Execute(Runtime runtime, Runtime.Thread thread)
 {
     thread.PushValue(this.literal);
 }
示例#12
0
            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 + "`");
            }
示例#13
0
 public abstract void Execute(Runtime runtime, Runtime.Thread thread);