Example #1
0
        public IodineGenerator(StackFrame parentFrame, IodineInstanceMethodWrapper baseMethod,
			IodineObject[] args)
            : base(TypeDef)
        {
            arguments = args;
            self = baseMethod.Self;
            this.baseMethod = baseMethod.Method;
        }
		public StackFrame (IodineMethod method, StackFrame parent, IodineObject self, int localCount,
		                   IodineObject[] locals) : this (method, parent, self, localCount)
		{
			parentLocals = locals;
			this.locals = new IodineObject[localCount];
			for (int i = 0; i < localCount; i++) {
				this.locals [i] = locals [i]; 
			}
		}
		public StackFrame (IodineMethod method, StackFrame parent, IodineObject self, int localCount)
		{
			LocalCount = localCount;
			locals = new IodineObject[localCount];
			parentLocals = locals;
			Method = method;
			Self = self;
			Parent = parent;
		}
		public NativeStackFrame (InternalMethodCallback method, StackFrame parent)
			: base (null, parent, null, 0)
		{
			this.NativeMethod = method;
		}
		internal StackFrame Duplicate (StackFrame top, int localCount)
		{
			if (localCount > LocalCount) {
				IodineObject[] oldLocals = locals;
				locals = new IodineObject[localCount];
				Array.Copy (oldLocals, locals, oldLocals.Length);
			}
			return new StackFrame (Method, top, Self, Math.Max (LocalCount, localCount), locals);
		}
Example #6
0
			public DebugResponse (SourceLocation location, StackFrame frame)
			{
				Location = location;
				Frame = frame;
			}
Example #7
0
        private IodineObject Invoke(IodineMethod method, IodineObject[] arguments)
        {
            if (method.Body.Count > 0)
            {
                currentLocation = method.Body [0].Location;
            }

            int insCount      = method.Body.Count;
            int prevStackSize = stackSize;
            int i             = 0;

            foreach (string param in method.Parameters.Keys)
            {
                if (method.Variadic && (method.AcceptsKeywordArgs ? i == method.Parameters.Keys.Count - 2 :
                                        i == method.Parameters.Keys.Count - 1))
                {
                    IodineObject[] tupleItems = new IodineObject[arguments.Length - i];
                    Array.Copy(arguments, i, tupleItems, 0, arguments.Length - i);
                    Top.StoreLocal(method.Parameters [param], new IodineTuple(tupleItems));
                }
                else if (i == method.Parameters.Keys.Count - 1 && method.AcceptsKeywordArgs)
                {
                    if (i < arguments.Length && arguments [i] is IodineHashMap)
                    {
                        Top.StoreLocal(method.Parameters [param], arguments [i]);
                    }
                    else
                    {
                        Top.StoreLocal(method.Parameters [param], new IodineHashMap());
                    }
                }
                else
                {
                    Top.StoreLocal(method.Parameters [param], arguments [i++]);
                }
            }
            StackFrame top = Top;

            if (traceCallback != null)
            {
                Trace(TraceType.Function, top, currentLocation);
            }

            while (top.InstructionPointer < insCount && !top.AbortExecution && !Top.Yielded)
            {
                instruction = method.Body [Top.InstructionPointer++];
                if (traceCallback != null && instruction.Location.Line != currentLocation.Line)
                {
                    Trace(TraceType.Line, top, instruction.Location);
                }
                ExecuteInstruction();
                top.Location = currentLocation;
            }

            IodineObject retVal = lastObject ?? IodineNull.Instance;

            while (top.DisposableObjects.Count > 0)
            {
                top.DisposableObjects.Pop().Exit(this);
            }

            stackSize = prevStackSize;

            if (top.AbortExecution)
            {
                return(IodineNull.Instance);
            }

            EndFrame();

            return(retVal);
        }
Example #8
0
 public IodineClosure(StackFrame frame, IodineMethod target)
     : base(TypeDefinition)
 {
     this.frame = frame;
     Target     = target;
 }
Example #9
0
 public IodineGenerator(StackFrame parentFrame, IodineMethod baseMethod, IodineObject[] args)
     : base(TypeDef)
 {
     arguments = args;
     this.baseMethod = baseMethod;
 }
Example #10
0
 private void NewFrame(IodineMethod method, IodineObject self, int localCount)
 {
     frameCount++;
     Top = new StackFrame (method, Top, self, localCount);
     frames.Push (Top);
 }
Example #11
0
 public StackFrame EndFrame()
 {
     frameCount--;
     StackFrame ret = frames.Pop ();
     if (frames.Count != 0) {
         Top = frames.Peek ();
     } else {
         Top = null;
     }
     return ret;
 }
Example #12
0
 private void NewFrame(StackFrame frame)
 {
     frameCount++;
     Top = frame;
     frames.Push (frame);
 }
Example #13
0
 public void Unwind(int frames)
 {
     for (int i = 0; i < frames; i++) {
         StackFrame frame = this.frames.Pop ();
         frame.AbortExecution = true;
     }
     frameCount -= frames;
     Top = this.frames.Peek ();
 }
Example #14
0
        public IodineObject InvokeMethod(IodineMethod method, StackFrame frame, IodineObject self,
		                                  IodineObject[] arguments)
        {
            int requiredArgs = method.AcceptsKeywordArgs ? method.ParameterCount - 1 :
                method.ParameterCount;
            if ((method.Variadic && arguments.Length + 1 < requiredArgs) ||
                (!method.Variadic && arguments.Length < requiredArgs)) {
                RaiseException (new IodineArgumentException (method.ParameterCount));
                return null;
            }

            NewFrame (frame);
            return Invoke (method, arguments);
        }
Example #15
0
 public UnhandledIodineExceptionException(StackFrame frame, IodineObject original)
 {
     OriginalException = original;
     Frame = frame;
 }
Example #16
0
 public override void IterReset(VirtualMachine vm)
 {
     stackFrame = new StackFrame (baseMethod, vm.Top, null, this.baseMethod.LocalCount);
 }
Example #17
0
		public IodineClosure (StackFrame frame, IodineMethod target)
			: base (TypeDefinition)
		{
			this.frame = frame;
			Target = target;
		}
Example #18
0
		private void Trace (TraceType type, StackFrame frame, SourceLocation location)
		{
			pauseVirtualMachine.WaitOne ();
			if (traceCallback (type, this, frame, location)) {
				pauseVirtualMachine.Reset ();
			}
		}