diff options
author | Camil Staps | 2023-01-30 20:02:11 +0100 |
---|---|---|
committer | Camil Staps | 2023-01-30 20:02:11 +0100 |
commit | 0e11c3ee8fa56ba19010b3eba18d78b5e84672ec (patch) | |
tree | 7d634661febf15b41f08756cd68f740fc80ea641 | |
parent | Add stack simulator for compilation (diff) |
Align on double words
-rw-r--r-- | driver.s | 18 | ||||
-rw-r--r-- | snug-clean/src/Snug/Compile/Simulate.icl | 2 |
2 files changed, 11 insertions, 9 deletions
@@ -42,7 +42,7 @@ driver: sw $ra,($sp) print: lw $t0,($s1) - andi $t0,$t0,2 + andi $t0,$t0,4 bne $t0,$0,print_hnf nop la $s2,EVALROOT @@ -53,13 +53,13 @@ print: addi $s1,$s3,0 print_hnf: lw $t0,($s1) - la $t1,_cINT+2 + la $t1,_cINT+4 beq $t0,$t1,print_int - lw $t1,2($t0) # name length - addi $t2,$t0,6 # name + lw $t1,($t0) # name length + addi $t2,$t0,4 # name add $t1,$t1,$t2 print_cons: - lw $t3,-2($t0) # arity + lw $t3,-4($t0) # arity beq $t3,$0,print_cons_no_paren li $a0,'(' li $v0,11 # print_char @@ -96,7 +96,7 @@ print_rewind: addi $t0,$s0,0 addi $t1,$s0,0 # argument pointer lw $t2,($t0) - lw $t2,-2($t2) # arity + lw $t2,-4($t2) # arity print_rewind_loop: addi $t1,$t1,4 lw $t3,($t1) @@ -132,7 +132,7 @@ print_rewind_root: eval: lw $t0,($s3) # Exit early in case of hnf - andi $t1,$t0,2 + andi $t1,$t0,4 bne $t1,$0,eval_rewind # Walk through indirections la $t1,_nindir @@ -144,7 +144,7 @@ eval_indir: beq $t0,$t1,eval_indir sw $s3,4($t2) # update original indir; optimizes chained indirs # Check again for hnf - andi $t1,$t0,2 + andi $t1,$t0,4 bne $t1,$0,eval_rewind nop eval_indir_done: @@ -203,6 +203,7 @@ eval_rewind_root: cycle_error: .asciiz "error: cycle in spine detected\n" .text + .align 3 .word 0 # strictness .word 1 # arity _nroot: @@ -215,6 +216,7 @@ _nroot: indir_error: .asciiz "error: indirection evaluated\n" .text + .align 3 .word 0x1 # strictness .word 1 # arity _nindir: diff --git a/snug-clean/src/Snug/Compile/Simulate.icl b/snug-clean/src/Snug/Compile/Simulate.icl index d1d65ac..9f09467 100644 --- a/snug-clean/src/Snug/Compile/Simulate.icl +++ b/snug-clean/src/Snug/Compile/Simulate.icl @@ -83,7 +83,7 @@ storeStackValue (SVRegOffset reg offset) doffset dreg = add buildCons :: !Label !Int -> Simulator () buildCons cons nargs = - write_heap (SVImmediate (Address 2 cons)) >>= \addr -> + write_heap (SVImmediate (Address 4 cons)) >>= \addr -> mapM_ (\_ -> pop >>= write_heap) [1..nargs] >>| push addr |