Skip to content

Commit

Permalink
Fix compile step to enforce left to right evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Jul 4, 2021
1 parent 51223cb commit 27e943b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8534,27 +8534,27 @@ void zend_compile_greater(znode *result, zend_ast *ast) /* {{{ */
* evaluation order. */
void zend_compile_pipe(znode *result, zend_ast *ast) /* {{{ */
{
// Convenience variables to give meaningful names.
zend_ast *expr_ast = ast->child[0];
zend_ast *name_ast = ast->child[1];

/*
znode expr_node, name_node;
expr_node = *zend_ast_get_znode(expr_ast);
// AST wrapper to hold the opcodes for the LHS expression.
znode expr_node;

zend_ast *call = zend_ast_create(ZEND_AST_CALL, name_ast, zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_node));
zend_compile_expr(result, call);
*/
// zend_compile_expr(&expr_node, expr_ast);
// zend_compile_expr(&name_node, name_ast);
// Evaluate the LHS first. (Or rather, generate the
// opcodes that will evaluate the LHS.
zend_compile_expr(&expr_node, expr_ast);

// This doesn't work. Need to do something with SEND_VAR_EX, Levi says.
// 3v4l.org/IOJQg/vld#output
// zend_emit_op(NULL, ZEND_INIT_DYNAMIC_CALL, NULL, &name_node);
//zend_compile_call_common(result, name_ast, NULL);
// Wrap the LHS back up into an AST, and replace the RHS
// with a call operation that wraps the original RHS expression.
zend_ast *call = zend_ast_create(ZEND_AST_CALL,
name_ast,
zend_ast_create_list(1,
ZEND_AST_ARG_LIST,
zend_ast_create_znode(&expr_node)));

//This version works, but evaluates out of order.
zend_ast *call = zend_ast_create(ZEND_AST_CALL, name_ast, zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast));
// Compile all of that back down to opcodes and save
// to the result znode.
zend_compile_expr(result, call);
}
/* }}} */
Expand Down

0 comments on commit 27e943b

Please sign in to comment.