Debian Codegraph @

src/libextra.scm

raw
1 ;;;
2 ;;; This is to test features that aren't accessible from Scheme by default.
3 ;;; We build a special executable that exposes those features.
4 ;;;
5
6 (select-module user)
7
8 ;; Foreign pointer features
9
10 (inline-stub
11 (.include "gauche/priv/configP.h")
12
13 (define-cvar fptr_simple::ScmClass* :static)
14 (define-cvar fptr_unique::ScmClass* :static)
15 (define-cvar fptr_maybe::ScmClass* :static)
16
17 (define-cfn print-fptr (obj sink::ScmPort* _::ScmWriteContext*) ::void
18 (let* ([k::ScmClass* (Scm_ClassOf obj)])
19 (Scm_Printf sink "#<fptr-%s %p>"
20 (?: (== k fptr_simple) "simple"
21 (?: (== k fptr_unique) "unique" "maybe"))
22 (SCM_FOREIGN_POINTER_REF (void*) obj))))
23
24 (define-cproc make-fptr-simple (value :optional (attr '()))
25 (return (Scm_MakeForeignPointerWithAttr fptr_simple value attr)))
26 (define-cproc make-fptr-unique (value :optional (attr '()))
27 (return (Scm_MakeForeignPointerWithAttr fptr_unique value attr)))
28 (define-cproc make-fptr-maybe (value :optional (attr '()))
29 (return (Scm_MakeForeignPointerWithAttr fptr_maybe
30 (?: (SCM_FALSEP value) 0 value)
31 attr)))
32 (define-cproc fptr-value (fptr)
33 (let* ([k::ScmClass* (Scm_ClassOf fptr)])
34 (unless (or (== k fptr_simple)
35 (== k fptr_unique)
36 (== k fptr_maybe))
37 (Scm_Error "fptr required, but got: %S" fptr))
38 (return (SCM_OBJ_SAFE (SCM_FOREIGN_POINTER_REF ScmObj fptr)))))
39
40 (initcode
41 (set! fptr_simple (Scm_MakeForeignPointerClass
42 (Scm_UserModule) "<fptr-simple>" print-fptr NULL 0))
43 (set! fptr_unique (Scm_MakeForeignPointerClass
44 (Scm_UserModule) "<fptr-simple>" print-fptr NULL
45 SCM_FOREIGN_POINTER_KEEP_IDENTITY))
46 (set! fptr_maybe (Scm_MakeForeignPointerClass
47 (Scm_UserModule) "<fptr-simple>" print-fptr NULL
48 SCM_FOREIGN_POINTER_MAP_NULL))
49 ))
50
51 ;; Pathname replacement
52 (inline-stub
53 (declcode ;we need declcode to ensure those .defines comes before .include
54 (.define PATH_ALLOC (n) (SCM_MALLOC_ATOMIC n))
55 (.define PATH_ERROR (...) (Scm_Error __VA_ARGS__))
56 (.include "paths.c"))
57
58 (define-cproc substitute-all (input::<const-cstring>
59 mark::<const-cstring>
60 subst::<const-cstring>)
61 ::<const-cstring>
62 (cast void replace_install_dir) ; to avoid unused warning
63 (cast void get_libgauche_path) ; ditto
64 (return (substitute_all input mark subst))))
65
66 ;; Entry point
67
68 (define (main args)
69 (unless (pair? (cdr args))
70 (exit 1 "usage: testgosh <test-script>"))
71 (load (cadr args))
72 0)