Skip to content

Commit

Permalink
() -> #nil
Browse files Browse the repository at this point in the history
This commit removes () from our stack diagrams and documentation, replacing it
with #nil. () remains a valid representation of NIL in Scheme and Humus
programs, but nowhere else.

This is the first step in the migration from Scheme-style to Humus-style list
depictions, for example (a b c) -> a,b,c,#nil.
  • Loading branch information
jamesdiacono committed Jan 12, 2025
1 parent fe1e589 commit 668647c
Show file tree
Hide file tree
Showing 29 changed files with 404 additions and 405 deletions.
4 changes: 2 additions & 2 deletions apps/debugger/examples/hum_beh.asm
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ boot: ; _ <- {caps}
; Create the 'top' actor.

push top_code ; msg code=top_code
push #nil ; msg code ()
push 1 ; msg code () 1
push #nil ; msg code #nil
push 1 ; msg code #nil 1
pair 1 ; msg code env=(1)
call hum.make_closure ; msg top_closure
push hum.beh ; msg top_closure beh
Expand Down
34 changes: 17 additions & 17 deletions apps/debugger/examples/peg.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
; and `in` is the current position of the input stream.

; The input stream `in` is either `(token . next)`
; or `()` at the end of the stream.
; or `#nil` at the end of the stream.
; The `token` is the input data at the current position
; and `next` is the actor to ask for the next input.

Expand Down Expand Up @@ -39,8 +39,8 @@ s_list: ; list <- cust
ref std.send_msg

s_eos:
push #nil ; ()
msg 0 ; () cust
push #nil ; #nil
msg 0 ; #nil cust
ref std.send_msg

;
Expand All @@ -51,7 +51,7 @@ s_eos:

