[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/25] Fix bug in `default' macro
From: |
KAction |
Subject: |
[PATCH 05/25] Fix bug in `default' macro |
Date: |
Mon, 18 Jul 2016 18:17:28 +0300 |
From: Dmitry Bogatov <address@hidden>
The following code will cause error:
(define (foo x)
(define x (* 2 x))
(+ x 12))
(display (foo 12))
instead displaying 36, since in (* 2 x) form variable x is bound, but
have value *unspecified*. In this case `set!' must be used.
* module/system/foreign/declarative.scm(default): replace `define'
with `set!'
* test-suite/tests/foreign-declarative.test: test encode/decode
procedures of primitive foreign types are identity.
---
module/system/foreign/declarative.scm | 5 ++---
test-suite/tests/foreign-declarative.test | 4 ++++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/module/system/foreign/declarative.scm
b/module/system/foreign/declarative.scm
index 65a6497..5b84c22 100644
--- a/module/system/foreign/declarative.scm
+++ b/module/system/foreign/declarative.scm
@@ -42,10 +42,9 @@
clone-proc
free-proc)
(define-syntax-rule (default <arg> <def>)
- (define <arg>
+ (set! <arg>
(with-proper-name (symbol-append name '<arg>)
- (or (and (unspecified? <arg>) <def>)
- <arg>))))
+ (or <arg> <def>))))
(define-syntax-rule (default-unavailable <arg>)
(default <arg> (lambda (x) (error "Unavailable" name '<arg> x))))
(define-syntax-rule (default-identity <arg>)
diff --git a/test-suite/tests/foreign-declarative.test
b/test-suite/tests/foreign-declarative.test
index 2c696f9..eb2a47c 100644
--- a/test-suite/tests/foreign-declarative.test
+++ b/test-suite/tests/foreign-declarative.test
@@ -27,6 +27,10 @@
(define ft-clone-proc (@@ (system foreign declarative) ft-clone-proc))
(define ft-free-proc (@@ (system foreign declarative) ft-free-proc))
+(with-test-prefix "foreign-type primitives"
+ (pass-if "int: encoder is identity"
+ (equal? 15 ((ft-encode-proc int:) 15))))
+
(define-foreign-type bogus:)
(with-test-prefix "foreign-type defaults"
(pass-if "clone-proc correctly defaults to identity"
--
I may be not subscribed. Please, keep me in carbon copy.
- Foreign-declarative module, KAction, 2016/07/18
- [PATCH 01/25] New module: system/foreign/declarative.scm, KAction, 2016/07/18
- [PATCH 02/25] Define <ffi-type> structure, KAction, 2016/07/18
- [PATCH 03/25] Mirror types from system/foreign as <foreign-type>, KAction, 2016/07/18
- [PATCH 04/25] Write boilerplate for primitive types, KAction, 2016/07/18
- [PATCH 05/25] Fix bug in `default' macro,
KAction <=
- [PATCH 06/25] Basic implementation of `define-foreign-function', KAction, 2016/07/18
- [PATCH 07/25] Introduce foreign-type predicates, KAction, 2016/07/18
- [PATCH 08/25] Add keywords for `define-foreign-function' macro, KAction, 2016/07/18
- [PATCH 10/25] Refactor type validation in `define-foreign-function', KAction, 2016/07/18
- [PATCH 09/25] system/foreign/declarative: rename `predicate' to `validate', KAction, 2016/07/18
- [PATCH 11/25] system/foreign/declarative: new macro, KAction, 2016/07/18
- [PATCH 13/25] system/foreign/declarative.scm: export string foreign type, KAction, 2016/07/18
- [PATCH 12/25] Improve deriving c symbol name from scheme one, KAction, 2016/07/18
- [PATCH 14/25] foreign/declarative: mirror more primitive types, KAction, 2016/07/18
- [PATCH 15/25] New macro: with-pointer, KAction, 2016/07/18