diff --git a/wat/printer.rkt b/wat/printer.rkt index 1ba8811..1d417fa 100644 --- a/wat/printer.rkt +++ b/wat/printer.rkt @@ -121,8 +121,13 @@ [(cons (Call f) is) (string-append (tabs ntabs) "(call $" (symbol->string f) ")\n" (parse-instruction-list is ntabs))] [(cons (WatIf p t f) is) (string-append + (parse-instruction-list (seq p) ntabs) (tabs ntabs) "(if (result i64)\n" - (parse-instruction-list (seq p t f) (add1 ntabs)) + (tabs (add1 ntabs)) "(then\n" (parse-instruction-list (seq t) (+ 2 ntabs)) + (tabs (add1 ntabs)) ")\n" + (tabs (add1 ntabs)) "(else\n" + (parse-instruction-list (seq f) (+ 2 ntabs)) + (tabs (add1 ntabs)) ")\n" (tabs ntabs) ")\n" (parse-instruction-list is ntabs))] [(cons (ConstT t n) is) (string-append @@ -161,9 +166,20 @@ (tabs ntabs) ")\n" (parse-instruction-list is ntabs) )] + [(cons (Loop e n) is) (string-append (tabs ntabs) "(loop $" (symbol->string n) "\n" + (parse-instruction-list (seq e) (add1 ntabs)) + (tabs ntabs) ")\n" + (parse-instruction-list is ntabs) + )] + [(cons (BranchIf p n) is) (string-append (tabs ntabs) "(br_if\n" + (parse-instruction-list (seq p) (add1 ntabs)) + (tabs ntabs) "$" (symbol->string n) ")\n" + (parse-instruction-list is ntabs) + )] [(cons (Drop) is) (string-append (tabs ntabs) "(drop)\n" (parse-instruction-list is ntabs) )] + [(cons (Load) is) (parse-instruction-list is ntabs)] [(cons x _) (parse-error "Instruction not recognized:" x)] [x (parse-error "Expected instruction list, got:" x)]))