예제 #1
0
        public void VisitNode(JSLiteral literal)
        {
            var literalType = literal.GetActualType(TypeSystem);
            var typeToken   = WasmUtil.PickTypeKeyword(literalType);

            if (typeToken == null)
            {
                Console.WriteLine("AstEmitter Unhandled literal type {0}", literalType.FullName);

                Formatter.WriteSExpr("untranslatable.literal");
            }

            dynamic literalValue;

            if (literal is JSDefaultValueLiteral)
            {
                literalValue = 0;
            }
            else
            {
                literalValue = (dynamic)literal.Literal;
                if (literalValue is bool)
                {
                    literalValue = (literalValue ? 1 : 0);
                }
            }

            Formatter.WriteSExpr(
                "const." + typeToken,
                // HACK
                (_) => Formatter.Value(literalValue)
                );
        }
예제 #2
0
        private void VisitLiteral(JSLiteral literal, TypeReference forcedType = null)
        {
            var literalType = forcedType ?? literal.GetActualType(TypeSystem);

            if ((literal is JSNullLiteral) && (literalType.FullName == "System.Object"))
            {
                // HACK: ILSpy screws up the type inference...
                VisitStringLiteral(null);
                return;
            }

            var typeToken = WasmUtil.PickTypeKeyword(literalType);

            if (typeToken == null)
            {
                Console.WriteLine("AstEmitter Unhandled literal type {0}", literalType.FullName);

                Formatter.WriteSExpr("untranslatable.literal");
            }

            if (literalType.FullName == "System.String")
            {
                if ((literal is JSDefaultValueLiteral) || (literal is JSNullLiteral))
                {
                    VisitStringLiteral(null);
                }
                else
                {
                    var literalStr = (string)literal.Literal;
                    VisitStringLiteral(literalStr);
                }
                return;
            }

            dynamic literalValue;

            if (literal is JSDefaultValueLiteral)
            {
                literalValue = 0;
            }
            else
            {
                literalValue = (dynamic)literal.Literal;
                if (literalValue is bool)
                {
                    literalValue = (literalValue ? 1 : 0);
                }
                else if (literalValue is char)
                {
                    literalValue = (int)(char)literalValue;
                }
            }

            Formatter.WriteSExpr(
                typeToken + ".const",
                // HACK
                (_) => Formatter.Value(literalValue)
                );
        }
예제 #3
0
        public JSNewExpression NewMemberReference(JSExpression target, JSLiteral member)
        {
            var resultType = new ByReferenceType(member.GetActualType(TypeSystem));

            return(new JSNewExpression(
                       Dot("MemberReference", resultType),
                       null, null, target, member
                       ));
        }
예제 #4
0
        public JSNewExpression NewMemberReference(JSExpression target, JSLiteral member)
        {
            var resultType = new ByReferenceType(member.GetActualType(TypeSystem));

            return new JSNewExpression(
                Dot("MemberReference", resultType),
                null, null, target, member
            );
        }