I've updated the patch to remove some unused functions captured in the
'compile-to-closure'.

LemonBoy

On 28 April 2016 at 11:48, lemonboy <[email protected]> wrote:
> Hello,
> This patch provides no functional changes and it just cleans up the
> way chicken checks whether a variable is undefined by using some
> inline macros that were already present but not used. The test suite
> shows no problem with this change and as an added feature you're now
> free to set! ##sys#arbitrary-unbound-symbol :^)
>
> I wasn't 100% sure if the ##core#inline should be wrapped in a
> predicate nor about where to define it or how to name it (the
> ##-prefixed namespaces are going away ?) so I just went for the least
> invasive solution.
>
> The attached patch is against the chicken-5 branch, I could rebase and
> adjust it for the -4 branch too if needed.
>
> Cheers,
> LemonBoy
From 2c3bd2b04a2b4fff600cd6c430244a8b543ddbd8 Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Thu, 28 Apr 2016 11:11:46 +0200
Subject: [PATCH] Change how unbound variables are checked for.
To: [email protected]

The previous method checks if the object 'x' we want to check is equal
to the value contained in the first slot of a symbol that's supposed to
always be undefined.
This patch replaces the code above with the use of the C_boundp and
C_unboundvaluep macros with no functional effect.
---
 csi.scm     | 2 +-
 eval.scm    | 6 +-----
 extras.scm  | 2 +-
 library.scm | 5 ++---
 4 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/csi.scm b/csi.scm
index 5466deb..65ec3fe 100644
--- a/csi.scm
+++ b/csi.scm
@@ -621,7 +621,7 @@ EOF
 	    ((bignum? x)
 	     (fprintf out "exact large integer ~S~%  #x~X~%  #o~O~%  #b~B~%"
 	       x x x x) )
-	    ((eq? x (##sys#slot '##sys#arbitrary-unbound-symbol 0))
+	    ((##core#inline "C_unboundvaluep" x)
 	     (fprintf out "unbound value~%") )
 	    ((flonum? x) (fprintf out "inexact rational number ~S~%" x))
 	    ((ratnum? x) (fprintf out "exact ratio ~S~%" x))
diff --git a/eval.scm b/eval.scm
index b426d11..c4755c5 100644
--- a/eval.scm
+++ b/eval.scm
@@ -206,11 +206,7 @@
 (define ##sys#eval-debug-level (make-parameter 1))
 
 (define compile-to-closure
-  (let ([write write]
-	[reverse reverse]
-	[with-input-from-file with-input-from-file]
-	[unbound (##sys#slot '##sys#arbitrary-unbound-symbol 0)]
-	[display display] )
+  (let ((reverse reverse))
     (lambda (exp env se #!optional cntr evalenv static)
 
       (define (find-id id se)		; ignores macro bindings
diff --git a/extras.scm b/extras.scm
index 6f0455c..c04f9ef 100644
--- a/extras.scm
+++ b/extras.scm
@@ -359,7 +359,7 @@
 					    [else (out (make-string 1 obj) col)] ) ) ) )
 	    ((##core#inline "C_undefinedp" obj) (out "#<unspecified>" col))
 	    ((##core#inline "C_anypointerp" obj) (out (##sys#pointer->string obj) col))
-	    ((eq? obj (##sys#slot '##sys#arbitrary-unbound-symbol 0))
+	    ((##core#inline "C_unboundvaluep" obj)
 	     (out "#<unbound value>" col) )
 	    ((##sys#generic-structure? obj)
 	     (let ([o (open-output-string)])
diff --git a/library.scm b/library.scm
index e0b3004..292554e 100644
--- a/library.scm
+++ b/library.scm
@@ -3978,8 +3978,7 @@ EOF
 				[else (outchr port x)] ) ) ] 
 		       [else (outchr port x)] ) )
 		((##core#inline "C_fixnump" x) (outstr port (##sys#number->string x)))
-		((eq? x (##sys#slot '##sys#arbitrary-unbound-symbol 0))
-		 (outstr port "#<unbound value>") )
+		((##core#inline "C_unboundvaluep" x) (outstr port "#<unbound value>"))
 		((not (##core#inline "C_blockp" x)) (outstr port "#<invalid immediate object>"))
 		((##core#inline "C_forwardedp" x) (outstr port "#<invalid forwarded object>"))
 		((##core#inline "C_symbolp" x)
@@ -5034,7 +5033,7 @@ EOF
   (##core#inline "C_update_pointer" addr vec) )
 
 (define (##sys#symbol-has-toplevel-binding? s)
-  (not (eq? (##sys#slot s 0) (##sys#slot '##sys#arbitrary-unbound-symbol 0))) )
+  (##core#inline "C_boundp" s))
 
 (define (##sys#copy-bytes from to offset1 offset2 bytes)
   (##core#inline 
-- 
2.8.0

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to