示例#1
0
        public void VisitNode(JSUnaryOperatorExpression uoe)
        {
            var exType = uoe.Expression.GetActualType(TypeSystem);
            var opType = uoe.ActualType;

            if (IsLongOrULong(exType) && IsLongOrULong(opType)) //exType == TypeSystem.Int64 && opType == TypeSystem.Int64)
            {
                string verb;
                switch (uoe.Operator.Token)
                {
                case "-":
                    verb = "op_UnaryNegation";
                    break;

                case "~":
                    verb = "op_OnesComplement";
                    break;

                default:
                    throw new NotSupportedException();
                }

                var method      = new JSFakeMethod(verb, TypeSystem.Int64, new[] { TypeSystem.Int64 }, MethodTypeFactory);
                var replacement = JSInvocationExpression.InvokeStatic(exType, method, new[] { uoe.Expression }, true);
                ParentNode.ReplaceChild(uoe, replacement);
                VisitReplacement(replacement);
                return;
            }

            VisitChildren(uoe);
        }
示例#2
0
        public JSSpecialIdentifiers(MethodTypeFactory methodTypes, TypeSystem typeSystem)
        {
            TypeSystem  = typeSystem;
            MethodTypes = methodTypes;

            prototype    = Object("prototype");
            eval         = new JSFakeMethod("eval", TypeSystem.Object, new[] { TypeSystem.String }, methodTypes);
            toString     = new JSFakeMethod("toString", TypeSystem.String, null, methodTypes);
            floor        = new JSDotExpression(Object("Math"), new JSFakeMethod("floor", TypeSystem.Int32, null, methodTypes));
            fromCharCode = new JSDotExpression(Object("String"), new JSFakeMethod("fromCharCode", TypeSystem.Char, new[] { TypeSystem.Int32 }, methodTypes));
            charCodeAt   = new JSFakeMethod("charCodeAt", TypeSystem.Int32, new[] { TypeSystem.Char }, methodTypes);
        }
示例#3
0
        public void VisitNode(JSFakeMethod fakeMethod)
        {
            Output.Identifier(fakeMethod.Name);

            var ga = fakeMethod.GenericArguments;

            if (ga != null)
            {
                Output.LPar();
                CommaSeparatedList(ga);
                Output.RPar();
            }
        }
示例#4
0
        private void VisitFakeMethod(JSInvocationExpression ie, JSFakeMethod fakeMethod)
        {
            if (TypeUtil.IsDelegateType(fakeMethod.ReturnType) && fakeMethod.Name == "New")
            {
                var type = (JSType)ie.Arguments[0];
                // FIXME: What the heck is in arg1????
                var method = UnwrapDeferred <JSMethod>(ie.Arguments[2]);

                var methodDef  = method.Reference.Resolve();
                var memberName = WasmUtil.FormatMemberName(methodDef);

                Formatter.WriteRaw("(i32.const {0} (; {1} ;))", AssemblyEmitter.GetFunctionIndex(methodDef), methodDef.FullName);
                return;
            }

            Console.WriteLine("Can't translate fake method {0}", ie);
            Formatter.WriteSExpr("untranslatable.call");
            return;
        }
示例#5
0
        public void VisitNode(JSBinaryOperatorExpression boe)
        {
            var leftType  = boe.Left.GetActualType(TypeSystem);
            var rightType = boe.Right.GetActualType(TypeSystem);

            TypeReference expectedType;

            try
            {
                // GetExpectedType can throw NoExpectedTypeException
                // Shouldn't it return null or something like a NoType instead?
                expectedType = boe.GetActualType(TypeSystem);
            }
            catch (NoExpectedTypeException)
            {
                expectedType = null;
            }

            var isLongExpression = IsLongOrULong(leftType) || IsLongOrULong(rightType);

            bool isUnsigned = (leftType.MetadataType == MetadataType.UInt64) || (rightType.MetadataType == MetadataType.UInt64);
            var  resultType = isUnsigned ? TypeSystem.UInt64 : TypeSystem.Int64;

            var assignmentOperator = boe.Operator as JSAssignmentOperator;

            if ((assignmentOperator != null) && (isLongExpression))
            {
                if (assignmentOperator == JSOperator.Assignment)
                {
                    VisitChildren(boe);
                    return;
                }

                // Deconstruct the mutation assignment so we can insert the appropriate operator call.
                var replacement = IntroduceEnumCasts.DeconstructMutationAssignment(boe, TypeSystem, resultType);
                ParentNode.ReplaceChild(boe, replacement);
                VisitReplacement(replacement);
            }
            else if (isLongExpression)
            {
                var verb = GetVerb(boe.Operator);

                if (verb == null)
                {
                    throw new NotImplementedException("Int64 operator not yet supported: " + boe.Operator.Token);
                }

                JSIdentifier method = new JSFakeMethod(
                    verb, resultType,
                    new[] { leftType, rightType }, MethodTypeFactory
                    );

                var replacement = JSInvocationExpression
                                  .InvokeStatic(leftType, method, new[] { boe.Left, boe.Right }, true);

                ParentNode.ReplaceChild(boe, replacement);
                VisitReplacement(replacement);
            }
            else
            {
                VisitChildren(boe);
            }
        }