コード例 #1
0
ファイル: AstEmitter.cs プロジェクト: uranium62/ilwasm
        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
ファイル: SpecialIdentifiers.cs プロジェクト: c444b774/JSIL
        public JSNewExpression NewMemberReference(JSExpression target, JSLiteral member)
        {
            var resultType = new ByReferenceType(member.GetActualType(TypeSystem));

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