فهرست منبع

Make intern function more readable

Justine Tunney 3 سال پیش
والد
کامیت
17bd5be818
2فایلهای تغییر یافته به همراه26 افزوده شده و 31 حذف شده
  1. 1 5
      lisp.c
  2. 25 26
      sectorlisp.S

+ 1 - 5
lisp.c

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

+ 25 - 26
sectorlisp.S

@@ -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				# GetChar→al: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