|
14 | 14 | [expr]
|
15 | 15 | (let [maybe-op (second expr)]
|
16 | 16 | (cond
|
17 |
| - (contains? (into wasm-ops (keys infix-ops)) maybe-op) (list maybe-op (first expr) (last expr)) |
| 17 | + (contains? all-ops maybe-op) (list maybe-op (first expr) (last expr)) |
18 | 18 | (= '= maybe-op) (list 'set_local (first expr) (last expr))
|
19 | 19 | :else expr)))
|
20 | 20 | (is (= (arrange-triple-list '(1 = 1)) '(set_local 1 1)))
|
|
36 | 36 | (defn expand-triple-list
|
37 | 37 | "Expand triple lists, and support infix if they aren't set_local"
|
38 | 38 | [expr]
|
39 |
| - (if (= 'set_local (first expr)) |
40 |
| - (list (first expr) (second expr) (maybe-expand-number (last expr))) |
| 39 | + (condp = (first expr) |
| 40 | + 'set_local (list (first expr) (second expr) (maybe-expand-number (last expr))) |
41 | 41 | (map maybe-expand-number expr)))
|
42 | 42 | (is (= (list) (expand-triple-list (list))))
|
43 | 43 | (is (= '(set_local $foo (f64.const 0.0)) (expand-triple-list '(set_local $foo 0.0)))))
|
|
69 | 69 | [expr]
|
70 | 70 | (let [param-counter (atom -1)]
|
71 | 71 | (or
|
72 |
| - (apply merge |
73 |
| - (filter some? |
74 |
| - (map (partial type-to-map param-counter) |
75 |
| - (tree-seq seq? identity expr)))) {}))) |
| 72 | + (->> |
| 73 | + (tree-seq seq? identity expr) |
| 74 | + (map (partial type-to-map param-counter)) |
| 75 | + (filter some?) |
| 76 | + (apply merge)) {}))) |
76 | 77 | (is (= {} (determine-type-map '())))
|
77 | 78 | (is (= '{$foo f32} (determine-type-map '(local $foo f32))))
|
78 | 79 | (is (= '{0 f32 $foo f32} (determine-type-map '((param f32) (local $foo f32)))))
|
|
100 | 101 | (defn transform-tree-node
|
101 | 102 | "The first level of abstraction for the tree-walker. Arranges lists, expands shortcuts"
|
102 | 103 | [expr]
|
103 |
| - ((if (list? expr) |
| 104 | + ((if (seq? expr) |
104 | 105 | arrange-list
|
105 | 106 | local-shortcut) expr))
|
106 | 107 |
|
107 |
| -(defn get-type |
108 |
| - [expr] |
109 |
| - (get (meta expr) :type)) |
| 108 | +(with-test |
| 109 | + (defn get-type |
| 110 | + [expr] |
| 111 | + (get (meta expr) :type)) |
| 112 | + (is (= 'f64 (get-type (with-meta '(f64.const 0) {:type 'f64})))) |
| 113 | + (is (= nil (get-type '(f64.const 0))))) |
110 | 114 |
|
111 | 115 | (with-test
|
112 | 116 | (defn resolve-infix-expression
|
|
0 commit comments