Search in sources :

Example 1 with JVMVariable

use of st.gravel.support.compiler.jvm.JVMVariable in project gravel by gravel-st.

the class SystemMapping method compileExpression_reference_.

public JVMClass[] compileExpression_reference_(final Node _anExpression, final Reference _aReference) {
    final JVMDefinedObjectType _ownerType;
    final BlockNode _fieldAccessed;
    final BlockInnerClass _aBlockInnerClass;
    final BlockNode _intermediate;
    final BlockNode _holderized;
    final JVMClassCompiler _jvmClassCompiler;
    final JVMClass _blockClass;
    _intermediate = ((BlockNode) IntermediateNodeRewriter.factory.visit_(BlockNode.factory.expression_(_anExpression)));
    _holderized = ((BlockNode) NonLocalTempWritesToHolderConverter.factory.visit_(_intermediate));
    _fieldAccessed = ((BlockNode) VariableAccessToFieldAccessConverter.factory.instVars_owner_ownerReference_(new VariableDeclarationNode[] {}, NilLiteralNode.factory.basicNew(), _aReference).visit_(_holderized));
    _ownerType = JVMDefinedObjectType.factory.dottedClassName_("Expression$" + _compilerTools.nextExtensionPostfix());
    _aBlockInnerClass = BlockInnerClass.factory.ownerType_blockNode_copiedVariables_(_ownerType, _fieldAccessed, new JVMVariable[] {});
    _jvmClassCompiler = JVMClassCompiler.factory.classDescriptionNode_systemNode_systemMappingUpdater_isStatic_(null, _systemNode, this.newSystemMappingUpdater(), false);
    _jvmClassCompiler.ownerType_(JVMDefinedObjectType.factory.dottedClassName_("ExpressionContainer$" + _compilerTools.nextExtensionPostfix()));
    _blockClass = _jvmClassCompiler.compileBlockNoAdd_(_aBlockInnerClass);
    return _jvmClassCompiler.withContainerAndExtraClasses_(_blockClass);
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) JVMClass(st.gravel.support.compiler.jvm.JVMClass) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) JVMClassCompiler(st.gravel.support.compiler.jvm.JVMClassCompiler) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) BlockInnerClass(st.gravel.support.compiler.jvm.BlockInnerClass)

Example 2 with JVMVariable

use of st.gravel.support.compiler.jvm.JVMVariable in project gravel by gravel-st.

the class JVMBlockCompiler method compileBlock.

public JVMClass compileBlock() {
    final JVMMethod _m;
    final JVMField[] _fields;
    final JVMMethodCompiler _methodCompiler;
    final JVMClass _jvmClass;
    _fields = st.gravel.support.jvm.ArrayExtensions.collect_(_block.copiedVariables(), ((st.gravel.support.jvm.Block1<JVMField, JVMVariable>) (new st.gravel.support.jvm.Block1<JVMField, JVMVariable>() {

        @Override
        public JVMField value_(final JVMVariable _each) {
            return (JVMField) _each.asField_isStatic_(_block.ownerType(), false);
        }
    })));
    _methodCompiler = JVMMethodCompiler.factory.parent_(_parent);
    _methodCompiler.isStatic_(false);
    _m = _methodCompiler.buildBlock_copiedVariables_blockType_(_block.blockNode(), _fields, _block.ownerType());
    _jvmClass = JVMClass.factory.type_superType_fields_methods_astConstants_(_block.ownerType(), this.superType(), _fields, st.gravel.support.jvm.ArrayFactory.with_with_(_m, this.createInit()), new BlockSendArgument[] {});
    if (_block.blockNode().sourcePosition() != null) {
        _jvmClass.source_(_block.blockNode().sourcePosition().sourceFile().name());
    }
    return _jvmClass;
}
Also used : JVMClass(st.gravel.support.compiler.jvm.JVMClass) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) JVMMethod(st.gravel.support.compiler.jvm.JVMMethod) BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument) JVMField(st.gravel.support.compiler.jvm.JVMField) JVMMethodCompiler(st.gravel.support.compiler.jvm.JVMMethodCompiler)

Example 3 with JVMVariable

use of st.gravel.support.compiler.jvm.JVMVariable in project gravel by gravel-st.

the class JVMMethodCompiler method produceBlockInlineMessageSend_.

