Make intern function more readable

This commit is contained in:
Justine Tunney 2021-11-24 00:09:01 -08:00
parent 7f55a4be0a
commit 17bd5be818
2 changed files with 26 additions and 31 deletions

6
lisp.c
View file

@ -111,12 +111,8 @@ GetObject(c) {
return Intern();
}
ReadObject() {
return GetObject(GetToken());
}
Read() {
return ReadObject();
return GetObject(GetToken());
}
PrintAtom(x) {

View file

@ -68,7 +68,7 @@ GetToken: # GetToken():al, dl is g_look
jbe 3f
cmp $')',%dl # dl = g_look
ja 1b
3: movb %bh,(%di) # bh is zero
3: mov %bh,(%di) # bh is zero
xchg %si,%ax
ret
@ -86,6 +86,7 @@ GetToken: # GetToken():al, dl is g_look
call .PutObject
4: mov $')',%al
jmp PutChar
.PutObject: # .PutObject(c:al,x:si)
.PrintString: # nul-terminated in si
call PutChar # preserves si
@ -99,32 +100,30 @@ PrintObject: # PrintObject(x:si)
ret
GetObject: # called just after GetToken
cmpb $'(',%al
cmp $'(',%al
je GetList
.Intern:
mov %cx,%si
# jmp Intern
Intern: push %cx # Intern(cx,di): ax
mov %di,%bp
sub %cx,%bp
inc %bp
xor %di,%di
xor %al,%al
0: push %di # save 1
1: cmpsb
jne 2f
dec %di
scasb
jne 1b
jmp 5f
2: pop %bp # drop 1
mov %cx,%si
3: scasb
jne 3b
cmp (%di),%al
jne 0b
push %di # StpCpy
4: movsb
dec %di
scasb
jnz 4b
5: pop %ax # restore 1
.ret: ret
1: pop %si
push %si
mov %bp,%cx
mov %di,%ax
cmp %bh,(%di)
je 2f
rep cmpsb # memcmp(di,si,cx)
je 9f
not %cx
xor %ax,%ax
repne scasb # memchr(di,al,cx)
jmp 1b
2: rep movsb # memcpy(di,si,cx)
9: pop %cx
ret
GetChar:xor %ax,%ax # GetCharal:dl
int $0x16 # get keystroke
@ -185,7 +184,7 @@ Gc: cmp %dx,%di # Gc(x:di,A:dx,B:si):ax
ret
GetList:call GetToken
cmpb $')',%al
cmp $')',%al
je .retF
call GetObject
push %ax # popped by xCons