예제 #1
0
	    protected internal virtual void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
	    {
	        if (g == null)
	            throw new ArgumentNullException(nameof(g));

	        OperandExtensions.SetLeakedState(this, false);
	        EmitGet(g);
	        if (labelTrue != null && labelTrue.IsLabelExist)
	        {
	            g.IL.Emit(BranchSet.Normal.BrTrue, labelTrue.Value);
                if (labelFalse != null && labelFalse.IsLabelExist)
                {
                    g.IL.Emit(OpCodes.Br, labelFalse.Value);
                }
            }
	        else if (labelFalse != null && labelFalse.IsLabelExist)
	        {
	            g.IL.Emit(BranchSet.Normal.BrFalse, labelFalse.Value);
	        }
	        else
	        {
                throw new InvalidOperationException("No labels passed");
            }
	            
	    }
예제 #2
0
파일: Operand.cs 프로젝트: jimmmeh/runsharp
		public void EmitRef(CodeGen g)
		{
			if (Type.IsValueType)
				EmitAddressOf(g);
			else
				EmitGet(g);
		}
예제 #3
0
파일: Operand.cs 프로젝트: jimmmeh/runsharp
		internal virtual void EmitBranch(CodeGen g, BranchSet branchSet, Label label)
		{
			if (g == null)
				throw new ArgumentNullException("g");
			if (branchSet == null)
				throw new ArgumentNullException("branchSet");

			EmitGet(g);
			g.IL.Emit(branchSet.brTrue, label);
		}
예제 #4
0
        public void Generate(ParseTree parseTree) {
            if (parseTree == null) return;
            GeneratedOK = true;
            defaultClass = ag.Public.Class("Default");
            typeTable.Add("Default", defaultClass);
            mainMethod = defaultClass.Public.Static.Method(typeof(void), "Main");

            //generator stack
            typeStack.Push(defaultClass);
            funcStack.Push(mainMethod);

            //InitIO();
            InitRequiredType();
            PushScope();
            var ioOperand = mainMethod.Local(exp.New(typeTable["IO"]));

            ParseNode(parseTree.Root);
            
            if (GeneratedOK) {
                ag.Save();
                AppDomain.CurrentDomain.ExecuteAssembly(name + ".exe");
            }
        }
		public void EmitArgs(CodeGen g, Operand[] args)
		{
			if (args.Length != appliedSignature.Length)
				throw new InvalidOperationException();

			if (IsExpanded)
			{
				int fixedCount = methodSignature.Length - 1;
				Type expType = methodSignature[fixedCount].GetElementType();

				for (int i = 0; i < fixedCount; i++)
					EmitArg(g, i, args[i]);

				int arrayLen = args.Length - methodSignature.Length - 1;
				g.EmitI4Helper(arrayLen);
				g.IL.Emit(OpCodes.Newarr, expType);
				OpCode stelemCode = CodeGen.GetStelemOpCode(expType);
				for (int i = 0; i < arrayLen; i++)
				{
					g.IL.Emit(OpCodes.Dup);
					g.EmitI4Helper(i);
					if (stelemCode == OpCodes.Stobj)
						g.IL.Emit(OpCodes.Ldelema, expType);
					EmitArg(g, fixedCount + i, args[fixedCount + i]);
					if (stelemCode == OpCodes.Stobj)
						g.IL.Emit(OpCodes.Stobj, expType);
					else
						g.IL.Emit(stelemCode);
				}
			}
			else
			{
				for (int i = 0; i < args.Length; i++)
					EmitArg(g, i, args[i]);
			}
		}
예제 #6
0
	    protected void EmitGetHelper(CodeGen g, Operand op, Type desiredType, bool allowExplicitConversion)
	    {
            g.EmitGetHelper(op, desiredType,allowExplicitConversion);
	    }
예제 #7
0
        protected internal virtual void EmitAddressOf(CodeGen g)
		{
			throw new InvalidOperationException(string.Format(null, Properties.Messages.ErrOperandNotReferencible, GetType()));
		}
			internal override void EmitAddressOf(CodeGen g)
			{
				CheckScope(g);

				if (var == null)
				{
					RequireType();
					var = g.il.DeclareLocal(t);
				}

				g.il.Emit(OpCodes.Ldloca, var);
			}