public JVMMethodCompiler produceBlockInlineMessageSend_(final MessageNode _messageNode) {
    final st.gravel.core.Symbol _selector;
    final String[][] _blockSendConstants;
    final int[] _passedNumArgs;
    final JVMVariable[][] _argumentsToCopy;
    _argumentsToCopy = new JVMVariable[1][];
    _blockSendConstants = new String[1][];
    _passedNumArgs = new int[1];
    _blockSendConstants[0] = new String[] {};
    _argumentsToCopy[0] = new JVMVariable[] {};
    _passedNumArgs[0] = 0;
    for (final Node _arg : _messageNode.arguments()) {
        if (_arg.isBlockNode()) {
            final BlockNode _blockNode;
            final JVMVariable[] _nCopiedVariables;
            _blockNode = ((BlockNode) _arg);
            _nCopiedVariables = JVMMethodCompiler.this.copiedVariablesForBlockNode_(_blockNode);
            for (final JVMVariable _each : _nCopiedVariables) {
                if (!st.gravel.support.jvm.ArrayExtensions.includes_(_argumentsToCopy[0], _each)) {
                    _argumentsToCopy[0] = st.gravel.support.jvm.ArrayExtensions.copyWith_(_argumentsToCopy[0], _each);
                }
            }
            _blockSendConstants[0] = st.gravel.support.jvm.ArrayExtensions.copyWith_(_blockSendConstants[0], JVMMethodCompiler.this.addASTConstant_(BlockSendArgument.factory.blockNode_copiedVariables_(_blockNode, _nCopiedVariables)));
        } else {
            _passedNumArgs[0] = ((_passedNumArgs[0]) + 1);
            JVMMethodCompiler.this.visit_(_arg);
            JVMMethodCompiler.this.ensureCast_(JVMDynamicObjectType.factory.basicNew());
            _blockSendConstants[0] = st.gravel.support.jvm.ArrayExtensions.copyWith_(_blockSendConstants[0], null);
        }
    }
    for (final JVMVariable _each : _argumentsToCopy[0]) {
        JVMMethodCompiler.this.produceVarRead_(_each.varName());
        JVMMethodCompiler.this.ensureCast_(_each.type());
    }
    _selector = st.gravel.core.Symbol.value(_messageNode.selector());
    this.emit_(DynamicLiteralBlockMessageSend.factory.functionName_numArgs_blockSendConstants_constantOwner_copiedArguments_(_parent.selectorConverter().selectorAsFunctionName_(_selector), ((_passedNumArgs[0]) + _argumentsToCopy[0].length), _blockSendConstants[0], _parent.ownerType(), st.gravel.support.jvm.ArrayExtensions.collect_(_argumentsToCopy[0], ((st.gravel.support.jvm.Block1<String, JVMVariable>) (new st.gravel.support.jvm.Block1<String, JVMVariable>() {

        @Override
        public String value_(final JVMVariable _each) {
            return (String) _each.varName();
        }
    })))));
    return this;
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) MessageNode(st.gravel.support.compiler.ast.MessageNode) LocalReadNode(st.gravel.support.compiler.ast.LocalReadNode) ArrayAtPutNode(st.gravel.support.compiler.ast.ArrayAtPutNode) FieldReadNode(st.gravel.support.compiler.ast.FieldReadNode) ReturnNode(st.gravel.support.compiler.ast.ReturnNode) IfTrueIfFalseNode(st.gravel.support.compiler.ast.IfTrueIfFalseNode) HolderDeclarationNode(st.gravel.support.compiler.ast.HolderDeclarationNode) ByteArrayLiteralNode(st.gravel.support.compiler.ast.ByteArrayLiteralNode) DoubleLiteralNode(st.gravel.support.compiler.ast.DoubleLiteralNode) BlockNode(st.gravel.support.compiler.ast.BlockNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) LocalWriteNode(st.gravel.support.compiler.ast.LocalWriteNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) GlobalReadNode(st.gravel.support.compiler.ast.GlobalReadNode) Node(st.gravel.support.compiler.ast.Node) ReferenceLiteralNode(st.gravel.support.compiler.ast.ReferenceLiteralNode) ArraySizeNode(st.gravel.support.compiler.ast.ArraySizeNode) ToDoNode(st.gravel.support.compiler.ast.ToDoNode) FloatLiteralNode(st.gravel.support.compiler.ast.FloatLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) SelfNode(st.gravel.support.compiler.ast.SelfNode) CharacterLiteralNode(st.gravel.support.compiler.ast.CharacterLiteralNode) InstanceCreationNode(st.gravel.support.compiler.ast.InstanceCreationNode) CascadeNode(st.gravel.support.compiler.ast.CascadeNode) ArrayAtNode(st.gravel.support.compiler.ast.ArrayAtNode) WhileFalseNode(st.gravel.support.compiler.ast.WhileFalseNode) SymbolLiteralNode(st.gravel.support.compiler.ast.SymbolLiteralNode) WriteHolderNode(st.gravel.support.compiler.ast.WriteHolderNode) BinaryMessageNode(st.gravel.support.compiler.ast.BinaryMessageNode) FieldWriteNode(st.gravel.support.compiler.ast.FieldWriteNode) ReadHolderNode(st.gravel.support.compiler.ast.ReadHolderNode) SuperNode(st.gravel.support.compiler.ast.SuperNode) CreateHolderNode(st.gravel.support.compiler.ast.CreateHolderNode) IsNilNode(st.gravel.support.compiler.ast.IsNilNode) NamespacedVariableNode(st.gravel.support.compiler.ast.NamespacedVariableNode) BooleanAndNode(st.gravel.support.compiler.ast.BooleanAndNode) BooleanOrNode(st.gravel.support.compiler.ast.BooleanOrNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode) GlobalWriteNode(st.gravel.support.compiler.ast.GlobalWriteNode) IntegerLiteralNode(st.gravel.support.compiler.ast.IntegerLiteralNode) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) BooleanLiteralNode(st.gravel.support.compiler.ast.BooleanLiteralNode) IdentityComparisonNode(st.gravel.support.compiler.ast.IdentityComparisonNode) WhileTrueNode(st.gravel.support.compiler.ast.WhileTrueNode) FixedPointLiteralNode(st.gravel.support.compiler.ast.FixedPointLiteralNode) NonLocalReturnNode(st.gravel.support.compiler.ast.NonLocalReturnNode) PushString(st.gravel.support.compiler.jvm.PushString)

