Example #1
0
        protected override void DoEmitCode(CompilerTarget target, StackSemantics stackSemantics)
        {
            var labelNs = @"Or\" + Guid.NewGuid().ToString("N");
            var trueLabel = @"True\" + labelNs;
            var falseLabel = @"False\" + labelNs;
            var evalLabel = @"Eval\" + labelNs;

            EmitCode(target, trueLabel, falseLabel);

            if (stackSemantics == StackSemantics.Value)
            {
                target.EmitLabel(Position, falseLabel);
                target.EmitConstant(Position, false);
                target.EmitJump(Position, evalLabel);
                target.EmitLabel(Position, trueLabel);
                target.EmitConstant(Position, true);
                target.EmitLabel(Position, evalLabel);
            }
            else
            {
                Debug.Assert(stackSemantics == StackSemantics.Effect);
                target.EmitLabel(Position, falseLabel);
                target.EmitLabel(Position, trueLabel);
            }
        }
Example #2
0
        protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics)
        {
            var constType = TypeExpr as AstConstantTypeExpression;

            var justEffect = stackSemantics == StackSemantics.Effect;
            if (constType != null)
            {
                EmitArguments(target);
                target.EmitStaticGetCall(Position, Arguments.Count, constType.TypeExpression, _memberId, justEffect);
            }
            else
            {
                TypeExpr.EmitValueCode(target);
                target.EmitConstant(Position, _memberId);
                EmitArguments(target);
                target.EmitGetCall(Position, Arguments.Count + 1, PType.StaticCallFromStackId, justEffect);
            }
        }
Example #3
0
 public void DoEmitPartialApplicationCode(CompilerTarget target)
 {
     var argv =
         AstPartiallyApplicable.PreprocessPartialApplicationArguments(
             Subject.Singleton().Append(Arguments));
     var ctorArgc = this.EmitConstructorArguments(target, argv);
     target.EmitConstant(Position, (int) Call);
     target.EmitConstant(Position, Id);
     target.EmitCommandCall(Position, ctorArgc + 2, Engine.PartialMemberCallAlias);
 }
Example #4
0
 public void DoEmitPartialApplicationCode(CompilerTarget target)
 {
     var argv =
         AstPartiallyApplicable.PreprocessPartialApplicationArguments(Arguments.ToList());
     var ctorArgc = this.EmitConstructorArguments(target, argv);
     var constType = _typeExpr as AstConstantTypeExpression;
     if (constType != null)
         target.EmitConstant(Position, constType.TypeExpression);
     else
         _typeExpr.EmitValueCode(target);
     target.EmitCommandCall(Position, ctorArgc + 1, Engine.PartialConstructionAlias);
 }
Example #5
0
        public void DoEmitPartialApplicationCode(CompilerTarget target)
        {
            var argv =
                AstPartiallyApplicable.PreprocessPartialApplicationArguments(Subject.Singleton());
            var ctorArgc = this.EmitConstructorArguments(target, argv);
            var constType = Type as AstConstantTypeExpression;
            if (constType != null)
                target.EmitConstant(Position, constType.TypeExpression);
            else
                Type.EmitValueCode(target);

            target.EmitCommandCall(Position, ctorArgc + 1, Engine.PartialTypeCastAlias);
        }
Example #6
0
 protected virtual void EmitSetCode(CompilerTarget target, StackSemantics stackSemantics)
 {
     var constType = TypeExpr as AstConstantTypeExpression;
     var justEffect = stackSemantics == StackSemantics.Effect;
     if (constType != null)
     {
         EmitArguments(target, !justEffect, 0);
         target.EmitStaticSetCall(Position, Arguments.Count, constType.TypeExpression + "::" + _memberId);
     }
     else
     {
         TypeExpr.EmitValueCode(target);
         target.EmitConstant(Position, _memberId);
         EmitArguments(target, !justEffect, 2);
         //type.StaticCall\FromStack(memberId, args...)
         target.EmitSetCall(Position, Arguments.Count + 1, PType.StaticCallFromStackId);
     }
 }
