use of st.gravel.support.compiler.ast.Expression in project gravel by gravel-st.
the class LiteralSendInliner method produceBlock_arguments_.
public Statement produceBlock_arguments_(final BlockNode _block, final Expression[] _arguments) {
final SequenceNode[] _body;
final Statement[] _stmts;
final Expression[] _argTemps;
final VariableNode _result;
final Statement _lastStatement;
_body = new SequenceNode[1];
_body[0] = _block.body();
if (_body[0].statements().length == 0) {
return NilLiteralNode.factory.basicNew();
}
for (final VariableDeclarationNode _temp : _block.body().temporaries()) {
_body[0] = ((SequenceNode) VariableRenamer.factory.in_rename_to_(_body[0], _temp.name(), LiteralSendInliner.this.newTempSuggestion_(_temp.name()).name()));
}
_argTemps = st.gravel.support.jvm.ArrayExtensions.collect_(_arguments, ((st.gravel.support.jvm.Block1<Expression, Expression>) (new st.gravel.support.jvm.Block1<Expression, Expression>() {
@Override
public Expression value_(final Expression _each) {
if (_each.isVariableNode()) {
return _each;
} else {
final VariableNode _t;
_t = LiteralSendInliner.this.newTempSuggestion_("extract");
LiteralSendInliner.this.extraEmit_(LocalWriteNode.factory.name_value_(_t.name(), _each));
return _t;
}
}
})));
_stmts = _body[0].statements();
int _temp1 = (_stmts.length - 1);
for (int _i = 1; _i <= _temp1; _i++) {
final Statement _stmt;
_stmt = _stmts[_i - 1];
LiteralSendInliner.this.extraEmit_(LiteralSendInliner.this.in_replaceAll_with_(_stmt, _block.arguments(), _argTemps));
}
_lastStatement = this.in_replaceAll_with_(_stmts[_stmts.length - 1], _block.arguments(), _argTemps);
if (_lastStatement.isReturnNode()) {
return _lastStatement;
}
_result = this.newTempSuggestion_("result");
this.extraEmit_(_result.assign_(((Expression) _lastStatement)));
return _result;
}
use of st.gravel.support.compiler.ast.Expression in project gravel by gravel-st.
the class LiteralSendInliner method visitReturnNode_.
@Override
public Statement visitReturnNode_(final ReturnNode _anObject) {
final Statement _value;
_value = ((Statement) this.visit_(_anObject.value()));
if (_value.isReturnNode()) {
return _value;
}
return ReturnNode.factory.value_(((Expression) _value));
}
use of st.gravel.support.compiler.ast.Expression in project gravel by gravel-st.
the class JVMMethodCompiler method produceMessageSend_.
public JVMMethodCompiler produceMessageSend_(final MessageNode _messageNode) {
final st.gravel.core.Symbol _selector;
if (_parent.allowBlockInlining() && (st.gravel.support.jvm.ArrayExtensions.anySatisfy_(_messageNode.arguments(), new st.gravel.support.jvm.Predicate1<Expression>() {
@Override
public boolean value_(final Expression _e) {
return _e.isBlockNode();
}
}) && (!st.gravel.support.jvm.ArrayExtensions.anySatisfy_(_messageNode.arguments(), new st.gravel.support.jvm.Predicate1<Expression>() {
@Override
public boolean value_(final Expression _e) {
return _e.isBlockNode() && _e.allNodesContains_(((st.gravel.support.jvm.Block1<Boolean, Node>) (new st.gravel.support.jvm.Block1<Boolean, Node>() {
@Override
public Boolean value_(final Node _n) {
return (boolean) _n.isSuperNode();
}
})));
}
})))) {
return JVMMethodCompiler.this.produceBlockInlineMessageSend_(_messageNode);
}
for (final Expression _arg : _messageNode.arguments()) {
JVMMethodCompiler.this.visit_(_arg);
JVMMethodCompiler.this.ensureCast_(JVMDynamicObjectType.factory.basicNew());
}
_selector = st.gravel.core.Symbol.value(_messageNode.selector());
this.emit_(DynamicMessageSend.factory.functionName_numArgs_(_parent.selectorConverter().selectorAsFunctionName_(_selector), _selector.numArgs()));
return this;
}
use of st.gravel.support.compiler.ast.Expression in project gravel by gravel-st.
the class MethodNode method primitiveIn_.
public String[] primitiveIn_(final String _className) {
final PragmaNode _pragma;
final Expression _argument;
final ArrayLiteralNode _arrayNode;
_pragma = this.primitivePragma();
if (_pragma == null) {
return null;
}
_argument = _pragma.expression().argument();
if (_argument.isStringLiteralNode()) {
return MethodNode.this.localPrimitiveIn_nameNode_(_className, ((StringLiteralNode) _argument));
}
if (!_argument.isArrayLiteralNode()) {
return null;
}
_arrayNode = ((ArrayLiteralNode) _argument);
return st.gravel.support.jvm.ArrayExtensions.collect_(_arrayNode.value(), ((st.gravel.support.jvm.Block1<String, Object>) (new st.gravel.support.jvm.Block1<String, Object>() {
@Override
public String value_(final Object _e) {
final String _str;
_str = ((String) _e);
return (String) _str;
}
})));
}
use of st.gravel.support.compiler.ast.Expression in project gravel by gravel-st.
the class Parser method parseBinaryOrUnaryMessage.
public Expression parseBinaryOrUnaryMessage() {
final Expression _receiver;
_receiver = this.parseOperand();
return this.parseBinaryOrUnaryMessage_(_receiver);
}
Aggregations