﻿using System;
using SharpJVM.SharpJVM.Class;
using SharpJVM.SharpJVM.Runtime.DataArea;
using SharpJVM.SharpJVM.Runtime.DataArea.Heap;
using SharpJVM.SharpJVM.Runtime.HeapConstantsPool;
using SharpJVM.SharpJVM.Runtime.Instructions.Base;
using SharpJVM.SharpJVM.Runtime.Ref;

namespace SharpJVM.SharpJVM.Runtime.Instructions.References
{
	public class New:Index16Instruction
	{
		public New()
		{
		}
		public override void Execute(Frame frame)
		{
			HeapConstantPool ConstantPool = frame.method.ConstantPool;
			ClassRef classRef = (ClassRef)ConstantPool[Index];
			JavaClass Class = classRef.ResolvedClass();
			if (ClassIniter.CheckInitClass(Class, frame))
				return;
			if (Class.AccessFlag.Interface | Class.AccessFlag.Abstract) {
				//to do
				Console.WriteLine("instantiationerror");
				return;
			}
			JavaObject ObjRef = new JavaObject(Class);
			frame.operandStack.PushRef(ObjRef);
		}
	}
}