use of st.gravel.support.compiler.ast.VariableDeclarationNode 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();
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode 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;
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class JVMMethodCompiler method buildBlock_copiedVariables_blockType_.
public JVMMethod buildBlock_copiedVariables_blockType_(final BlockNode _aBlockNode, final JVMField[] _anArray, final JVMDefinedObjectType _blockType) {
final int _numArgs;
this.reset();
_isBlock = true;
_copiedVariables = new java.util.HashMap<String, JVMField>();
for (final JVMField _each : _anArray) {
_copiedVariables.put(_each.varName(), _each);
}
_copiedVariablesOwner = this.newTempName();
this.pushLocal_type_(_copiedVariablesOwner, _blockType);
for (final VariableDeclarationNode _each : _aBlockNode.arguments()) {
JVMMethodCompiler.this.pushLocal_(_each.name());
}
this.produceBlockBody_(_aBlockNode.body());
_numArgs = _aBlockNode.arguments().length;
_methodName = _parent.selectorConverter().functionNameForNumArgs_(_numArgs);
_signature = JVMMethodType.factory.dynamic_(_numArgs);
return this.buildMethod();
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class NonLocalTempAccessToHolderConverter method visitSequenceNode_.
@Override
public SequenceNode visitSequenceNode_(final SequenceNode _anObject) {
final SequenceNode[] _node;
_node = new SequenceNode[1];
_node[0] = SequenceNode.factory.temporaries_statements_(st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.temporaries(), ((st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>) (new st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>() {
@Override
public VariableDeclarationNode value_(final VariableDeclarationNode _each) {
_temps.put(_each.name(), VariableScopeAnalyzerStateDefined.factory.basicNew());
return (VariableDeclarationNode) NonLocalTempAccessToHolderConverter.this.visit_(_each);
}
}))), st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.statements(), ((st.gravel.support.jvm.Block1<Statement, Statement>) (new st.gravel.support.jvm.Block1<Statement, Statement>() {
@Override
public Statement value_(final Statement _each) {
return (Statement) NonLocalTempAccessToHolderConverter.this.visit_(_each);
}
}))));
for (final Map.Entry<String, VariableScopeAnalyzerState> _temp1 : _temps.entrySet()) {
String _varName = _temp1.getKey();
VariableScopeAnalyzerState _state = _temp1.getValue();
if (NonLocalTempAccessToHolderConverter.this.needsRewrite_(_state)) {
_node[0] = ((SequenceNode) VariableToHolderRewriter.factory.varName_(_varName).visit_(_node[0]));
}
}
return _node[0];
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class SystemMapping method newClassMappingForJavaClass_.
public ClassMapping newClassMappingForJavaClass_(final Class _receiverClass) {
final Map<st.gravel.core.Symbol, AbstractMethodMapping>[] _methodMappings;
final ClassNode _classNode;
final ClassMapping _superMapping;
final java.util.Set<st.gravel.core.Symbol>[] _allSelectors;
_allSelectors = new java.util.Set[1];
_methodMappings = new Map[1];
_superMapping = this.bestClassMappingFor_(_receiverClass);
_allSelectors[0] = _superMapping.allSelectorsIn_(this);
_methodMappings[0] = new java.util.HashMap<st.gravel.core.Symbol, AbstractMethodMapping>();
_compilerTools.methodNamesIn_do_(_receiverClass, new st.gravel.support.jvm.Block2<Object, String, Integer>() {
@Override
public Object value_value_(final String _methodName, final Integer _numArgs) {
final st.gravel.core.Symbol _sel;
_sel = _selectorConverter.functionNameAsSelector_(_methodName);
if (st.gravel.support.jvm.IntegerExtensions.equals_(_sel.numArgs(), _numArgs) && _allSelectors[0].contains(_sel)) {
final java.lang.invoke.MethodHandle _methodHandle;
_methodHandle = _compilerTools.methodHandleAt_numArgs_in_identityClass_isStatic_(_methodName, _sel.numArgs(), _receiverClass, _receiverClass, false);
if (_methodHandle != null) {
return _methodMappings[0].put(_sel, AnonymousMethodMapping.factory.methodHandle_definingClass_(_methodHandle, _receiverClass));
}
}
return SystemMapping.this;
}
});
_classNode = ClassNode.factory.name_superclassPath_properties_instVars_classInstVars_sharedVariables_methods_classMethods_namespace_isExtension_isTrait_traitUsage_classTraitUsage_(_superMapping.classNode().name(), _superMapping.reference().toString(), new java.util.HashMap<String, String>(), new VariableDeclarationNode[] {}, new VariableDeclarationNode[] {}, new SharedDeclarationNode[] {}, new MethodNode[] {}, new MethodNode[] {}, _superMapping.classNode().namespace(), false, false, EmptyTraitUsageNode.factory.basicNew(), EmptyTraitUsageNode.factory.basicNew());
return ClassMapping.factory.identityMapping_extensions_instVarMappings_classNode_(IdentityClassPartMapping.factory.javaClass_isGenerated_(_receiverClass, false).withMethodMappings_(_methodMappings[0]), new ExtensionClassPartMapping[] {}, new java.util.HashMap<String, InstVarMapping>(), _classNode);
}
Aggregations