mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 07:08:56 +00:00
feat: Add implementation of conjunction and disjunction
This commit is contained in:
parent
35aa317fde
commit
88dd752e2d
5 changed files with 117 additions and 0 deletions
|
@ -357,6 +357,71 @@ region_t* codegen_not_equals(FILE* out, scope_t* scope, region_t* op1, region_t*
|
|||
return op1;
|
||||
}
|
||||
|
||||
region_t* codegen_conjunction(FILE* out, scope_t* scope, region_t* op1, region_t* op2) {
|
||||
if (!op1->is_temp) {
|
||||
op1 = clone(op1);
|
||||
}
|
||||
if (!op2->is_temp) {
|
||||
op2 = clone(op2);
|
||||
}
|
||||
|
||||
region_t* tmp = scope_add_tmp(scope, 1);
|
||||
move_to(tmp); reset();
|
||||
|
||||
move_to(op1);
|
||||
loop({
|
||||
move_to(op2);
|
||||
loop({
|
||||
move_to(tmp); inc();
|
||||
move_to(op2); reset();
|
||||
});
|
||||
|
||||
move_to(op1); reset();
|
||||
});
|
||||
|
||||
scope_remove(scope, op1);
|
||||
scope_remove(scope, op2);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
region_t* codegen_disjunction(FILE* out, scope_t* scope, region_t* op1, region_t* op2) {
|
||||
if (!op1->is_temp) {
|
||||
op1 = clone(op1);
|
||||
}
|
||||
if (!op2->is_temp) {
|
||||
op2 = clone(op2);
|
||||
}
|
||||
|
||||
region_t* tmp = scope_add_tmp(scope, 1);
|
||||
move_to(tmp); reset();
|
||||
|
||||
move_to(op1);
|
||||
loop({
|
||||
move_to(tmp); inc();
|
||||
move_to(op1); reset();
|
||||
});
|
||||
|
||||
move_to(op2);
|
||||
loop({
|
||||
move_to(tmp); inc();
|
||||
move_to(op2); reset();
|
||||
});
|
||||
|
||||
move_to(tmp);
|
||||
loop({
|
||||
move_to(op1); inc();
|
||||
move_to(tmp); reset();
|
||||
})
|
||||
|
||||
scope_remove(scope, op2);
|
||||
scope_remove(scope, tmp);
|
||||
|
||||
return op1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
@ -385,6 +450,12 @@ region_t* codegen_calc_expr(FILE* out, scope_t* scope, struct calc_expression ex
|
|||
case NOT_EQUALS:
|
||||
result = codegen_not_equals(out, scope, operand1, operand2);
|
||||
break;
|
||||
case CONJUNCTION:
|
||||
result = codegen_conjunction(out, scope, operand1, operand2);
|
||||
break;
|
||||
case DISJUNCTION:
|
||||
result = codegen_disjunction(out, scope, operand1, operand2);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown operator: %d\n", expr.operator);
|
||||
panic("unknown operator");
|
||||
|
|
15
compiler/test/cases/018a-print-and.in
Normal file
15
compiler/test/cases/018a-print-and.in
Normal file
|
@ -0,0 +1,15 @@
|
|||
if (0 && 0) {
|
||||
print "no 00\n";
|
||||
}
|
||||
|
||||
if (0 && 1) {
|
||||
print "no 01\n";
|
||||
}
|
||||
|
||||
if (1 && 0) {
|
||||
print "no 10\n";
|
||||
}
|
||||
|
||||
if (1 && 1) {
|
||||
print "yes 11\n";
|
||||
}
|
8
compiler/test/cases/018a-print-and.out
Normal file
8
compiler/test/cases/018a-print-and.out
Normal file
|
@ -0,0 +1,8 @@
|
|||
[-]>[-]>[-]<<[>[>+<[-]]<[-]]>>[>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<.>.>.>.>.>.
|
||||
<<<<<<[-]]
|
||||
<<[-]>[-]+>[-]<<[>[>+<[-]]<[-]]>>[>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<.>.>.>.>.>.
|
||||
<<<<<<[-]]
|
||||
<<[-]+>[-]>[-]<<[>[>+<[-]]<[-]]>>[>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<.>.>.>.>.>.
|
||||
<<<<<<[-]]
|
||||
<<[-]+>[-]+>[-]<<[>[>+<[-]]<[-]]>>[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<<.>.>.>.>.>.>.
|
||||
<<<<<<<[-]]
|
15
compiler/test/cases/018b-print-or.in
Normal file
15
compiler/test/cases/018b-print-or.in
Normal file
|
@ -0,0 +1,15 @@
|
|||
if (0 || 0) {
|
||||
print "no 00\n";
|
||||
}
|
||||
|
||||
if (0 || 1) {
|
||||
print "yes 01\n";
|
||||
}
|
||||
|
||||
if (1 || 0) {
|
||||
print "yes 10\n";
|
||||
}
|
||||
|
||||
if (1 || 1) {
|
||||
print "yes 11\n";
|
||||
}
|
8
compiler/test/cases/018b-print-or.out
Normal file
8
compiler/test/cases/018b-print-or.out
Normal file
|
@ -0,0 +1,8 @@
|
|||
[-]>[-]>[-]<<[>>+<<[-]]>[>+<[-]]>[<<+>>[-]]<<[>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<.>.>.>.>.>.
|
||||
<<<<<<[-]]
|
||||
[-]>[-]+>[-]<<[>>+<<[-]]>[>+<[-]]>[<<+>>[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<<.>.>.>.>.>.>.
|
||||
<<<<<<<[-]]
|
||||
[-]+>[-]>[-]<<[>>+<<[-]]>[>+<[-]]>[<<+>>[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<<.>.>.>.>.>.>.
|
||||
<<<<<<<[-]]
|
||||
[-]+>[-]+>[-]<<[>>+<<[-]]>[>+<[-]]>[<<+>>[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<<<<.>.>.>.>.>.>.
|
||||
<<<<<<<[-]]
|
Loading…
Reference in a new issue