-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.ms
197 lines (173 loc) · 6.44 KB
/
driver.ms
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
; Copyright (c) 2017 Chris Double. All rights reserved.
; BSD 3-Clause License: http://opensource.org/licenses/BSD-3-Clause
;
; Shen Scheme derived soure code is:
; Copyright (c) 2012-2015 Bruno Deferrari. All rights reserved.
(import "primitives")
(import "declarations")
(import "compiler")
;(load "primitives.ms")
;(load "declarations.ms")
;(load "overwrites-internal.ms")
;(load "compiler.ms")
(define (pretty x) (if (list? x) (begin (print "(") (for-each (lambda (y) (if (list? y) (pretty y) (begin (print (format y)) (print " ")))) x) (print ") ")) (begin (print (format x)) (print " "))))
(define (char-whitespace? char)
(or
(= char (string-ref " " 0))
(= char (string-ref "\t" 0))
(= char (string-ref "\n" 0))
(= char (string-ref "\r" 0))))
(define (digit? char)
(and (>= char 48) (<= char 57)))
;; From https://rosettacode.org/wiki/S-Expressions#Scheme
(define (sexpr-read str)
(define (help str)
(let ((char (string-read-byte! str)))
(cond
((or (not char) (eq? char (string-ref "\)" 0))) '())
((= char (string-ref "(" 0))
(define lhs (help str))
(define rhs (help str))
(cons lhs rhs))
((char-whitespace? char) (help str))
((eq? char (string-ref "\"" 0)) (cons (quote-read str) (help str)))
((and (= char (string-ref "-" 0)) (> (string-length str) 1) (digit? (string-ref str 0))) (cons (* -1 (number-read str)) (help str)))
((digit? char) (string-prepend! str (make-string 1 char)) (cons (number-read str) (help str)))
(else (string-prepend! str (make-string 1 char)) (cons (string-read str) (help str))))))
; This is needed because the function conses all parsed sexprs onto something,
; so the top expression is one level too deep.
(define result (help str))
(if (null? result ) result (car result)))
(define (list->string lst str)
(cond
((null? lst) str)
(else
(string-append-byte! str (car lst))
(list->string (cdr lst) str))))
(define (quote-read str)
(define (help str)
(let ((char (string-read-byte! str)))
(if
(or (not char) (eq? char (string-ref "\"" 0)))
'()
(cons char (help str)))))
(list->string (help str) (make-string)))
(define (string-read str)
(define (help str)
(let ((char (string-read-byte! str)))
(cond
((or (not char) (char-whitespace? char)) '())
((eq? char (string-ref ")" 0)) (string-prepend! str (make-string 1 char)) '())
(else (cons char (help str))))))
(kl:intern (list->string (help str) (make-string))))
(define (number-read str)
(define real #f)
(define (help str)
(let ((char (string-read-byte! str)))
(cond
((or (not char) (char-whitespace? char)) '())
((eq? char (string-ref ")" 0)) (string-prepend! str (make-string 1 char)) '())
((eq? char (string-ref "." 0)) (set! real #t) (cons char (help str)))
((or (< char 48) (> char 57)) (string-prepend! str (make-string 1 char)) '())
(else (cons char (help str))))))
(define str (list->string (help str) (make-string)))
((if real string->real string->integer) str))
(define (read-kl-file path)
(sexpr-read (string-append "(" (read-data-file path) ")")))
(import "lib/waspc")
(define (compile-all)
(define files '("toplevel.kl"
"core.kl"
"sys.kl"
"dict.kl"
"sequent.kl"
"yacc.kl"
"reader.kl"
"prolog.kl"
"track.kl"
"load.kl"
"writer.kl"
"macros.kl"
"declarations.kl"
"types.kl"
"t-star.kl"
"init.kl"
"extension-features.kl"
"extension-launcher.kl"
"extension-factorise-defun.kl"
"extension-programmable-pattern-matching.kl"
))
(for-each
(lambda (file)
(print "Compiling ") (print file) (print "\n")
(define compiled-name (string-append "compiled/" file))
(write-lisp-file (string-append compiled-name ".ms") (cons `(module ,compiled-name) (map kl->wasp (read-kl-file (string-append "kl/" file)))))
(waspc (string-append "compiled/" file ".ms")))
files)
(waspc "overwrites-internal.ms"))
(define (eval-all)
(define files '("toplevel.kl"
"core.kl"
"sys.kl"
"dict.kl"
"sequent.kl"
"yacc.kl"
"reader.kl"
"prolog.kl"
"track.kl"
"load.kl"
"writer.kl"
"macros.kl"
"declarations.kl"
"types.kl"
"t-star.kl"
"init.kl"
"extension-features.kl"
"extension-launcher.kl"
"extension-factorise-defun.kl"
"extension-programmable-pattern-matching.kl"
))
(for-each
(lambda (file)
(print "Compiling ") (print file) (print "\n")
(map (lambda (x) (eval (kl->wasp x))) (read-kl-file (string-append "kl/" file))))
files)
(load "overwrites-internal.ms"))
(define (load-all)
(define files '("toplevel.kl"
"core.kl"
"sys.kl"
"dict.kl"
"sequent.kl"
"yacc.kl"
"reader.kl"
"prolog.kl"
"track.kl"
"load.kl"
"writer.kl"
"macros.kl"
"declarations.kl"
"types.kl"
"t-star.kl"
"init.kl"
"extension-features.kl"
"extension-launcher.kl"
"extension-factorise-defun.kl"
"extension-programmable-pattern-matching.kl"
))
(for-each
(lambda (file)
(print "Loading ") (print file) (print "\n")
(load (string-append "compiled/" file ".mo")))
files)
(load "overwrites-internal.ms"))
(kl:set (quote *language*) "Wasp Lisp")
(kl:set (quote *implementation*) "WaspVM")
(kl:set (quote *port*) "0.12")
(kl:set (quote *release*) "0.12")
(kl:set (quote *porters*) "Chris Double")
(kl:set (quote *sterror*) (cons (current-output) #f))
(kl:set (quote *stinput*) (cons (current-input) (make-string)))
(kl:set (quote *stoutput*) (cons (current-output) #f))
(kl:set (quote *home-directory*) (getcwd))
(kl:set (quote shen.*initial-home-directory*) (getcwd))