forked from samirose/sicp-compiler-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwasm-syntax.sls
41 lines (31 loc) · 1.13 KB
/
wasm-syntax.sls
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
#!r6rs
(library
(wasm-syntax)
(export wasm-definition-type wasm-definition-type?
wasm-elem-definition-func-index
wasm-const-value?
wasm-define-locals wasm-locals-definition? wasm-local-definitions-to-top)
(import (rnrs base)
(rnrs lists)
(lists)
(pattern-match))
(define (wasm-definition-type wasm-definition)
(car wasm-definition))
(define (wasm-definition-type? type wasm-definition)
(eq? (wasm-definition-type wasm-definition) type))
(define (wasm-elem-definition-func-index elem-definition)
(cadr elem-definition))
(define wasm-const-instructions
'(i32.const f32.const))
(define (wasm-const-instruction? instr)
(memq instr wasm-const-instructions))
(define (wasm-const-value? instr)
(pattern-match? `(,wasm-const-instruction? ,??) instr))
(define (wasm-define-locals type n)
(cons 'local (make-list type n)))
(define (wasm-locals-definition? exp)
(pattern-match? `(local ,?? ,??*) exp))
(define (wasm-local-definitions-to-top seq)
(let ((split-code (partition-list wasm-locals-definition? seq)))
(append (car split-code) (cdr split-code))))
)