+ self->expression.outr = *out;
+
+ return true;
+}
+
+bool ast_store_codegen(ast_store *self, ast_function *func, bool lvalue, ir_value **out)
+{
+ ast_expression_codegen *cgen;
+ ir_value *left = NULL;
+ ir_value *right = NULL;
+
+ ast_value *arr;
+ ast_value *idx = 0;
+ ast_array_index *ai = NULL;
+
+ if (lvalue && self->expression.outl) {
+ *out = self->expression.outl;
+ return true;
+ }
+
+ if (!lvalue && self->expression.outr) {
+ *out = self->expression.outr;
+ return true;
+ }
+
+ if (ast_istype(self->dest, ast_array_index))
+ {
+
+ ai = (ast_array_index*)self->dest;
+ idx = (ast_value*)ai->index;
+
+ if (ast_istype(ai->index, ast_value) && idx->isconst)
+ ai = NULL;
+ }
+
+ if (ai) {
+ /* we need to call the setter */
+ ir_value *iridx, *funval;
+ ir_instr *call;
+
+ if (lvalue) {
+ asterror(ast_ctx(self), "array-subscript assignment cannot produce lvalues");
+ return false;
+ }
+
+ arr = (ast_value*)ai->array;
+ if (!ast_istype(ai->array, ast_value) || !arr->setter) {
+ asterror(ast_ctx(self), "value has no setter (%s)", arr->name);
+ return false;
+ }
+
+ cgen = idx->expression.codegen;
+ if (!(*cgen)((ast_expression*)(idx), func, false, &iridx))
+ return false;
+
+ cgen = arr->setter->expression.codegen;
+ if (!(*cgen)((ast_expression*)(arr->setter), func, true, &funval))
+ return false;
+
+ cgen = self->source->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+ return false;
+
+ call = ir_block_create_call(func->curblock, ast_function_label(func, "store"), funval);
+ if (!call)
+ return false;
+ ir_call_param(call, iridx);
+ ir_call_param(call, right);
+ self->expression.outr = right;
+ }
+ else
+ {
+ /* regular code */
+
+ cgen = self->dest->expression.codegen;
+ /* lvalue! */
+ if (!(*cgen)((ast_expression*)(self->dest), func, true, &left))
+ return false;
+ self->expression.outl = left;
+
+ cgen = self->source->expression.codegen;
+ /* rvalue! */
+ if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+ return false;
+
+ if (!ir_block_create_store_op(func->curblock, self->op, left, right))
+ return false;
+ self->expression.outr = right;
+ }
+
+ /* Theoretically, an assinment returns its left side as an
+ * lvalue, if we don't need an lvalue though, we return
+ * the right side as an rvalue, otherwise we have to
+ * somehow know whether or not we need to dereference the pointer
+ * on the left side - that is: OP_LOAD if it was an address.
+ * Also: in original QC we cannot OP_LOADP *anyway*.
+ */
+ *out = (lvalue ? left : right);
+
+ return true;
+}
+
+bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_value **out)
+{
+ ast_expression_codegen *cgen;
+ ir_value *left, *right;
+
+ /* A binary operation cannot yield an l-value */
+ if (lvalue) {
+ asterror(ast_ctx(self), "not an l-value (binop)");
+ return false;
+ }
+
+ if (self->expression.outr) {
+ *out = self->expression.outr;
+ return true;
+ }
+
+ if (OPTS_FLAG(SHORT_LOGIC) &&
+ (self->op == INSTR_AND || self->op == INSTR_OR))
+ {
+ /* short circuit evaluation */
+ ir_block *other, *merge;
+ ir_block *from_left, *from_right;
+ ir_instr *phi;
+ size_t merge_id;
+ uint16_t notop;
+
+ /* Note about casting to true boolean values:
+ * We use a single NOT for sub expressions, and an
+ * overall NOT at the end, and for that purpose swap
+ * all the jump conditions in order for the NOT to get
+ * doubled.
+ * ie: (a && b) usually becomes (!!a ? !!b : !!a)
+ * but we translate this to (!(!a ? !a : !b))
+ */
+
+ merge_id = vec_size(func->ir_func->blocks);
+ merge = ir_function_create_block(func->ir_func, ast_function_label(func, "sce_merge"));
+
+ cgen = self->left->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+ return false;
+ if (!OPTS_FLAG(PERL_LOGIC)) {
+ notop = type_not_instr[left->vtype];
+ if (notop == AINSTR_END) {
+ asterror(ast_ctx(self), "don't know how to cast to bool...");
+ return false;
+ }
+ left = ir_block_create_unary(func->curblock,
+ ast_function_label(func, "sce_not"),
+ notop,
+ left);
+ }
+ from_left = func->curblock;
+
+ other = ir_function_create_block(func->ir_func, ast_function_label(func, "sce_other"));
+ if ( !(self->op == INSTR_OR) != !OPTS_FLAG(PERL_LOGIC) ) {
+ if (!ir_block_create_if(func->curblock, left, other, merge))
+ return false;
+ } else {
+ if (!ir_block_create_if(func->curblock, left, merge, other))
+ return false;
+ }
+ /* use the likely flag */
+ vec_last(func->curblock->instr)->likely = true;
+
+ func->curblock = other;
+ cgen = self->right->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+ return false;
+ if (!OPTS_FLAG(PERL_LOGIC)) {
+ notop = type_not_instr[right->vtype];
+ if (notop == AINSTR_END) {
+ asterror(ast_ctx(self), "don't know how to cast to bool...");
+ return false;
+ }
+ right = ir_block_create_unary(func->curblock,
+ ast_function_label(func, "sce_not"),
+ notop,
+ right);
+ }
+ from_right = func->curblock;
+
+ if (!ir_block_create_jump(func->curblock, merge))
+ return false;
+
+ vec_remove(func->ir_func->blocks, merge_id, 1);
+ vec_push(func->ir_func->blocks, merge);
+
+ func->curblock = merge;
+ phi = ir_block_create_phi(func->curblock, ast_function_label(func, "sce_value"), TYPE_FLOAT);
+ ir_phi_add(phi, from_left, left);
+ ir_phi_add(phi, from_right, right);
+ *out = ir_phi_value(phi);
+ if (!OPTS_FLAG(PERL_LOGIC)) {
+ notop = type_not_instr[(*out)->vtype];
+ if (notop == AINSTR_END) {
+ asterror(ast_ctx(self), "don't know how to cast to bool...");
+ return false;
+ }
+ *out = ir_block_create_unary(func->curblock,
+ ast_function_label(func, "sce_final_not"),
+ notop,
+ *out);
+ }
+ if (!*out)
+ return false;
+ self->expression.outr = *out;
+ return true;
+ }
+
+ cgen = self->left->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+ return false;
+
+ cgen = self->right->expression.codegen;
+ if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+ return false;
+
+ *out = ir_block_create_binop(func->curblock, ast_function_label(func, "bin"),
+ self->op, left, right);
+ if (!*out)
+ return false;
+ self->expression.outr = *out;
+