Exemplo n.º 1
0
        public static void AppendStrings(ByteCodeGenerator generator, DefinedType sb, ExpressionNode node)
        {
            if (node is AdditiveNode)
            {
                var addNode = node as AdditiveNode;

                generator.Kill();
                var addType = new AdditiveCompiler(addNode).Compile(generator).Type;
                generator.Revive();

                if (addType.Name == BuiltinTypes.String.Name)
                {
                    AppendStrings(generator, sb, addNode.LeftChild.Child);
                    AppendStrings(generator, sb, addNode.RightChild.Child);

                    return;
                }
            }

            var item = new ExpressionCompiler(node).Compile(generator);

            var appendMethod = sb.FindMethod(generator, "append", new List<Type> { item.Type });
            if (appendMethod == null) throw new InvalidOperationException();

            item.Load();
            new MemberItem(generator, appendMethod, false).Invoke();
        }
Exemplo n.º 2
0
        public static void BufferToString(ByteCodeGenerator generator, DefinedType sb)
        {
            var toString = sb.FindMethod(generator, "toString", null);
            if (toString == null) throw new InvalidOperationException();

            new MemberItem(generator, toString, false).Invoke();
        }
Exemplo n.º 3
0
        private static Item CompileMethod(ByteCodeGenerator generator, DefinedType parentType, PrimaryNode.TermMethodExpression id)
        {
            generator.Kill();
            var args = id.Arguments.Select(parameter => new TranslationCompiler(parameter).Compile(generator).Type).ToList();
            generator.Revive();

            var method = parentType.FindMethod(generator, id.Identifier, args);
            if (method == null) throw new InvalidOperationException();

            foreach (var arg in method.Parameters.Zip(id.Arguments, (dst, src) => new { dst, src }))
            {
                new TranslationCompiler(arg.src, arg.dst.Type).Compile(generator).Load();
            }

            var isSuper = false;
            if (generator.Method.DeclaringType is Class)
            {
                isSuper = parentType == ((Class)generator.Method.DeclaringType).Super;
            }

            var item = method.Modifiers.HasFlag(Modifier.Static)
               ? (Item)new StaticItem(generator, method)
               : new MemberItem(generator, method, method.Name == "<init>" || isSuper);

            return item.Invoke();
        }