empty: ; _ <- ((ok . fail) accum . in)
msg -2 ; in
push #nil ; in accum'=()
push #nil ; in accum'=#nil
pair 1 ; (accum' . in)
msg 1 ; (accum' . in) custs=(ok . fail)
nth 1 ; (accum' . in) ok
Expand All @@ -69,7 +69,7 @@ fail: ; _ <- ((ok . fail) accum . in)

any: ; _ <- ((ok . fail) accum . in)
msg -2 ; in
eq #nil ; in==()
eq #nil ; in==#nil
if fail ; --

ok: ; --
Expand All @@ -93,7 +93,7 @@ k_next: ; (ok . token) <- in

eq: ; expect <- ((ok . fail) accum . in)
msg -2 ; in
eq #nil ; in==()
eq #nil ; in==#nil
if fail ; --

msg 3 ; token
Expand All @@ -105,7 +105,7 @@ eq: ; expect <- ((ok . fail) accum . in)

if: ; pred <- ((ok . fail) accum . in)
msg -2 ; in
eq #nil ; in==()
eq #nil ; in==#nil
if fail ; --

msg 3 ; token
Expand Down Expand Up @@ -217,12 +217,12 @@ not: ; peg <- ((ok . fail) accum . in)
msg 1 ; custs=(ok . fail)
part 1 ; fail ok
msg -2 ; fail ok in
push #nil ; fail ok in ()
pair 1 ; fail ok (() . in)
roll 2 ; fail (() . in) ok
pair 1 ; fail (ok () . in)
push lib.relay_beh ; fail (ok () . in) relay_beh
actor create ; fail fail'=relay_beh.(ok () . in)
push #nil ; fail ok in #nil
pair 1 ; fail ok (#nil . in)
roll 2 ; fail (#nil . in) ok
pair 1 ; fail (ok #nil . in)
push lib.relay_beh ; fail (ok #nil . in) relay_beh
actor create ; fail fail'=relay_beh.(ok #nil . in)

msg -2 ; fail fail' in
roll 3 ; fail' in fail
Expand Down Expand Up @@ -265,7 +265,7 @@ unexpected: ; _ <- _
assert #t ; assert(#f==#t)
ref std.commit

test_1_data: ; (())
test_1_data: ; (#nil)
pair_t #nil
ref #nil

Expand Down Expand Up @@ -331,7 +331,7 @@ boot: ; _ <- {caps}

; test 1: `empty` succeeds at end-of-stream

push #nil ; in=()
push #nil ; in=#nil
push #? ; in accum=#?
push #? ; in accum #?
push unexpected ; in accum #? unexpected
Expand All @@ -348,7 +348,7 @@ boot: ; _ <- {caps}

; test 2: `fail` fails at end-of-stream

push #nil ; in=()
push #nil ; in=#nil
push #? ; in accum=#?
push #? ; in accum #?
push expect_2 ; in accum #? expect_2
Expand All @@ -365,7 +365,7 @@ boot: ; _ <- {caps}

; test 3: `any` fails at end-of-stream

push #nil ; in=()
push #nil ; in=#nil
push #? ; in accum=#?
push #? ; in accum #?
push expect_3 ; in accum #? expect_3
Expand Down
96 changes: 48 additions & 48 deletions apps/debugger/examples/scm_jump.asm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tail: ; ... k args env args' closure
; (lambda (a b)
; (+ a b)))

sum_code: ; k args=(a b) env=()
sum_code: ; k args=(a b) env=#nil
pick 2 ; k args env |1| args
nth 1 ; k args env |1| a
pick 3 ; k args env |2| a args
Expand All @@ -79,23 +79,23 @@ sum:
; (lambda (a b c d)
; (+ (sum a b) (sum c d))))

double_sum_code: ; k args=(a b c d) env=()
double_sum_code: ; k args=(a b c d) env=#nil
push k1 ; k args env |1| k1
push #nil ; k args env |2| k1 ()
pick 4 ; k args env |3| k1 () args
nth 2 ; k args env |3| k1 () b
pick 5 ; k args env |4| k1 () b args
nth 1 ; k args env |4| k1 () b a
push #nil ; k args env |2| k1 #nil
pick 4 ; k args env |3| k1 #nil args
nth 2 ; k args env |3| k1 #nil b
pick 5 ; k args env |4| k1 #nil b args
nth 1 ; k args env |4| k1 #nil b a
pair 2 ; k args env |2| k1 args'=(a b)
push sum ; k args env |3| k1 args' sum
ref call
k1: ; k args env |1| a+b
push k2 ; k args env |2| a+b k2
push #nil ; k args env |3| a+b k2 ()
pick 5 ; k args env |4| a+b k2 () args
nth 4 ; k args env |4| a+b k2 () d
pick 6 ; k args env |5| a+b k2 () d args
nth 3 ; k args env |5| a+b k2 () d c
push #nil ; k args env |3| a+b k2 #nil
pick 5 ; k args env |4| a+b k2 #nil args
nth 4 ; k args env |4| a+b k2 #nil d
pick 6 ; k args env |5| a+b k2 #nil d args
nth 3 ; k args env |5| a+b k2 #nil d c
pair 2 ; k args env |3| a+b k2 args'=(c d)
push sum ; k args env |4| a+b k2 args' sum
ref call
Expand All @@ -117,7 +117,7 @@ double_sum:
; (ifact (- n 1) (* a n))
; a)))

ifact_code: ; k args=(n a) env=()
ifact_code: ; k args=(n a) env=#nil
pick 2 ; k args env |1| args
nth 1 ; k args env |1| n
push 1 ; k args env |2| n 1
Expand All @@ -127,16 +127,16 @@ ifact_code: ; k args=(n a) env=()
nth 2 ; k args env |1| a
ref return
recurse:
push #nil ; k args env |1| ()
pick 3 ; k args env |2| () args
nth 2 ; k args env |2| () a
pick 4 ; k args env |3| () a args
nth 1 ; k args env |3| () a n
alu mul ; k args env |2| () a*n
pick 4 ; k args env |3| () a*n args
nth 1 ; k args env |3| () a*n n
push 1 ; k args env |4| () a*n n 1
alu sub ; k args env |3| () a*n n-1
push #nil ; k args env |1| #nil
pick 3 ; k args env |2| #nil args
nth 2 ; k args env |2| #nil a
pick 4 ; k args env |3| #nil a args
nth 1 ; k args env |3| #nil a n
alu mul ; k args env |2| #nil a*n
pick 4 ; k args env |3| #nil a*n args
nth 1 ; k args env |3| #nil a*n n
push 1 ; k args env |4| #nil a*n n 1
alu sub ; k args env |3| #nil a*n n-1
pair 2 ; k args env |1| args=(n-1 a*n)
push ifact ; k args env |2| args closure=ifact
ref tail
Expand All @@ -156,7 +156,7 @@ ifact:
; (lambda s
; (list p q r s) ))))

