Search in sources :

Example 1 with JVMDefinedObjectType

use of st.gravel.support.compiler.jvm.JVMDefinedObjectType 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 JVMDefinedObjectType

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

the class JVMClassCompiler method compileClassNode.

public JVMClass compileClassNode() {
    final MethodNode[] _allMethods;
    Reference _superclassReference;
    BoundVariableDeclarationNode[] _allInstVars;
    final MethodNode[] _localLinkedMethods;
    ClassDescriptionNode _scn;
    if (_ownerType == null) {
        _ownerType = ((JVMDefinedObjectType) _selfType);
    }
    _allMethods = _classDescriptionNode.methods();
    _superclassReference = _classDescriptionNode.superclassReference();
    _allInstVars = _classDescriptionNode.boundInstVars();
    boolean _temp1 = false;
    while (!_temp1) {
        _temp1 = _superclassReference == null;
        if (!_temp1) {
            _scn = _systemNode.classNodeAt_(_superclassReference);
            _superclassReference = _scn.superclassReference();
            _allInstVars = st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_scn.boundInstVars(), _allInstVars);
        }
    }
    _localLinkedMethods = _systemMappingUpdater.localLinkMethods_instVars_ownerReference_(_allMethods, _allInstVars, _classDescriptionNode.reference());
    for (final MethodNode _each : _localLinkedMethods) {
        JVMClassCompiler.this.compileMethod_(_each);
    }
    for (final VariableDeclarationNode _each : _classDescriptionNode.instVars()) {
        _fields.add(JVMField.factory.ownerType_varName_type_isStatic_(_ownerType, _each.name(), TypeNodeToJVMTypeConverter.factory.namespace_(JVMClassCompiler.this.namespace()).visit_(_each.type()), false));
    }
    this.compileBlocks();
    return this.createContainerClass();
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) BoundVariableDeclarationNode(st.gravel.support.compiler.ast.BoundVariableDeclarationNode) Reference(st.gravel.support.compiler.ast.Reference) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) BoundVariableDeclarationNode(st.gravel.support.compiler.ast.BoundVariableDeclarationNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 3 with JVMDefinedObjectType

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

the class JVMClassCompiler method initialize.

public JVMClassCompiler initialize() {
    _innerclasses = new java.util.ArrayList();
    _constantCount = 0;
    _constants = new java.util.ArrayList();
    _astConstants = new java.util.ArrayList();
    _selectorConverter = SelectorConverter.factory.basicNew();
    _jvmMethods = new java.util.ArrayList();
    _fields = new java.util.ArrayList();
    _extraClasses = new java.util.ArrayList();
    if ((_classDescriptionNode != null) && (_selfType == null)) {
        final Reference _superclassReference;
        _selfType = JVMDefinedObjectType.factory.dottedClassName_(_systemMappingUpdater.compilerTools().referenceAsClassName_(_classDescriptionNode.reference()));
        _superclassReference = _classDescriptionNode.superclassReference();
        _superType = ((JVMDefinedObjectType) (_superclassReference == null ? _classDescriptionNode.isMeta() ? JVMDefinedObjectType.factory.objectClass() : JVMDefinedObjectType.factory.object() : _systemMappingUpdater.compilerTools().jvmTypeForClass_(_systemMappingUpdater.systemMapping().classMappingAtReference_(_superclassReference).identityClass())));
    }
    _allowBlockInlining = this.factory().allowBlockInliningDefault();
    return this;
}
Also used : Reference(st.gravel.support.compiler.ast.Reference) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) ArrayList(java.util.ArrayList)

Example 4 with JVMDefinedObjectType

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

the class JVMMethodCompiler method producePrimitive_def_.

