mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 07:08:56 +00:00
feat: Add negation to codegen
This commit is contained in:
parent
7de4815ab8
commit
8126e835a3
3 changed files with 35 additions and 1 deletions
|
@ -420,11 +420,31 @@ region_t* codegen_disjunction(FILE* out, scope_t* scope, region_t* op1, region_t
|
|||
return op1;
|
||||
}
|
||||
|
||||
region_t* codegen_negation(FILE* out, scope_t* scope, region_t* op) {
|
||||
if (!op->is_temp) {
|
||||
op = clone(op);
|
||||
}
|
||||
|
||||
region_t* result = scope_add_tmp(scope, 1);
|
||||
move_to(result); reset(); inc();
|
||||
|
||||
move_to(op);
|
||||
loop({
|
||||
move_to(result); dec();
|
||||
move_to(op); reset();
|
||||
});
|
||||
|
||||
scope_remove(scope, op);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
region_t* codegen_calc_expr(FILE* out, scope_t* scope, struct calc_expression expr) {
|
||||
region_t* operand1 = codegen_expr(out, scope, expr.operand1);
|
||||
region_t* operand2 = codegen_expr(out, scope, expr.operand2);
|
||||
region_t* operand2 = NULL;
|
||||
if (expr.operand2) {
|
||||
operand2 = codegen_expr(out, scope, expr.operand2);
|
||||
}
|
||||
|
||||
region_t* result = NULL;
|
||||
|
||||
|
@ -456,6 +476,9 @@ region_t* codegen_calc_expr(FILE* out, scope_t* scope, struct calc_expression ex
|
|||
case DISJUNCTION:
|
||||
result = codegen_disjunction(out, scope, operand1, operand2);
|
||||
break;
|
||||
case NEGATION:
|
||||
result = codegen_negation(out, scope, operand1);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown operator: %d\n", expr.operator);
|
||||
panic("unknown operator");
|
||||
|
|
7
compiler/test/cases/018c-print-not.in
Normal file
7
compiler/test/cases/018c-print-not.in
Normal file
|
@ -0,0 +1,7 @@
|
|||
if (!0) {
|
||||
print "yes 0\n";
|
||||
}
|
||||
|
||||
if (!1) {
|
||||
print "no 1\n";
|
||||
}
|
4
compiler/test/cases/018c-print-not.out
Normal file
4
compiler/test/cases/018c-print-not.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
[-]>[-]+<[>-<[-]]>[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<.>.>.>.>.>.
|
||||
<<<<<<[-]]
|
||||
<[-]+>[-]+<[>-<[-]]>[>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<.>.>.>.>.
|
||||
<<<<<[-]]
|
Loading…
Reference in a new issue