Beispiel #1
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);
            _symbolConversion?.Emit(builder);

            if (_method.IsInstance)
            {
                if (((Owner == null || Owner.IsStatic) && _thisPtr == null) || _staticCall)
                {
                    ErrorManager.ExitWithError(new Exception("Can't call instance function from static context"));
                }


                if (!_valueType)
                {
                    builder.PushValue(_thisPtr ?? Owner.ThisPointer);
                }
                else
                {
                    builder.PushAddress(_thisPtr as CodeSymbol);
                }
            }

            foreach (var p in _parameters)
            {
                builder.PushValue(p);
            }

            if (_method.IsVirtual && !_baseAccess)
            {
                if (_valueType)
                {
                    //NOTE: This is sometimes emitted while not needed, like with System.Int32.ToString(), as these methods appear
                    //as virtual but actually aren't. I don't know why, but it still works so whatever.
                    builder.EmitLine("constrained. " + _thisPtr.Type.Name);
                }

                builder.EmitOpCode(OpCodes.Callvirt, _method.FullSignature);
            }
            else
            {
                builder.EmitOpCode(OpCodes.Call, _method.FullSignature);
            }

            builder.ShrinkStack(_parameters.Length);

            if (_return != CodeType.Void)
            {
                if (!_expression)
                {
                    builder.EmitOpCode(OpCodes.Pop);
                }
                else
                {
                    builder.ExpandStack(1);
                }
            }
        }
Beispiel #2
0
 public override void Push(IlBuilder builder)
 {
     if (Index <= 3)
     {
         builder.EmitOpCode(OpCodeUtil.GetOpcode("Ldloc_" + Index));
     }
     else
     {
         builder.EmitOpCode(OpCodeUtil.GetOpcode("Ldloc"), Index);
     }
 }
Beispiel #3
0
 public override void PushAddress(IlBuilder builder)
 {
     if (Index <= 255)
     {
         builder.EmitOpCode(OpCodes.Ldloca_S, Index);
     }
     else
     {
         builder.EmitOpCode(OpCodes.Ldloca, Index);
     }
 }
Beispiel #4
0
 public override void PushAddress(IlBuilder builder)
 {
     if (!Field.IsStatic)
     {
         builder.PushValue(_owner);
         builder.EmitOpCode(OpCodes.Ldflda, Type.ArgumentName, $"{ReferenceName}::{ID}");
     }
     else
     {
         builder.EmitOpCode(OpCodes.Ldsflda, Type.ArgumentName, $"{ReferenceName}::{ID}");
     }
 }
Beispiel #5
0
 public override void Store(IlBuilder builder, CodeValue val)
 {
     builder.PushValue(val);
     if (Index <= 3)
     {
         builder.EmitOpCode(OpCodeUtil.GetOpcode("Stloc_" + Index));
     }
     else
     {
         builder.EmitOpCode(OpCodeUtil.GetOpcode("Stloc"), Index);
     }
 }
Beispiel #6
0
 public override void Store(IlBuilder builder, CodeValue store)
 {
     if (!Field.IsStatic)
     {
         builder.PushValue(_owner);
         builder.PushValue(store);
         builder.EmitOpCode(OpCodes.Stfld, Type.ArgumentName, $"{ReferenceName}::{ID}");
     }
     else
     {
         builder.PushValue(store);
         builder.EmitOpCode(OpCodes.Stsfld, Type.ArgumentName, $"{ReferenceName}::{ID}");
     }
 }
Beispiel #7
0
        public override void ConvertFrom(CodeValue val, IlBuilder builder)
        {
            Debug.Assert(val.Type is UserType);
            //Console.WriteLine("WARING: trying to convert from Usertype " + Name + " to " + val.Type.Name);

            builder.PushValue(val);
            builder.EmitOpCode(OpCodes.Castclass, ShortName);
        }
Beispiel #8
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);

            if (hasValue)
            {
                _exp.Push(builder);
            }

            builder.EmitOpCode(OpCodes.Ret);
        }
