Hello hackers,
the first two patches are meant to be applied after you review them, they are
pretty much the same I've previously sent but with some minor corrections so
those should be fine now.

Both the patches target the define-foreign-type form: the first patch fixes a 
regression where the tl? flag was not propagated when walking the inner `begin`
form which defines some auxiliary functions, the other one makes sure form is
always used in toplevel contexts like the other define- forms.

The same cannot be done for `define-foreign-variable` since that's used in
`foreign-type-size` and `foreign-value` to locally define foreign variables on
the go. This asymmetry is nothing too serious but makes me wonder if we should
remove the toplevelness (heh) checks in `walk` and generate
`##core#ensure-toplevel-definition` nodes when needed instead.

Time to get those upstreamed, they've been sitting in my git repo for too long
:)

Cheers,
Lemonboy
>From 2c56a709cf28ce412a72212a704d65b9377be347 Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Wed, 14 Jun 2017 21:28:52 +0200
Subject: [PATCH 1/2] Propagate the tl? flag to the inner definitions

The define-foreign-type form defines some auxiliary functions using
define and this was bound to always fail as we'd treat those as
non-toplevel ones.
---
 core.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core.scm b/core.scm
index 15f5f236..3281ac43 100644
--- a/core.scm
+++ b/core.scm
@@ -1218,7 +1218,7 @@
 					(define
 					 ,ret
 					 ,(if (pair? (cdr conv)) (second conv) '##sys#values)) )
-				     e se dest ldest h ln #f) ) ]
+				     e se dest ldest h ln tl?))]
 				 [else
 				  (register-foreign-type! name type)
 				  '(##core#undefined) ] ) ) )
-- 
2.11.0

>From e552ef7d98b44fc67b5457c645fd02974d49d59c Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Wed, 14 Jun 2017 21:30:48 +0200
Subject: [PATCH 2/2] Restrict define-foreign-type forms to the toplevel

This brings this in line with how the other define forms.
---
 core.scm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core.scm b/core.scm
index 3281ac43..0aa3a894 100644
--- a/core.scm
+++ b/core.scm
@@ -1204,6 +1204,11 @@
 			 (let ((name (second x))
 			       (type (strip-syntax (third x)))
 			       (conv (cdddr x)))
+			   (unless tl?
+			     (quit-compiling
+			       "~adefinition of foreign type `~s' in non-toplevel context"
+			       (if ln (sprintf "(~a) - " ln) "")
+			       name))
 			   (cond [(pair? conv)
 				  (let ([arg (gensym)]
 					[ret (gensym)] )
-- 
2.11.0

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

Reply via email to