-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSPL15.rkt
118 lines (82 loc) · 3.02 KB
/
CSPL15.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#lang at-exp racket/base
(require "exports.rkt")
(require syntax/strip-context
racket/port
syntax/modresolve)
(require (prefix-in r: scribble/reader))
(provide (rename-out [new-read read]
[new-read-syntax read-syntax]))
;;| Reader |
(define (make-$-readtable)
(define read-dollar
(case-lambda
[(ch in)
(let* [[prefix (open-input-string "@begin/text{\n ")]
[block (r:read (input-port-append #f prefix in))]]
(append block '(#\newline)))]
[(ch in src line col pos)
(let* [[prefix (open-input-string "@begin/text{\n ")]
[block (r:read-syntax src (input-port-append #f prefix in))]]
(datum->syntax block
(append (syntax->list block) '(#\newline))))]))
(make-readtable (current-readtable)
#\{ 'terminating-macro read-dollar))
(define (new-read in)
(syntax->datum (new-read-syntax #f in)))
(define (new-read-syntax src in)
(define (read-syntax-all src port)
(define (get-expr x)
(define y (read-syntax src x))
(unless (eof-object? y) (cons y x)))
(unfold get-expr port))
(strip-context
(parameterize ([current-readtable (make-$-readtable)])
#`(module main (file #,(path->string
(resolve-module-path "exports.rkt" __FILE__)))
(require scribble/text)
(require syntax/location)
(require racket/cmdline)
(require racket/file)
(define export-only? (make-parameter #f))
(define unit-test? (make-parameter #f))
(command-line
#:program "CSPL15"
#:once-any
[("-e" "--exports") "Output header definitions only"
(export-only? #t)]
[("-t" "--test") "Run unit test"
(unit-test? #t)])
(include: "cspl15-rebind.h")
(include: "cspl15-support.h")
(include: <stdexcept>)
#,@(read-syntax-all src in)
(if (unit-test?)
(run-unit-test #,(directory-from-path __FILE__)
#,src
(quote-module-path test))
(export-all (export-only?)))))))
;; | Test |
(module+ test
(define module-test
(new-read (open-input-string "
(displayln '====)
(class: /Object)
(ƒ: /Object/.public/set_m (name m)
\"documenation for this function\"
:: (virtual rw) => \"const char *\" → \"int\" → \"int\"
{
int st1;
int st2;
return 1234;
})
(module+ test
(displayln \"entered test\")
(include: <stdio.h>)
(ƒ: /main (argc argv) ∷ \"int\" → \"char **\" → \"int\"
(𝑣: x = \"Object()\")
{ printf(\"test: %d\\n\", x.set_m(\"xxx\", 0)); }))
")))
module-test
(eval module-test)
(parameterize [[current-command-line-arguments (vector "-t")]]
(dynamic-require ''main #f)))