Beispiel #9
0
 public override void ConvertTo(CodeValue val, IlBuilder builder, CodeType to)
 {
     if (to == BaseType)
     {
         builder.PushValue(val);
         builder.EmitOpCode(OpCodes.Unbox_Any, Name);
     }
     else
     {
         base.ConvertTo(val, builder, to);
     }
 }
Beispiel #10
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);

            builder.PushValue(_rank);

            builder.EmitOpCode(OpCodes.Newarr, _typeof.TypeOf.Name);

            if (_entries == null)
            {
                return;
            }

            for (int i = 0; i < _entries.Length; i++)
            {
                builder.EmitOpCode(OpCodes.Dup);

                builder.PushValue(new CodeValue(BasicType.Int32, i));
                builder.PushValue(_entries[i]);
                builder.EmitOpCode(OpCodeUtil.GetOpcode("Stelem_" + _typeof.TypeOf.OpName));
            }
        }
Beispiel #11
0
 public override void Push(IlBuilder builder)
 {
     if (_indexerCall == null)
     {
         builder.PushValue(_array);
         builder.PushValue(_index);
         builder.EmitOpCode(OpCodeUtil.GetOpcode("Ldelem_" + Type.OpName));
     }
     else
     {
         _indexerCall.Emit(builder);
     }
 }
Beispiel #12
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);


            string label1 = Owner.LabelManager.NextLabel;
            string label2 = Owner.LabelManager.NextLabel;

            builder.PushValue(_exp);

            builder.EmitOpCode(OpCodes.Brfalse, label1);

            builder.PushValue(_op1);
            builder.EmitOpCode(OpCodes.Br, label2);

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label1 + ": ");
            builder.PushValue(_op2);

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label2 + ": ");
            builder.EmitOpCode(OpCodes.Nop);
        }
Beispiel #13
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);

            bool or = _op.Type == Operator.OperatorType.Or;

            string label1 = Owner.LabelManager.NextLabel;
            string label2 = Owner.LabelManager.NextLabel;

            builder.PushValue(_op1);
            builder.EmitOpCode(or ? OpCodes.Brtrue : OpCodes.Brfalse, label1);

            builder.PushValue(_op2);
            builder.EmitOpCode(OpCodes.Br, label2);

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label1 + ": ");
            builder.PushValue(new CodeValue(CodeType.Int32, or ? 1 : 0));

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label2 + ": ");
            builder.EmitOpCode(OpCodes.Nop);
        }
Beispiel #14
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);

            foreach (var p in _parameters)
            {
                builder.PushValue(p);
            }

            builder.EmitOpCode(OpCodes.Newobj, _constructor.FullSignature);

            builder.ShrinkStack(_parameters.Length);
            builder.ExpandStack(1);
        }
Beispiel #15
0
 public override void Store(IlBuilder builder, CodeValue source)
 {
     if (_indexerCall == null)
     {
         builder.PushValue(_array);
         builder.PushValue(_index);
         builder.PushValue(source);
         builder.EmitOpCode(OpCodeUtil.GetOpcode("Stelem_" + Type.OpName));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Beispiel #16
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);

            _op?.Push(builder);

            OpCode op = Condition switch
            {
                BranchCondition.Always => OpCodes.Br,
                BranchCondition.OnFalse => OpCodes.Brfalse,
                BranchCondition.Leave => OpCodes.Leave,
                _ => OpCodes.Brtrue
            };

            builder.EmitOpCode(op, _label);
        }
Beispiel #17
0
 public override void Emit(IlBuilder builder)
 {
     base.Emit(builder);
     builder.EmitOpCode(OpCodes.Endfinally);
 }
Beispiel #18
0
 public override void Push(IlBuilder builder)
 => builder.EmitOpCode(OpCodes.Ldnull);
Beispiel #19
0
 public override void Store(IlBuilder builder, CodeValue val)
 {
     builder.PushValue(val);
     builder.EmitOpCode(OpCodeUtil.GetOpcode("Starg"), Index);
 }
Beispiel #20
0
 public virtual void Push(IlBuilder builder)
 => builder.EmitOpCode(Type.GetPushCode(), Value);