예제 #9
0
        protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
		{
		    OperandExtensions.SetLeakedState(this, false); 
            _operand.EmitBranch(g, labelTrue, labelFalse);
        }
예제 #10
0
		public abstract void Emit(CodeGen g, Type from, Type to);
			internal override void EmitGet(CodeGen g)
			{
				CheckScope(g);

				if (var == null)
					throw new InvalidOperationException(Properties.Messages.ErrUninitializedVarAccess);

				g.il.Emit(OpCodes.Ldloc, var);
			}
예제 #12
0
 public override void Emit(CodeGen g, Operator op)
 {
     g.IL.Emit(OpCodes.Call, method);
 }
예제 #13
0
		    public override void Emit(CodeGen g, Type from, Type to)
		    {
		        var l = g.LocalInitedFromStack(from);

		        Type toUnderlying = Helpers.GetNullableUnderlyingType(to);
		        Type fromUnderlying = Helpers.GetNullableUnderlyingType(from);
		        var cond = new Conditional(
		            l.Property("HasValue"),
		            new NewObject(
		                g.TypeMapper.TypeInfo.FindConstructor(to, new Operand[] { new FakeTypedOperand(toUnderlying), }),
		                new Operand[] { new ConversationWrapper(_internalConversation, l.Property("Value"), fromUnderlying, toUnderlying) }),
		            new DefaultValue(to));


		        //GetImplicit(l.Property("Value"), toUnderlying, false, g.TypeMapper), l, from, toUnderlying
		        cond.EmitGet(g);
		    }
예제 #14
0
 internal override void EmitAddressOf(CodeGen g)
 {
     _op.EmitAddressOf(g);
 }
예제 #15
0
 public override void Emit(CodeGen g, Operator op)
 {
     g.IL.Emit(OpCodes.Call, miRemove);
     g.IL.Emit(OpCodes.Castclass, ReturnType);
 }
예제 #16
0
 internal virtual void EmitGet(CodeGen g)
 {
     throw new InvalidOperationException(string.Format(null, Messages.ErrOperandNotReadable, GetType()));
 }
예제 #17
0
 public abstract void Emit(CodeGen g, Type from, Type to);
예제 #18
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     _before.Emit(g, from, _fromType);
     g.IL.Emit(OpCodes.Call, (MethodInfo)_method.Member);
     _after.Emit(g, _toType, to);
 }
예제 #19
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     g.IL.Emit(OpCodes.Box, from);
 }
예제 #20
0
 public override void Emit(CodeGen g, Operator op)
 {
     base.Emit(g, op);
 }
예제 #21
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     throw new AmbiguousMatchException(string.Format(null, Messages.ErrAmbiguousConversion, from.FullName, to.FullName));
 }
예제 #22
0
 protected void EmitGetHelper(CodeGen g, Operand op, Type desiredType, bool allowExplicitConversion)
 {
     g.EmitGetHelper(op, desiredType, allowExplicitConversion);
 }
예제 #23
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     g.IL.Emit(OpCodes.Castclass, to);
 }
예제 #24
0
 public void _ManualEmitGet(CodeGen g) => EmitGet(g);
예제 #25
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     g.EmitConvHelper(Type.GetTypeCode(to));
 }
예제 #26
0
 protected internal virtual void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion)
 {
     throw new InvalidOperationException(string.Format(null, Properties.Messages.ErrOperandNotWritable, GetType()));
 }
			internal override void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion)
			{
				CheckScope(g);

				if (t == null)
					t = value.Type;

				if (var == null)
					var = g.il.DeclareLocal(t);

				g.EmitGetHelper(value, t, allowExplicitConversion);
				g.il.Emit(OpCodes.Stloc, var);
			}
예제 #28
0
 protected internal virtual void EmitAddressOf(CodeGen g)
 {
     throw new InvalidOperationException(string.Format(null, Properties.Messages.ErrOperandNotReferencible, GetType()));
 }
예제 #29
0
        protected internal override void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion)
		{
		    OperandExtensions.SetLeakedState(this, false);  
            OperandExtensions.SetLeakedState(this, false);
            _operand.EmitSet(g, value, allowExplicitConversion);
        }
