use of st.gravel.support.compiler.jvm.BlockSendArgument in project gravel by gravel-st.
the class BlockInliner method buildMethodNodeArguments_.
public VariableDeclarationNode[] buildMethodNodeArguments_(final MethodNode _node) {
final List<VariableDeclarationNode>[] _arguments;
_arguments = new List[1];
_arguments[0] = new java.util.ArrayList();
st.gravel.support.jvm.ArrayExtensions.with_do_(_astConstants, _node.arguments(), new st.gravel.support.jvm.Block2<Object, BlockSendArgument, VariableDeclarationNode>() {
@Override
public Object value_value_(final BlockSendArgument _astConstant, final VariableDeclarationNode _arg) {
if (_astConstant == null) {
return _arguments[0].add(_arg);
}
return BlockInliner.this;
}
});
for (final String _each : _copiedArgumentNames) {
_arguments[0].add(BlockInliner.this.variableDeclarationNodeFor_(_each));
}
return _arguments[0].toArray(new VariableDeclarationNode[_arguments[0].size()]);
}
use of st.gravel.support.compiler.jvm.BlockSendArgument in project gravel by gravel-st.
the class JVMClassCompiler method addASTConstant_.
public String addASTConstant_(final BlockSendArgument _aBlockSendArgument) {
final BlockSendArgument _bsa;
_bsa = _aBlockSendArgument.withName_(this.newConstantName());
_astConstants.add(_bsa);
return _bsa.name();
}
use of st.gravel.support.compiler.jvm.BlockSendArgument in project gravel by gravel-st.
the class JVMClassCompiler method compileAstInit.
public JVMClassCompiler compileAstInit() {
final List<JVMInstruction>[] _instructions;
final int[] _i;
_i = new int[1];
_instructions = new List[1];
_instructions[0] = new java.util.ArrayList();
_i[0] = 0;
for (final BlockSendArgument _each : _astConstants) {
final JVMType _type;
_type = JVMDynamicObjectType.factory.basicNew();
_instructions[0].add(ALoad.factory.index_type_(_i[0], _type));
_instructions[0].add(PutStatic.factory.ownerType_name_type_(_ownerType, _each.name(), _type));
_i[0] = ((_i[0]) + 1);
_fields.add(JVMField.factory.ownerType_varName_type_isStatic_(_ownerType, _each.name(), _type, true));
}
_instructions[0].add(Return.factory.basicNew());
_jvmMethods.add(JVMMethod.factory.name_locals_instructions_isStatic_signature_("_astinit", new JVMLocalDeclaration[] {}, _instructions[0].toArray(new JVMInstruction[_instructions[0].size()]), true, JVMMethodType.factory.voidDynamic_(_astConstants.size())));
return this;
}
use of st.gravel.support.compiler.jvm.BlockSendArgument 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.BlockSendArgument in project gravel by gravel-st.
the class BlockInliner method buildOptimized.
public java.lang.invoke.MethodHandle buildOptimized() {
final MethodNode[] _node;
MethodNode _inlined;
final VariableDeclarationNode[] _arguments;
final String _selector;
_node = new MethodNode[1];
this.log_text_("methodNode: ", _methodNode.sourceString());
_node[0] = this.link_(_methodNode);
this.log_text_("linked methodNode: ", _node[0].sourceString());
for (final String _each : _copiedArgumentNames) {
final String _newTempName;
_newTempName = BlockInliner.this.newTempName_for_(_each, _node[0]);
_copiedArgRenames.put(_each, _newTempName);
}
_arguments = this.buildMethodNodeArguments_(_node[0]);
_selector = _systemMapping.selectorConverter().selectorForNumArgs_(_arguments.length);
this.log_text_("selector: ", _selector);
_node[0] = this.newMethodNode_arguments_body_(_selector, _arguments, _node[0].body()).withNlrMarker_(_node[0].nlrMarker());
this.log_text_("node: ", _node[0].sourceString());
st.gravel.support.jvm.ArrayExtensions.with_do_(_astConstants, _methodNode.arguments(), new st.gravel.support.jvm.Block2<Object, BlockSendArgument, VariableDeclarationNode>() {
@Override
public Object value_value_(final BlockSendArgument _astConstant, final VariableDeclarationNode _arg) {
if (_astConstant != null) {
BlockInliner.this.log_text_("block " + _arg.name() + ": ", _astConstant.blockNode().sourceString());
return _node[0] = ((MethodNode) VariableNodeReplacer.factory.in_replace_with_(_node[0], _arg.name(), BlockInliner.this.renamedBlockNodeFor_(_astConstant)));
}
return BlockInliner.this;
}
});
_inlined = LiteralSendInliner.factory.inline_(_node[0]);
_inlined = this.link_(_inlined);
this.log_text_("inlined: ", _inlined.sourceString());
return this.compileMethodNode_(_inlined);
}
Aggregations