public JVMMethodCompiler producePrimitive_def_(final MethodNode _aMethodNode, final String[] _prim) {
    final JVMDefinedObjectType _ownerType;
    final String _name;
    final Invoke _invoke;
    final JVMMethodType[] _staticSignature;
    final int[] _selfOffset;
    _selfOffset = new int[1];
    _staticSignature = new JVMMethodType[1];
    _ownerType = JVMDefinedObjectType.factory.dottedClassName_(_prim[0]);
    _name = _prim[1];
    _invoke = _parent.createInvokeInstruction_name_numArgs_(_ownerType, _name, _aMethodNode.arguments().length);
    if (_invoke == null) {
        JVMMethodCompiler.this.emit_(NewInstance.factory.type_(JVMDefinedObjectType.factory.runtimeException()));
        JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
        JVMMethodCompiler.this.pushString_("Cannot find method " + _ownerType.descriptorString() + ">>" + _name);
        JVMMethodCompiler.this.emit_(InvokeSpecial.factory.init_voidArguments_(JVMDefinedObjectType.factory.runtimeException(), st.gravel.support.jvm.ArrayFactory.with_(JVMDefinedObjectType.factory.string())));
        JVMMethodCompiler.this.emit_(AThrow.factory.basicNew());
        return JVMMethodCompiler.this;
    }
    _staticSignature[0] = _invoke.staticSignature();
    if (_invoke.isInvokeStatic() && st.gravel.support.jvm.IntegerExtensions.equals_(_invoke.signature().numArgs(), _aMethodNode.numArgs())) {
        _selfOffset[0] = 0;
    } else {
        _selfOffset[0] = 1;
        JVMMethodCompiler.this.produceVarRead_("self");
        JVMMethodCompiler.this.ensureCast_(_staticSignature[0].arguments()[0]);
    }
    for (int _temp1 = 0; _temp1 < _aMethodNode.arguments().length; _temp1++) {
        final int _i = _temp1 + 1;
        final VariableDeclarationNode _each = _aMethodNode.arguments()[_temp1];
        JVMMethodCompiler.this.produceVarRead_(_each.name());
        JVMMethodCompiler.this.ensureCast_(_staticSignature[0].arguments()[(_i + (_selfOffset[0])) - 1]);
    }
    this.emit_(_invoke);
    if (_staticSignature[0].returnType().isVoidType()) {
        JVMMethodCompiler.this.produceVarRead_("self");
    } else {
        JVMMethodCompiler.this.ensureCast_(JVMDynamicObjectType.factory.basicNew());
    }
    this.emit_(AReturn.factory.basicNew());
    return this;
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) PushString(st.gravel.support.compiler.jvm.PushString) JVMMethodType(st.gravel.support.compiler.jvm.JVMMethodType) Invoke(st.gravel.support.compiler.jvm.Invoke)

Example 5 with JVMDefinedObjectType

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

the class JavaSystemMappingCompilerTools method writeClass_.

@Override
public Class writeClass_(JVMClass jvmClass) {
    JVMDefinedObjectType key = jvmClass.type();
    CompiledClass current = jvmClasses.get(key);
    if (current == null) {
        current = new CompiledClass(jvmClass, new ASMClassWriter(jvmClass).createClass());
        jvmClasses.put(key, current);
    }
    return current.javaClass;
}
Also used : JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) ASMClassWriter(st.gravel.support.compiler.ASMClassWriter)

Aggregations

JVMDefinedObjectType (st.gravel.support.compiler.jvm.JVMDefinedObjectType)6 Reference (st.gravel.support.compiler.ast.Reference)2 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)2 JVMMethodType (st.gravel.support.compiler.jvm.JVMMethodType)2 MethodHandle (java.lang.invoke.MethodHandle)1 MethodType (java.lang.invoke.MethodType)1 ArrayList (java.util.ArrayList)1 ASMClassWriter (st.gravel.support.compiler.ASMClassWriter)1 BlockNode (st.gravel.support.compiler.ast.BlockNode)1 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)1 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)1 MethodNode (st.gravel.support.compiler.ast.MethodNode)1 BlockInnerClass (st.gravel.support.compiler.jvm.BlockInnerClass)1 Invoke (st.gravel.support.compiler.jvm.Invoke)1 JVMClass (st.gravel.support.compiler.jvm.JVMClass)1 JVMClassCompiler (st.gravel.support.compiler.jvm.JVMClassCompiler)1 JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)1 PushString (st.gravel.support.compiler.jvm.PushString)1