Example #7
0
 public void DoEmitPartialApplicationCode(CompilerTarget target)
 {
     var argv = AstPartiallyApplicable.PreprocessPartialApplicationArguments(Arguments);
     var ctorArgc = this.EmitConstructorArguments(target, argv);
     var constTypeExpr = TypeExpr as AstConstantTypeExpression;
     if (constTypeExpr != null)
         target.EmitConstant(constTypeExpr.Position, constTypeExpr.TypeExpression);
     else
         TypeExpr.EmitValueCode(target);
     target.EmitConstant(Position, (int) Call);
     target.EmitConstant(Position, _memberId);
     target.EmitCommandCall(Position, ctorArgc + 3, Engine.PartialStaticCallAlias);
 }
Example #8
0
        /// <summary>
        ///     Emits code for the AstStringConcatenation node.
        /// </summary>
        /// <param name = "target">The target to which to write the code to.</param>
        /// <param name="stackSemantics">The stack semantics with which to emit code. </param>
        /// <remarks>
        ///     <para>
        ///         AstStringConcatenation tries to find the most efficient way to concatenate strings. StringBuilders are actually slower when concatenating only two arguments.
        ///     </para>
        ///     <para>
        ///         <list type = "table">
        ///             <listheader>
        ///                 <term>Arguments</term>
        ///                 <description>Emitted code</description>
        ///             </listheader>
        ///             <item>
        ///                 <term>0</term>
        ///                 <description><c><see cref = "OpCode.ldc_string">ldc.string</see> ""</c> (Empty string)</description>
        ///             </item>
        ///             <item>
        ///                 <term>1</term>
        ///                 <description>Just that argument and, unless it is a <see cref = "AstConstant">string constant</see>, a call to <c>ToString</c>.</description>
        ///             </item>
        ///             <item>
        ///                 <term>2</term>
        ///                 <description>Concatenation using the Addition (<c><see cref = "OpCode.add">add</see></c>) operator.</description>
        ///             </item>
        ///             <item>
        ///                 <term>n</term>
        ///                 <description>A call to the <c><see cref = "Prexonite.Engine.ConcatenateAlias">concat</see></c> command.</description>
        ///             </item>
        ///         </list>
        ///     </para>
        /// </remarks>
        protected override void DoEmitCode(CompilerTarget target, StackSemantics stackSemantics)
        {
            if (_arguments.Count > 2)
            {
                var call = _multiConcatPrototype.GetCopy();
                call.Arguments.AddRange(Arguments);
                call.EmitCode(target, stackSemantics);
            }
            else if (_arguments.Count >= 2)
            {
                var call = _simpleConcatPrototype.GetCopy();
                call.Arguments.AddRange(Arguments);
                call.EmitCode(target, stackSemantics);
            }
            else if (_arguments.Count == 1)
            {
                if (stackSemantics == StackSemantics.Value)
                {
                    _arguments[0].EmitValueCode(target);

                    AstConstant constant;
                    if ((constant = _arguments[0] as AstConstant) != null &&
                        !(constant.Constant is string))
                        target.EmitGetCall(Position, 1, "ToString");
                }
                else
                {
                    _arguments[0].EmitEffectCode(target);
                }
            }
            else if (_arguments.Count == 0)
            {
                if(stackSemantics == StackSemantics.Value)
                    target.EmitConstant(Position, "");
            }
        }
Example #9
0
        protected override void DoEmitCode(CompilerTarget target, StackSemantics stackSemantics)
        {
            if(stackSemantics == StackSemantics.Effect)
                return;

            if (Constant == null)
                target.EmitNull(Position);
            else
                switch (Type.GetTypeCode(Constant.GetType()))
                {
                    case TypeCode.Boolean:
                        target.EmitConstant(Position, (bool) Constant);
                        break;
                    case TypeCode.Int16:
                    case TypeCode.Byte:
                    case TypeCode.Int32:
                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                        target.EmitConstant(Position, (int) Constant);
                        break;
                    case TypeCode.Single:
                    case TypeCode.Double:
                        target.EmitConstant(Position, (double) Constant);
                        break;
                    case TypeCode.String:
                        target.EmitConstant(Position, (string) Constant);
                        break;
                    default:
                        var moduleName = Constant as ModuleName;

                        if (moduleName != null)
                        {
                            target.EmitConstant(Position, moduleName);
                        }
                        else
                        {
                            throw new PrexoniteException(
                                "Prexonite does not support constants of type " +
                                    Constant.GetType().Name + ".");
                        }
                        break;
                }
        }