Skip to content

Commit

Permalink
rep putn test
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Jan 6, 2021
1 parent c85141f commit 2bff0ee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions asm.y
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Construct
| I_REP I_DUP NumericalConstant { $$ = node(DUP, $3); }
| I_REP I_DROP NumericalConstant { $$ = node(DROP, $3); }
| I_REP I_ADD NumericalConstant { $$ = node2(ADD, $3, imm_val(1)); }
| I_REP I_PUTN NumericalConstant { $$ = node2(PUTN, $3, imm_val(1)); }
| I_REP I_SUB NumericalConstant { $$ = node2(SUB, $3, imm_val(1)); }
| I_REP I_MUL NumericalConstant { $$ = node2(MUL, $3, imm_val(1)); }
| I_REP I_DIV NumericalConstant { $$ = node2(DIV, $3, imm_val(1)); }
Expand Down
9 changes: 9 additions & 0 deletions asm_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ void asm_gen(FILE * output, vector(struct node_t) data, int optlevel) {
T;N;T;T; // GETN
break;
case PUTN:
if(it->data2.type != IMM_NONE) {
// REP PUTN X times
rep(it->data1.value) {
T;N;S;T;
}

break;
}

if(it->data1.type != IMM_NONE) {
S;S;numeral(output, it->data1.value); // PUTN N => PUSH N
}
Expand Down
6 changes: 3 additions & 3 deletions mktest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ case $ans in
cd "ws-build-run"

_prompt "program" "asm"
_prompt "input" "ws.in"
_prompt "output" "ws.out"
_prompt "input" "asm.ws.in"
_prompt "output" "asm.ws.out"

[ $(wc -c < "$name.in") -eq 0 ] && rm "$name.in"
[ $(wc -c < "$name.asm.ws.in") -eq 0 ] && rm "$name.asm.ws.in"
;;
*)
exit;;
Expand Down
2 changes: 2 additions & 0 deletions tests/ws-build-run/rep_putn.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1/2/3/4
REP PUTN 4
1 change: 1 addition & 0 deletions tests/ws-build-run/rep_putn.asm.ws.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4321

0 comments on commit 2bff0ee

Please sign in to comment.