From 1a39377ca158fe9ae286c66d70426c563d81a5b8 Mon Sep 17 00:00:00 2001 From: Yiyun Liu Date: Fri, 6 Jun 2025 00:17:27 -0400 Subject: [PATCH] Fix the add-node function --- printer.rkt | 6 ++++-- semantics.rkt | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/printer.rkt b/printer.rkt index 408f620..72ab6ff 100644 --- a/printer.rkt +++ b/printer.rkt @@ -115,7 +115,7 @@ (define (ppr-node a) (cond [(integer? a) - (iseq-append "NNum" (number->string a))] + (iseq-append "NNum " (number->string a))] [(not (eq? (car a) 'define)) (let ([fun (first a)] [arg (second a)]) @@ -136,7 +136,7 @@ (let ([ppr-stack-item : (-> Addr ISeq) (λ (addr) (iseq-append (ppr-fwaddr addr) ": " (ppr-stack-node heap (lookup-node heap addr))))]) - (iseq-append "Stk [" (list 'Hang -1 (ppr-list ppr-stack-item 'Newline stack))))) + (iseq-append "Stk [" (list 'Hang 0 (ppr-list ppr-stack-item 'Newline stack)) "]"))) (: ppr-state (-> State ISeq)) (define (ppr-state st) @@ -170,3 +170,5 @@ [(? string?) (display i s)]))]) (go l a) (get-output-string s)))) + +(provide (all-defined-out)) diff --git a/semantics.rkt b/semantics.rkt index e25fed8..15b4f47 100644 --- a/semantics.rkt +++ b/semantics.rkt @@ -48,8 +48,9 @@ (: allocate-node (-> Heap Node (Values Heap Addr))) (define (allocate-node heap node) - (let ([heap (treelist-add heap node)]) - (values heap (treelist-length heap)))) + (let ([addr (treelist-length heap)] + [heap (treelist-add heap node)]) + (values heap addr))) (: lookup-node (-> Heap Addr Node)) (define lookup-node treelist-ref)