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);
}
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;
}
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;
}
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;
}
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];
}
Aggregations