use of st.gravel.support.compiler.ast.VariableDeclarationNode 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);
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class BlockInliner method buildNonOptimized.
public java.lang.invoke.MethodHandle buildNonOptimized() {
final MethodNode _node;
final VariableDeclarationNode[] _arguments;
final List<Expression>[] _sendArgs;
_sendArgs = new List[1];
for (final String _each : _copiedArgumentNames) {
final String _newTempName;
_newTempName = BlockInliner.this.newTempName_for_(_each, _methodNode);
_copiedArgRenames.put(_each, _newTempName);
}
_arguments = this.buildMethodNodeArguments_(_methodNode);
_sendArgs[0] = new java.util.ArrayList();
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) {
return _sendArgs[0].add(_arg.asVariableNode());
} else {
return _sendArgs[0].add(BlockInliner.this.renamedBlockNodeFor_(_astConstant));
}
}
});
_node = this.newMethodNode_arguments_body_(_systemMapping.selectorConverter().selectorForNumArgs_(_arguments.length), _arguments, SequenceNode.factory.return_(SelfNode.factory.basicNew().send_withAll_(_methodNode.selector(), _sendArgs[0].toArray(new Expression[_sendArgs[0].size()]))));
this.log_text_("nonOptimized: ", _node.sourceString());
return this.compileMethodNode_allowBlockInlining_(this.link_(_node), false);
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class BlockNode method innerSourceOn_.
@Override
public BlockNode innerSourceOn_(final StringBuilder _aStream) {
_aStream.append('[');
if (_arguments.length != 0) {
for (final VariableDeclarationNode _arg : _arguments) {
_aStream.append(':');
_arg.sourceOn_(_aStream);
_aStream.append(' ');
}
_aStream.append('|');
}
_body.sourceOn_(_aStream);
_aStream.append(']');
return this;
}
use of st.gravel.support.compiler.ast.VariableDeclarationNode in project gravel by gravel-st.
the class DiskClassWriter method writeClass_in_.
public DiskClassWriter writeClass_in_(final ClassNode _aClassNode, final java.io.File _aFilename) {
final java.io.File _nsFn;
final java.io.File _clFn;
final StringBuilder[] _str;
final VariableNode[] _reader;
_reader = new VariableNode[1];
_str = new StringBuilder[1];
_nsFn = ((java.io.File) st.gravel.support.jvm.ArrayExtensions.inject_into_(_aClassNode.reference().namespace().path(), _aFilename, ((st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>) (new st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>() {
@Override
public java.io.File value_value_(final java.io.File _fn, final st.gravel.core.Symbol _each) {
return (java.io.File) new java.io.File(_fn, _each.asString());
}
}))));
_nsFn.mkdirs();
_clFn = new java.io.File(_nsFn, _aClassNode.reference().name().asString() + ".st");
_str[0] = st.gravel.support.jvm.WriteStreamFactory.on_(new String());
_reader[0] = VariableNode.factory.name_("reader");
if (_aClassNode.isExtension()) {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_(_aClassNode.isTrait() ? "extendTrait:" : "extendClass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString())), _str[0]);
} else {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_(_aClassNode.isTrait() ? "defineTrait:superclass:" : "defineClass:superclass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString()), DiskClassWriter.this.referenceAsLiteralNode_(_aClassNode.superclassReference())), _str[0]);
for (final SharedDeclarationNode _sv : _aClassNode.metaclassNode().sharedVariables()) {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("defineSharedVariable:init:", DiskClassWriter.this.asLiteralNode_(_sv.name()), DiskClassWriter.this.initializerSource_(_sv.initializer())), _str[0]);
}
}
for (final Node _each : TraitUsageToDirectiveConverter.factory.visit_(_aClassNode.traitUsage())) {
DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
}
for (final Node _each : ClassTraitUsageToDirectiveConverter.factory.visit_(_aClassNode.metaclassNode().traitUsage())) {
DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
}
for (final VariableDeclarationNode _each : _aClassNode.instVars()) {
if (_each.type() == null) {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
} else {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
}
}
for (final VariableDeclarationNode _each : _aClassNode.metaclassNode().instVars()) {
if (_each.type() == null) {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
} else {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addClassInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
}
}
for (final Map.Entry<String, String> _temp1 : _aClassNode.properties().entrySet()) {
String _k = _temp1.getKey();
String _v = _temp1.getValue();
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("propertyAt:put:", DiskClassWriter.this.asLiteralNode_(_k), DiskClassWriter.this.asLiteralNode_(_v)), _str[0]);
}
for (final MethodNode _each : _aClassNode.methods()) {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
}
for (final MethodNode _each : _aClassNode.metaclassNode().methods()) {
DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
}
st.gravel.support.jvm.StringExtensions.writeToFile_(_str[0].toString(), _clFn);
return this;
}
Aggregations