Example 4 with JVMVariable

use of st.gravel.support.compiler.jvm.JVMVariable in project gravel by gravel-st.

the class JVMMethodCompiler method visitBlockNode_.

@Override
public JVMMethodCompiler visitBlockNode_(final BlockNode _blockNode) {
    final JVMVariable[] _nCopiedVariables;
    final BlockInnerClass[] _innerClassDefinition;
    _innerClassDefinition = new BlockInnerClass[1];
    _nCopiedVariables = this.copiedVariablesForBlockNode_(_blockNode);
    _innerClassDefinition[0] = this.createBlockInnerClass_copiedVariables_(_blockNode, _nCopiedVariables);
    if (_nCopiedVariables.length == 0) {
        JVMMethodCompiler.this.produceConstant_ifAbsentPut_(_blockNode, new st.gravel.support.jvm.Block0<Object>() {

            @Override
            public Object value() {
                JVMMethodCompiler.this.emit_(NewInstance.factory.type_(_innerClassDefinition[0].ownerType()));
                JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
                return JVMMethodCompiler.this.emit_(InvokeSpecial.factory.init_voidArguments_(_innerClassDefinition[0].ownerType(), new JVMType[] {}));
            }
        });
    } else {
        JVMMethodCompiler.this.emit_(NewInstance.factory.type_(_innerClassDefinition[0].ownerType()));
        JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
        for (final JVMVariable _each : _nCopiedVariables) {
            JVMMethodCompiler.this.produceVarRead_(_each.varName());
            JVMMethodCompiler.this.ensureCast_(_each.type());
        }
        JVMMethodCompiler.this.emit_(InvokeSpecial.factory.init_voidArguments_(_innerClassDefinition[0].ownerType(), st.gravel.support.jvm.ArrayExtensions.collect_(_nCopiedVariables, ((st.gravel.support.jvm.Block1<JVMType, JVMVariable>) (new st.gravel.support.jvm.Block1<JVMType, JVMVariable>() {

            @Override
            public JVMType value_(final JVMVariable _each) {
                return (JVMType) _each.type();
            }
        })))));
    }
    return this;
}
Also used : JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) JVMType(st.gravel.support.compiler.jvm.JVMType) BlockInnerClass(st.gravel.support.compiler.jvm.BlockInnerClass)

Example 5 with JVMVariable

use of st.gravel.support.compiler.jvm.JVMVariable in project gravel by gravel-st.

the class BlockInliner method renamedBlockNodeFor_.

public BlockNode renamedBlockNodeFor_(final BlockSendArgument _astConstant) {
    final BlockNode[] _blockNode;
    _blockNode = new BlockNode[1];
    _blockNode[0] = _astConstant.blockNode();
    for (final JVMVariable _cv : _astConstant.copiedVariables()) {
        _blockNode[0] = ((BlockNode) BlockInliner.this.renameVariable_from_to_(_blockNode[0], _cv.varName(), _copiedArgRenames.get(_cv.varName())));
    }
    this.log_text_("renamedBlockNode: ", _blockNode[0].sourceString());
    return _blockNode[0];
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable)

Aggregations

JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BlockNode (st.gravel.support.compiler.ast.BlockNode)3 JVMClass (st.gravel.support.compiler.jvm.JVMClass)2 JVMType (st.gravel.support.compiler.jvm.JVMType)2 BigInteger (java.math.BigInteger)1 ArrayAtNode (st.gravel.support.compiler.ast.ArrayAtNode)1 ArrayAtPutNode (st.gravel.support.compiler.ast.ArrayAtPutNode)1 ArrayLiteralNode (st.gravel.support.compiler.ast.ArrayLiteralNode)1 ArraySizeNode (st.gravel.support.compiler.ast.ArraySizeNode)1 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)1 BooleanAndNode (st.gravel.support.compiler.ast.BooleanAndNode)1 BooleanLiteralNode (st.gravel.support.compiler.ast.BooleanLiteralNode)1 BooleanOrNode (st.gravel.support.compiler.ast.BooleanOrNode)1 ByteArrayLiteralNode (st.gravel.support.compiler.ast.ByteArrayLiteralNode)1 CascadeNode (st.gravel.support.compiler.ast.CascadeNode)1 CharacterLiteralNode (st.gravel.support.compiler.ast.CharacterLiteralNode)1 CreateHolderNode (st.gravel.support.compiler.ast.CreateHolderNode)1 DoubleLiteralNode (st.gravel.support.compiler.ast.DoubleLiteralNode)1