From ef4f1436800e184e300de091c92f64f980bc201f Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Fri, 7 Jan 2022 15:23:48 +0900 Subject: [PATCH 01/23] Add READ and PRINT --- sectorlisp.S | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 3b1305e..fca7ed0 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -28,6 +28,8 @@ _start: .asciz "NIL" # dec %si ; dec %cx ; dec %sp kT: .asciz "T" # add %dl,(%si) boot A:\ DL=0 start: ljmp $0x7c00>>4,$begin # cs = 0x7c00 is boot address .asciz "" # interned strings +kRead: .asciz "READ" # builtin for eval +kPrint: .asciz "PRINT" # builtin for eval kQuote: .asciz "QUOTE" # builtin for eval kCond: .asciz "COND" # builtin for eval kCar: .asciz "CAR" # builtin to apply @@ -52,12 +54,9 @@ begin: mov $0x8000,%sp # uses higher address as stack mov $2,%bx main: mov %sp,%cx mov $'\r',%al - call PutChar # Call first to initialize %dx - call GetToken - call GetObject - call Eval - xchg %ax,%si - call PrintObject + call PutChar + call Read + call EvalPrint jmp main GetToken: # GetToken():al, dl is g_look @@ -105,6 +104,8 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret +Read: call GetChar + call GetToken GetObject: # called just after GetToken cmp $'(',%al je GetList @@ -143,6 +144,18 @@ PutChar:mov $0x0e,%ah # prints CP-437 .RetDx: xchg %dx,%ax ret +Print: mov (%si),%si # si = Cdr(e) + mov (%si),%ax # ax = Car(Cdr(e)) +EvalPrint: + call Eval + push %ax + push %dx + xchg %ax,%si + call PrintObject + pop %dx + pop %ax + ret + //////////////////////////////////////////////////////////////////////////////// Evlis: test %di,%di # Evlis(m:di,a:dx):ax @@ -258,6 +271,10 @@ Eval: test %ax,%ax # Eval(e:ax,a:dx):ax jns Assoc # lookup val if atom xchg %ax,%si # di = e lodsw # ax = Car(e) + cmp $kRead,%ax + je Read + cmp $kPrint,%ax + je Print cmp $kQuote,%ax # maybe CONS mov (%si),%di # di = Cdr(e) je Car From 90903662a9e7073c2b940ed675c2a04f58ac47f1 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Tue, 4 Jan 2022 00:31:50 +0900 Subject: [PATCH 02/23] Shave 2 bytes --- sectorlisp.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sectorlisp.S b/sectorlisp.S index fca7ed0..8bb5831 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -104,7 +104,7 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -Read: call GetChar +Read: xchg %dx,%ax call GetToken GetObject: # called just after GetToken cmp $'(',%al From 46ba9fee4fd5630c5611c4efdd8503a5675ee80e Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Tue, 4 Jan 2022 06:34:58 +0900 Subject: [PATCH 03/23] A more robust Read function --- sectorlisp.S | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 8bb5831..9ae8b8e 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -104,8 +104,25 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -Read: xchg %dx,%ax +Print: mov (%si),%si # si = Cdr(e) + mov (%si),%ax # ax = Car(Cdr(e)) +EvalPrint: + call Eval + push %ax + push %dx + xchg %ax,%si + call PrintObject + pop %dx + pop %ax + ret + +Read: push %dx + call GetChar call GetToken + call GetObject + pop %dx + ret + GetObject: # called just after GetToken cmp $'(',%al je GetList @@ -144,18 +161,6 @@ PutChar:mov $0x0e,%ah # prints CP-437 .RetDx: xchg %dx,%ax ret -Print: mov (%si),%si # si = Cdr(e) - mov (%si),%ax # ax = Car(Cdr(e)) -EvalPrint: - call Eval - push %ax - push %dx - xchg %ax,%si - call PrintObject - pop %dx - pop %ax - ret - //////////////////////////////////////////////////////////////////////////////// Evlis: test %di,%di # Evlis(m:di,a:dx):ax From 162969de4279708cafbc46095773926248c553a0 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 06:48:37 +0900 Subject: [PATCH 04/23] Fix READ buffer bug --- sectorlisp.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sectorlisp.S b/sectorlisp.S index 9ae8b8e..81ceb29 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -117,7 +117,7 @@ EvalPrint: ret Read: push %dx - call GetChar + mov %fs,%dx # Get cached character call GetToken call GetObject pop %dx @@ -152,6 +152,7 @@ Intern: push %cx # Intern(cx,di): ax GetChar:xor %ax,%ax # GetChar→al:dl int $0x16 # get keystroke + mov %ax,%fs # Used for READ PutChar:mov $0x0e,%ah # prints CP-437 int $0x10 # vidya service cmp $'\r',%al # don't clobber From 1136e5752eac40284144a27119bb228da799d3f4 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 06:58:33 +0900 Subject: [PATCH 05/23] Initialize register cache for robustness --- sectorlisp.S | 1 + 1 file changed, 1 insertion(+) diff --git a/sectorlisp.S b/sectorlisp.S index 81ceb29..aeb054a 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -55,6 +55,7 @@ begin: mov $0x8000,%sp # uses higher address as stack main: mov %sp,%cx mov $'\r',%al call PutChar + mov %dx,%fs # Clear input lookahead cache call Read call EvalPrint jmp main From 829ed4f398904580ffbdb4ec51904083dcde8000 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 07:07:13 +0900 Subject: [PATCH 06/23] Add types for kRead and kPrint --- sectorlisp.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sectorlisp.S b/sectorlisp.S index aeb054a..87b2317 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -309,6 +309,8 @@ Eval: test %ax,%ax # Eval(e:ax,a:dx):ax 1: .ascii " SECTORLISP v2 " .word 0xAA55 2: .type .sig,@object + .type kRead,@object + .type kPrint,@object .type kQuote,@object .type kCond,@object .type kAtom,@object From 72b037de932ba4760635a573a7b4dabb59067fda Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 11:40:51 +0900 Subject: [PATCH 07/23] Shave one byte --- sectorlisp.S | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 87b2317..46cf3bc 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -109,12 +109,11 @@ Print: mov (%si),%si # si = Cdr(e) mov (%si),%ax # ax = Car(Cdr(e)) EvalPrint: call Eval - push %ax push %dx xchg %ax,%si call PrintObject + xchg %dx,%ax pop %dx - pop %ax ret Read: push %dx From 1ff4ea987d70d541a28dc35d342b273fba82d756 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 11:43:11 +0900 Subject: [PATCH 08/23] Print newline capability --- sectorlisp.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 46cf3bc..f7a97bf 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -53,8 +53,7 @@ begin: mov $0x8000,%sp # uses higher address as stack pop %ss # errata exists but don't care mov $2,%bx main: mov %sp,%cx - mov $'\r',%al - call PutChar + call NewLine mov %dx,%fs # Clear input lookahead cache call Read call EvalPrint @@ -106,7 +105,11 @@ PrintObject: # PrintObject(x:si) ret Print: mov (%si),%si # si = Cdr(e) - mov (%si),%ax # ax = Car(Cdr(e)) + test %si,%si + jnz 1f +NewLine:mov $'\r',%al + jmp PutChar +1: mov (%si),%ax # ax = Car(Cdr(e)) EvalPrint: call Eval push %dx From 36678457f38d57e43d2c99be50fcd99cbea292a8 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 12:44:40 +0900 Subject: [PATCH 09/23] Put Print in Apply --- sectorlisp.S | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index f7a97bf..6dbcab3 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -56,7 +56,9 @@ main: mov %sp,%cx call NewLine mov %dx,%fs # Clear input lookahead cache call Read - call EvalPrint + call Eval + xchg %si,%ax + call PrintObject jmp main GetToken: # GetToken():al, dl is g_look @@ -104,21 +106,18 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -Print: mov (%si),%si # si = Cdr(e) - test %si,%si - jnz 1f -NewLine:mov $'\r',%al - jmp PutChar -1: mov (%si),%ax # ax = Car(Cdr(e)) -EvalPrint: - call Eval +Print: test %si,%si + jz NewLine + mov (%si),%si # ax = Car(Cdr(e)) push %dx - xchg %ax,%si call PrintObject xchg %dx,%ax pop %dx ret +NewLine:mov $'\r',%al + jmp PutChar + Read: push %dx mov %fs,%dx # Get cached character call GetToken @@ -233,6 +232,8 @@ Pairlis:test %di,%di # Pairlis(x:di,y:si,a:dx):dx ja .resolv # ah is zero if not above mov (%si),%di # di = Car(x) je .ifAtom + cmp $kPrint,%al + je Print cmp $kCons,%al jae .ifCons .ifCar: cmp $kCar,%al @@ -282,8 +283,6 @@ Eval: test %ax,%ax # Eval(e:ax,a:dx):ax lodsw # ax = Car(e) cmp $kRead,%ax je Read - cmp $kPrint,%ax - je Print cmp $kQuote,%ax # maybe CONS mov (%si),%di # di = Cdr(e) je Car From 9ca97d2ea70f152a0806a6eb91f3c44dab4274d8 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 13:23:54 +0900 Subject: [PATCH 10/23] Shave two bytes --- sectorlisp.S | 2 -- 1 file changed, 2 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 6dbcab3..f01f17a 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -109,10 +109,8 @@ PrintObject: # PrintObject(x:si) Print: test %si,%si jz NewLine mov (%si),%si # ax = Car(Cdr(e)) - push %dx call PrintObject xchg %dx,%ax - pop %dx ret NewLine:mov $'\r',%al From cac1923ebfa74942a5ae0bfe836d73fc408f807e Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 13:29:08 +0900 Subject: [PATCH 11/23] Shave three more bytes by placing Read inside Apply --- sectorlisp.S | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index f01f17a..81ffb49 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -116,11 +116,9 @@ Print: test %si,%si NewLine:mov $'\r',%al jmp PutChar -Read: push %dx - mov %fs,%dx # Get cached character +Read: mov %fs,%dx # Get cached character call GetToken call GetObject - pop %dx ret GetObject: # called just after GetToken @@ -232,6 +230,8 @@ Pairlis:test %di,%di # Pairlis(x:di,y:si,a:dx):dx je .ifAtom cmp $kPrint,%al je Print + cmp $kRead,%al + je Read cmp $kCons,%al jae .ifCons .ifCar: cmp $kCar,%al @@ -279,8 +279,6 @@ Eval: test %ax,%ax # Eval(e:ax,a:dx):ax jns Assoc # lookup val if atom xchg %ax,%si # di = e lodsw # ax = Car(e) - cmp $kRead,%ax - je Read cmp $kQuote,%ax # maybe CONS mov (%si),%di # di = Cdr(e) je Car From 1af3db75fe49c964d27b5a86e65db9d7b4353ba9 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 17:09:33 +0900 Subject: [PATCH 12/23] Use %bp instead of %fs for caching the user input --- sectorlisp.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 81ffb49..ca06b49 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -54,7 +54,7 @@ begin: mov $0x8000,%sp # uses higher address as stack mov $2,%bx main: mov %sp,%cx call NewLine - mov %dx,%fs # Clear input lookahead cache + mov %dx,%bp # Clear input lookahead cache call Read call Eval xchg %si,%ax @@ -116,7 +116,7 @@ Print: test %si,%si NewLine:mov $'\r',%al jmp PutChar -Read: mov %fs,%dx # Get cached character +Read: mov %bp,%dx # Get cached character call GetToken call GetObject ret @@ -150,7 +150,7 @@ Intern: push %cx # Intern(cx,di): ax GetChar:xor %ax,%ax # GetChar→al:dl int $0x16 # get keystroke - mov %ax,%fs # Used for READ + mov %ax,%bp # Used for READ PutChar:mov $0x0e,%ah # prints CP-437 int $0x10 # vidya service cmp $'\r',%al # don't clobber From bcb147469376912053af187dc2b2756898c4fd18 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 18:02:03 +0900 Subject: [PATCH 13/23] Shave two bytes --- sectorlisp.S | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index ca06b49..1ad96ee 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -118,8 +118,7 @@ NewLine:mov $'\r',%al Read: mov %bp,%dx # Get cached character call GetToken - call GetObject - ret + jmp GetObject GetObject: # called just after GetToken cmp $'(',%al From 8a59e66349795d58c0e7f4bdcad6fee0d59fce0a Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 18:03:52 +0900 Subject: [PATCH 14/23] Shave two more bytes --- sectorlisp.S | 2 -- 1 file changed, 2 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 1ad96ee..877493e 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -118,8 +118,6 @@ NewLine:mov $'\r',%al Read: mov %bp,%dx # Get cached character call GetToken - jmp GetObject - GetObject: # called just after GetToken cmp $'(',%al je GetList From f14c20a5b694c029632111034e8c1f9a881cb5b9 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 18:06:44 +0900 Subject: [PATCH 15/23] Shave one byte --- sectorlisp.S | 1 - 1 file changed, 1 deletion(-) diff --git a/sectorlisp.S b/sectorlisp.S index 877493e..8db0522 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -110,7 +110,6 @@ Print: test %si,%si jz NewLine mov (%si),%si # ax = Car(Cdr(e)) call PrintObject - xchg %dx,%ax ret NewLine:mov $'\r',%al From c84eed864fbba27f229ea416dde6969c70e490b2 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 18:12:17 +0900 Subject: [PATCH 16/23] Simplify --- sectorlisp.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sectorlisp.S b/sectorlisp.S index 8db0522..787d0b9 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -108,7 +108,7 @@ PrintObject: # PrintObject(x:si) Print: test %si,%si jz NewLine - mov (%si),%si # ax = Car(Cdr(e)) + xchg %di,%si call PrintObject ret From 9b0b5e9f20283a82fbe8ee51be46b00ad99c5d87 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Thu, 6 Jan 2022 19:14:31 +0900 Subject: [PATCH 17/23] Shave three more bytes using overlaps --- sectorlisp.S | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 787d0b9..7103133 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -94,6 +94,10 @@ GetToken: # GetToken():al, dl is g_look 4: mov $')',%al jmp PutChar +Print: test %si,%si + jz NewLine + xchg %di,%si + .byte 0x81 # sub ax, §call Putchar .PutObject: # .PutObject(c:al,x:si) .PrintString: # nul-terminated in si call PutChar # preserves si @@ -106,12 +110,6 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -Print: test %si,%si - jz NewLine - xchg %di,%si - call PrintObject - ret - NewLine:mov $'\r',%al jmp PutChar From 1dbcb9c9b56b94d3f728f619fe906171053aa7cb Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Fri, 7 Jan 2022 09:57:40 +0900 Subject: [PATCH 18/23] Shave three bytes (469 bytes) --- sectorlisp.S | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 7103133..838b2ba 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -53,8 +53,8 @@ begin: mov $0x8000,%sp # uses higher address as stack pop %ss # errata exists but don't care mov $2,%bx main: mov %sp,%cx - call NewLine - mov %dx,%bp # Clear input lookahead cache + mov $'\r',%al + call PutChar call Read call Eval xchg %si,%ax @@ -94,10 +94,10 @@ GetToken: # GetToken():al, dl is g_look 4: mov $')',%al jmp PutChar -Print: test %si,%si - jz NewLine - xchg %di,%si - .byte 0x81 # sub ax, §call Putchar +Print: xchg %di,%si + test %di,%di + jnz PrintObject + mov $'\r',%al .PutObject: # .PutObject(c:al,x:si) .PrintString: # nul-terminated in si call PutChar # preserves si @@ -110,9 +110,6 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -NewLine:mov $'\r',%al - jmp PutChar - Read: mov %bp,%dx # Get cached character call GetToken GetObject: # called just after GetToken From 97531f6cb7a0bd379bfd162bbbdc23960945f695 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Fri, 7 Jan 2022 15:51:57 +0900 Subject: [PATCH 19/23] Refine comments and .type directives --- sectorlisp.S | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 838b2ba..c051e19 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -28,10 +28,10 @@ _start: .asciz "NIL" # dec %si ; dec %cx ; dec %sp kT: .asciz "T" # add %dl,(%si) boot A:\ DL=0 start: ljmp $0x7c00>>4,$begin # cs = 0x7c00 is boot address .asciz "" # interned strings -kRead: .asciz "READ" # builtin for eval -kPrint: .asciz "PRINT" # builtin for eval kQuote: .asciz "QUOTE" # builtin for eval kCond: .asciz "COND" # builtin for eval +kRead: .asciz "READ" # builtin to apply +kPrint: .asciz "PRINT" # builtin to apply kCar: .asciz "CAR" # builtin to apply kCdr: .asciz "CDR" # ordering matters kCons: .asciz "CONS" # must be 3rd last @@ -54,7 +54,7 @@ begin: mov $0x8000,%sp # uses higher address as stack mov $2,%bx main: mov %sp,%cx mov $'\r',%al - call PutChar + call PutChar # call first to initialize %dx call Read call Eval xchg %si,%ax @@ -94,9 +94,9 @@ GetToken: # GetToken():al, dl is g_look 4: mov $')',%al jmp PutChar -Print: xchg %di,%si +Print: xchg %di,%si # Print(x:si) test %di,%di - jnz PrintObject + jnz PrintObject # print newline for empty args mov $'\r',%al .PutObject: # .PutObject(c:al,x:si) .PrintString: # nul-terminated in si @@ -110,8 +110,10 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -Read: mov %bp,%dx # Get cached character +Read: mov %bp,%dx # get cached character call GetToken +# jmp GetObject + GetObject: # called just after GetToken cmp $'(',%al je GetList @@ -141,7 +143,7 @@ Intern: push %cx # Intern(cx,di): ax GetChar:xor %ax,%ax # GetChar→al:dl int $0x16 # get keystroke - mov %ax,%bp # Used for READ + mov %ax,%bp # used for READ PutChar:mov $0x0e,%ah # prints CP-437 int $0x10 # vidya service cmp $'\r',%al # don't clobber @@ -245,7 +247,7 @@ Assoc: mov %dx,%si # Assoc(x:ax,y:dx):ax mov (%bx,%si),%si scasw jne 1b - .byte 0xA9 # shifted ip; read as test, cmp + .byte 0xA9 # shifted ip; reads as test, cmp Cadr: mov (%bx,%di),%di # contents of decrement register .byte 0x3C # cmp §scasw,%al (nop next byte) Cdr: scasw # increments our data index by 2 @@ -297,10 +299,10 @@ Eval: test %ax,%ax # Eval(e:ax,a:dx):ax 1: .ascii " SECTORLISP v2 " .word 0xAA55 2: .type .sig,@object - .type kRead,@object - .type kPrint,@object .type kQuote,@object .type kCond,@object + .type kRead,@object + .type kPrint,@object .type kAtom,@object .type kCar,@object .type kCdr,@object From 6de7911b7ce82b3a9f87c3096a6e434aaffa3bc7 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Fri, 7 Jan 2022 18:53:23 +0900 Subject: [PATCH 20/23] Add tests for IO --- test/Makefile | 2 ++ test/test2.lisp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/test2.lisp diff --git a/test/Makefile b/test/Makefile index 5884708..78fd3fd 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,7 @@ test1: test1.lisp qemu.sh tcat sh qemu.sh test1.lisp +test2: test2.lisp qemu.sh tcat + sh qemu.sh test2.lisp eval10: eval10.lisp qemu.sh tcat sh qemu.sh eval10.lisp eval15: eval15.lisp qemu.sh tcat diff --git a/test/test2.lisp b/test/test2.lisp new file mode 100644 index 0000000..02c3aaa --- /dev/null +++ b/test/test2.lisp @@ -0,0 +1,42 @@ +(READ)AAA +(READ)(1 (2 3) 4) +(READ) + + AAA +(READ) + + (1 (2 3) 4) +(CAR (READ))(1 (2 3) 4) +(CDR (READ))(1 (2 3) 4) +(CONS (READ) (CONS (QUOTE A) NIL))B +(CONS (READ) (CONS (QUOTE A) NIL))(1 (2 3) 4) +(ATOM (READ))A +(ATOM (READ))(1 2) +(EQ (QUOTE A) (READ))A +(EQ (QUOTE B) (READ))A +(PRINT (QUOTE A)) +(PRINT (QUOTE (1 2))) +((LAMBDA () ()) + (PRINT (QUOTE A)) + (PRINT (QUOTE B)) + (PRINT) + (PRINT (QUOTE C)) + (PRINT (QUOTE (1 2 3))) + (PRINT)) +(PRINT (READ))AAA +(PRINT (READ))(1 (2 3) 4) +(PRINT) +(PRINT (PRINT)) +(PRINT (PRINT (QUOTE A))) +((LAMBDA (LOOP) (LOOP LOOP)) + (QUOTE (LAMBDA (LOOP) + ((LAMBDA () ()) + (PRINT (QUOTE >)) + (PRINT (CONS (QUOTE INPUT) (CONS (READ) NIL))) + (PRINT) + (LOOP LOOP))))) +A +B +C +(1 2) +(1 (2 3) 4) From e6c65971858cea05da192bddccae21843dd4b930 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Sun, 9 Jan 2022 08:44:36 +0900 Subject: [PATCH 21/23] Separate Read and .ifRead --- sectorlisp.S | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index c051e19..9e343de 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -94,7 +94,8 @@ GetToken: # GetToken():al, dl is g_look 4: mov $')',%al jmp PutChar -Print: xchg %di,%si # Print(x:si) +.ifPrint: + xchg %di,%si # Print(x:si) test %di,%di jnz PrintObject # print newline for empty args mov $'\r',%al @@ -110,8 +111,8 @@ PrintObject: # PrintObject(x:si) jnz .PrintString # -> ret ret -Read: mov %bp,%dx # get cached character - call GetToken +.ifRead:mov %bp,%dx # get cached character +Read: call GetToken # jmp GetObject GetObject: # called just after GetToken @@ -222,9 +223,9 @@ Pairlis:test %di,%di # Pairlis(x:di,y:si,a:dx):dx mov (%si),%di # di = Car(x) je .ifAtom cmp $kPrint,%al - je Print + je .ifPrint cmp $kRead,%al - je Read + je .ifRead cmp $kCons,%al jae .ifCons .ifCar: cmp $kCar,%al From a6836ede0fbe55ed764999c5988d80b2981be6c0 Mon Sep 17 00:00:00 2001 From: Hikaru Ikuta Date: Sun, 9 Jan 2022 08:46:14 +0900 Subject: [PATCH 22/23] Update binary --- bin/sectorlisp.bin | Bin 512 -> 512 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/bin/sectorlisp.bin b/bin/sectorlisp.bin index ba247c77c8e2a3c53db3379ad12551514c75b48f..dfe39cd824ba4d1d5ec8266951cc466b41e25f56 100755 GIT binary patch delta 283 zcmV+$0p$LG1b_q~PDxAvQ~>HX0Kf+TQB_Y=MF2xjPDB7wML|RWP*O=wRFM`ZWs3ml zSpeu&0hZ`S0PF3E&xp`GAa(+(mgsB%JRo-QJSlbsfchzS=!iX*!>}m-FpD(k8UU~$ zUWN8}@^l5T`REJ)uqo?ChyI2Cbp@~u=sN&~_ITE;gur$5!-?wXt^YhIbW)L+CIX4Y zk-irkw*X&I=}p=&%2mlIW`cl3(lTJu(1y)r&lIB0L-qgfjm;7Y~F%|2!&l20S8kBkLfG hFs*cglTQIl4J7}TSmd}jr0cuQF}aJ~LA>2T}+60!e=-K;NG zGsFkH`0ziz{bwg{Cu6TK%k;x9lKBXx5lj2{$v{h#)zuIk6B4#6B%w{8AqWoH++hA=;-{c}jZ(f7{(;{A! Y{*UTBH~mGxND{0KEo(7XSbN From b2d4ef99600387a00b04d98ee866ba13530c89d0 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 11 Jan 2022 19:22:14 -0800 Subject: [PATCH 23/23] Shave four bytes --- sectorlisp.S | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/sectorlisp.S b/sectorlisp.S index 9e343de..e666117 100644 --- a/sectorlisp.S +++ b/sectorlisp.S @@ -174,6 +174,27 @@ Cons: xchg %di,%cx # Cons(m:di,a:ax):ax .RetDi: xchg %di,%ax ret +Builtin:cmp $kAtom,%ax # atom: last builtin atom + ja .resolv # ah is zero if not above + mov (%si),%di # di = Car(x) + je .ifAtom + cmp $kPrint,%al + je .ifPrint + cmp $kRead,%al + je .ifRead + cmp $kCons,%al + jae .ifCons +.ifCar: cmp $kCar,%al + je Car +.ifCdr: jmp Cdr +.ifCons:mov (%bx,%si),%si # si = Cdr(x) + lodsw # si = Cadr(x) + je Cons +.isEq: xor %di,%ax + jne .retF +.retT: mov $kT,%al + ret + GetList:call GetToken cmp $')',%al je .retF @@ -200,7 +221,7 @@ Gc: cmp %dx,%di # Gc(x:di,A:dx,B:si):ax call Assoc # do (fn si) → ((λ ...) si) pop %si Apply: test %ax,%ax # Apply(fn:ax,x:si:a:dx):ax - jns .switch # jump if atom + jns Builtin # jump if atom xchg %ax,%di # di = fn .lambda:mov (%bx,%di),%di # di = Cdr(fn) push %di # for .EvCadr @@ -218,26 +239,6 @@ Pairlis:test %di,%di # Pairlis(x:di,y:si,a:dx):dx xchg %ax,%dx # a = new list pop %di # grab Cdr(x) jmp Pairlis -.switch:cmp $kAtom,%ax # atom: last builtin atom - ja .resolv # ah is zero if not above - mov (%si),%di # di = Car(x) - je .ifAtom - cmp $kPrint,%al - je .ifPrint - cmp $kRead,%al - je .ifRead - cmp $kCons,%al - jae .ifCons -.ifCar: cmp $kCar,%al - je Car -.ifCdr: jmp Cdr -.ifCons:mov (%bx,%si),%si # si = Cdr(x) - lodsw # si = Cadr(x) - je Cons -.isEq: xor %di,%ax - jne .retF -.retT: mov $kT,%al - ret .ifAtom:test %di,%di # test if atom jns .retT .retF: xor %ax,%ax # ax = nil