hof3_code: ; k args=(p) env=()
hof3_code: ; k args=(p) env=#nil
pick 1 ; k args env |1| env
pick 3 ; k args env |2| env args
pair 1 ; k args env |1| env'=(args . env)
Expand All @@ -175,17 +175,17 @@ qr_code: ; k args=(qr) env=((p))
ref return

s_code: ; k args=s env=((q r) (p))
push #nil ; k args env |1| ()
pick 3 ; k args env |2| () s
pick 3 ; k args env |3| () s env
nth 1 ; k args env |3| () s (q r)
nth 2 ; k args env |3| () s r
pick 4 ; k args env |4| () s r env
nth 1 ; k args env |4| () s r (q r)
nth 1 ; k args env |4| () s r q
pick 5 ; k args env |5| () s r q env
nth 2 ; k args env |5| () s r q (p)
nth 1 ; k args env |5| () s r q p
push #nil ; k args env |1| #nil
pick 3 ; k args env |2| #nil s
pick 3 ; k args env |3| #nil s env
nth 1 ; k args env |3| #nil s (q r)
nth 2 ; k args env |3| #nil s r
pick 4 ; k args env |4| #nil s r env
nth 1 ; k args env |4| #nil s r (q r)
nth 1 ; k args env |4| #nil s r q
pick 5 ; k args env |5| #nil s r q env
nth 2 ; k args env |5| #nil s r q (p)
nth 1 ; k args env |5| #nil s r q p
pair 4 ; k args env |1| (p q r s)
ref return

Expand All @@ -199,38 +199,38 @@ boot: ; _ <- {caps}
; Call the 'double_sum' closure and print its return value.

; push print_rv ; k=print_rv
; push #nil ; k ()
; push 4 ; k () d=4
; push 3 ; k () d c=3
; push 2 ; k () d c b=2
; push 1 ; k () d c b a=1
; push #nil ; k #nil
; push 4 ; k #nil d=4
; push 3 ; k #nil d c=3
; push 2 ; k #nil d c b=2
; push 1 ; k #nil d c b a=1
; pair 4 ; k args=(a b c d)
; push double_sum ; k args closure=double_sum
; ref call

; Print the factorial of 6.

push print_rv ; k=print_rv
push #nil ; k ()
push 1 ; k () a=1
push 6 ; k () a n=6
push #nil ; k #nil
push 1 ; k #nil a=1
push 6 ; k #nil a n=6
pair 2 ; k args=(n a)
push ifact ; k args closure=ifact
ref call

; Call the innermost lambda in hof3 and print its return value.

