[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/25] Refactor type validation in `define-foreign-function'
From: |
KAction |
Subject: |
[PATCH 10/25] Refactor type validation in `define-foreign-function' |
Date: |
Mon, 18 Jul 2016 18:17:33 +0300 |
From: Dmitry Bogatov <address@hidden>
---
module/system/foreign/declarative.scm | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/module/system/foreign/declarative.scm
b/module/system/foreign/declarative.scm
index 5a5d688..fb949db 100644
--- a/module/system/foreign/declarative.scm
+++ b/module/system/foreign/declarative.scm
@@ -136,6 +136,23 @@
(set! function-name (string-drop function-name 2)))
function-name)
+(define *validate-function-name* (make-parameter #f))
+(define *validate-argument-name* (make-parameter #f))
+(define *validate-argument-value* (make-parameter #f))
+
+(define (validate-type function-name type arg-name arg-value)
+ (define validate-proc (ft-validate-proc type))
+ (parameterize ((*validate-function-name* function-name)
+ (*validate-argument-name* arg-name)
+ (*validate-argument-value* arg-value))
+ (unless (validate-proc arg-value)
+ (throw
+ 'wrong-type-arg
+ function-name
+ "Wrong type argument named `~A' (failed to satisfy validator `~A'): ~S"
+ (list arg-name (procedure-name validate-proc) arg-value)
+ (list arg-value)))))
+
(export define-foreign-function)
(define-syntax define-foreign-function
(syntax-rules (::)
@@ -151,15 +168,7 @@
(map %make-foreign-argument (list type ...))))
(frontend-function
(lambda (arg-name ...)
- (let ((validate (ft-validate-proc type)))
- (unless (validate arg-name)
- (throw
- 'wrong-type-arg
- 'function-name
- "Wrong type argument named `~A' (failed to satisfy
validator `~A'): ~S"
- (list 'arg-name (procedure-name validate) arg-name)
- (list arg-name))))
- ...
+ (validate-type 'function-name type 'arg-name arg-name) ...
(backend-function arg-name ...))))
(set-procedure-property! backend-function 'name 'function-name)
(set-procedure-property! frontend-function 'name 'function-name)
--
I may be not subscribed. Please, keep me in carbon copy.
- [PATCH 01/25] New module: system/foreign/declarative.scm, (continued)
- [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, 2016/07/18
- [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 <=
- [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
- [PATCH 16/25] Configure emacs file-local indention, KAction, 2016/07/18
- [PATCH 17/25] system/foreign/declarative: unexport internal macro, KAction, 2016/07/18
- [PATCH 18/25] write documentation for (system foreign declarative), KAction, 2016/07/18