예제 #30
0
 protected internal override void EmitAddressOf(CodeGen g)
 {
     OperandExtensions.SetLeakedState(this, false);
     _op.EmitAddressOf(g);
 }
예제 #31
0
		protected internal void EmitRef(CodeGen g)
		{
            OperandExtensions.SetLeakedState(this, false);
            if (GetReturnType(g.TypeMapper).IsValueType)
				EmitAddressOf(g);
			else
				EmitGet(g);
		}
예제 #32
0
 protected ILGenerator GetILGenerator(CodeGen g)
 {
     return(g.IL);
 }
예제 #33
0
        protected internal virtual void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion)
		{
			throw new InvalidOperationException(string.Format(null, Properties.Messages.ErrOperandNotWritable, GetType()));
		}
예제 #34
0
		    public override void Emit(CodeGen g, Type from, Type to)
			{
				g.EmitConvHelper(Type.GetTypeCode(to));
			}
예제 #35
0
			protected internal override void EmitAddressOf(CodeGen g)
		    {
		        OperandExtensions.SetLeakedState(this, false);  
				_op.EmitAddressOf(g);
			}
예제 #36
0
		    public override void Emit(CodeGen g, Type from, Type to)
		    {
		        g.IL.Emit(
		            OpCodes.Call,
		            g.TypeMapper.MapType(typeof(Nullable<>)).MakeGenericType(Helpers.GetNullableUnderlyingType(from))
		                .GetProperty(nameof(Nullable<int>.Value)).GetGetMethod());
		    }
예제 #37
0
	    protected ILGenerator GetILGenerator(CodeGen g)
	    {
	        return g.IL;
	    }
예제 #38
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     throw new InvalidCastException(string.Format(null, Messages.ErrInvalidConversion, from == null ? "<null>" : from.FullName, to.FullName));
 }
예제 #39
0
		    public override void Emit(CodeGen g, Type from, Type to)
			{
				g.IL.Emit(OpCodes.Box, from);
			}
예제 #40
0
			public override void Emit(CodeGen g, Type from, Type to)
			{
				g.IL.Emit(OpCodes.Castclass, to);
			}
예제 #41
0
            public override void Emit(CodeGen g, Type from, Type to)
		    {
                _fromConv?.Emit(g, from, Helpers.GetNullableUnderlyingType(to));
		        g.IL.Emit(
		            OpCodes.Newobj,
		            to.GetConstructor(new[] { from }));
		    }
예제 #42
0
		    public override void Emit(CodeGen g, Type from, Type to)
			{
				throw new AmbiguousMatchException(string.Format(null, Properties.Messages.ErrAmbiguousConversion, from.FullName, to.FullName));
			}
예제 #43
0
		    public override void Emit(CodeGen g, Type from, Type to)
			{
				g.IL.Emit(OpCodes.Unbox_Any, to);
			}
예제 #44
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
     g.IL.Emit(OpCodes.Unbox_Any, to);
 }
예제 #45
0
		    public override void Emit(CodeGen g, Type from, Type to)
			{
				throw new InvalidCastException(string.Format(null, Properties.Messages.ErrInvalidConversion, from == null ? "<null>" : from.FullName, to.FullName));
			}
			public _Local(CodeGen owner, LocalBuilder var)
			{
				this.owner = owner;
				this.var = var;
				this.t = var.LocalType;
			}
예제 #47
0
			public override void Emit(CodeGen g, Type from, Type to)
			{
				_before.Emit(g, from, _fromType);
				g.IL.Emit(OpCodes.Call, (MethodInfo)_method.Member);
				_after.Emit(g, _toType, to);
			}
			void CheckScope(CodeGen g)
			{
				if (g != owner)
					throw new InvalidOperationException(Properties.Messages.ErrInvalidVariableContext);
				if (scope != null && !owner.blocks.Contains(scope))
					throw new InvalidOperationException(Properties.Messages.ErrInvalidVariableScope);
			}
예제 #49
0
			public override void Emit(CodeGen g, Type from, Type to)
			{
			}
예제 #50
0
 public override void Emit(CodeGen g, Type from, Type to)
 {
 }