; push p_return ; k=p_return
; push #nil ; k ()
; push 1 ; k () p=1
; push #nil ; k #nil
; push 1 ; k #nil p=1
; pair 1 ; k args=(p)
; push hof3 ; k args closure=hof3
; ref call
; p_return: ; qr
; push qr_return ; qr k=qr_return
; push #nil ; qr k ()
; push 3 ; qr k () r=3
; push 2 ; qr k () r q=2
; push #nil ; qr k #nil
; push 3 ; qr k #nil r=3
; push 2 ; qr k #nil r q=2
; pair 2 ; qr k args=(q r)
; roll 3 ; k args closure=qr
; ref call
Expand Down
10 changes: 5 additions & 5 deletions apps/debugger/examples/test_rom.asm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_if:
push -1 ; -1
eq 0 ; #f
if stop ; --
push #nil ; ()
push #nil ; #nil
if stop ; --
push 0 ; 0
if stop ; --
Expand All @@ -45,8 +45,8 @@ test_nth:
assert 273 ; (546 819)
part 1 ; (819) 546
assert 546 ; (819)
part 1 ; () 819
assert 819 ; ()
part 1 ; #nil 819
assert 819 ; #nil
assert #nil ; --
push list-0 ; (273 546 819)
nth 0 ; (273 546 819)
Expand All @@ -67,7 +67,7 @@ test_nth:
nth 3 ; 819
assert 819 ; --
push list-0 ; (273 546 819)
nth -3 ; ()
nth -3 ; #nil
assert list-3 ; --
; assert #nil ; --
push list-0 ; (273 546 819)
Expand Down Expand Up @@ -149,7 +149,7 @@ list-1: ; (546 819)
pair_t 16#222 ; 546
list-2: ; (819)
pair_t 16#333 ; 819
list-3: ; ()
list-3: ; #nil
ref #nil

; taken from `assert_eq.asm`
Expand Down
6 changes: 3 additions & 3 deletions apps/grant_matcher/gm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ grant: ; donor
msg -4 ; donor donor withdraw
cmp eq ; donor donor==withdraw
if std.commit ; donor
push #nil ; donor ()
roll 2 ; () donor
msg -4 ; () donor withdraw
push #nil ; donor #nil
roll 2 ; #nil donor
msg -4 ; #nil donor withdraw
pair 2 ; (withdraw donor)
msg 4 ; (withdraw donor) deposit
actor send ; --
Expand Down
6 changes: 3 additions & 3 deletions apps/grant_matcher/grant_matcher.asm
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ GM_grant: ; donor
msg -4 ; donor donor withdraw
cmp eq ; donor donor==withdraw
if std.commit ; donor
push #nil ; donor ()
roll 2 ; () donor
msg -4 ; () donor withdraw
push #nil ; donor #nil
roll 2 ; #nil donor
msg -4 ; #nil donor withdraw
pair 2 ; (withdraw donor)
msg 4 ; (withdraw donor) deposit
actor send ; --
Expand Down
9 changes: 4 additions & 5 deletions docs/proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ A _list_ can be represented by a sequence of pairs,
where the _head_ of each pair is an element of the list,
and the _tail_ of each pair is another list.
The base-case is the empty list,
represented by the `#nil` literal in uFork assembly,
and usually printed as `()`.
represented by the `#nil` literal in uFork assembly.

A list is usually printed in a more compact form than a pair.
The list `(1 2 3)` is an abbreviation for
Expand Down Expand Up @@ -111,7 +110,7 @@ As an example, consider indexing into the list `(1 2 3)`:
2 | `2`
-2 | `(3)`
3 | `3`
-3 | `()`
-3 | `#nil`
4 | `#?`
-4 | `#?`

Expand Down Expand Up @@ -143,7 +142,7 @@ For example, the customer could be the next actor in a processing pipeline.
The usual convention is to provide the _customer_
as the first element of a list-structured message.
Viewed as a pair, a _call_ looks like `(customer . request)`.
If the _request_ is `()`,
If the _request_ is `#nil`,
the call degenerates to the one-element list `(customer)`.
This convention is most appropriate
for representing arguments lists
Expand Down Expand Up @@ -241,7 +240,7 @@ read: ; value <- (tag cust . _)

The "read" handler expects a message matching `(tag cust)`.
Note that this is a subset of the top-level pattern `(tag cust . req)`
where `req` is `()`.
where `req` is `#nil`.
Reading the cell entails sending the current state `value`
to the customer actor `cust`.

Expand Down
Loading

0 comments on commit 668647c

Please sign in to comment.