Repository navigation
Expand file tree
/
Copy pathnative_compute_macro.sl
More file actions
35 lines (35 loc) · 2.12 KB
/
Copy pathnative_compute_macro.sl
File metadata and controls
35 lines (35 loc) · 2.12 KB
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
; expect: (MkU8 20 _)
; host-path: yes
; native-compute spread by a macro over a Settled list of bounds, one compiled decision per bound.
(def-lvl D)
(def-fns _ $ (many decider : (many (Nat) n) -> (many (Fn D -> (many (Dec (Nat) Lt n u8-modulus) d)) f))
(def-fns D $ (many go : -> (many (Dec (Nat) Lt n u8-modulus) d)) (lt-dec n u8-modulus))
go)
(let ((erased nats)) (List (Nat)))
(def-fns _ $ (many calls : (unique (MacroWorld) mw at vacant-slot) (many (Pos) here) (many (Raw) f) (subterm many (List $ Nat) ns) ->
(unique (MacroWorld) mw2 at mw) (many (List $ Raw) out))
(let-match many ns (Cons _ n rest) ((Nil _) (values mw $ Nil _)))
(let ((unique mw1) (many h)) (intern-nat mw n))
(let ((unique mw2) (many more)) (notail $ calls mw1 here f rest))
(values mw2 $ Cons _ (RawList here $ Cons _ f $ Cons _ (RawSettled here _ _ _ h) $ Nil _) more))
(def-fns _ $ (many native-each-fn : (unique (MacroWorld) mw at vacant-slot) (many (Pos) here) (many (List $ Raw) args) ->
(unique (MacroWorld) mw2 at mw) (many (List $ Raw) out))
(let-match many args (Cons _ f r1) ((Nil _) (values mw $ Nil _)))
(let-match many r1 (Cons _ xs _) ((Nil _) (values mw $ Nil _)))
(let-match many xs (RawSymbol _ s) (else (values mw $ Nil _)))
(let ((unique mw1) (many r)) (resolve mw s))
(let-match many r (RSettled _ _ _ h) (else (values mw1 $ Nil _)))
(let-match many (settled-mult _ _ _ h) (MMany) (else (values mw1 $ Nil _)))
(let ((unique mw2) (many e)) (settled-eq _ _ _ _ _ _ mw1 (settled-type _ _ _ h) (settled-of erased nats)))
(let-match many e (ESome _ j) ((ENone _) (values mw2 $ Nil _)))
(let-match erased j (JMRefl _ _))
(let ((many ns)) $ settled-value _ _ h)
(let ((unique mw3) (many cs)) (calls mw2 here f ns))
(values mw3 $ Cons _ (RawList here $ Cons _ (RawSymbol here $ SName "native-compute") cs) $ Nil _))
(let ((many native-each)) (MkMacro _ native-each-fn))
(let ((many bounds)) (Cons _ 3 $ Cons _ 20 $ Cons _ u8-modulus $ Nil _))
(let ((many a) (many b) (many c)) (native-each decider bounds))
(comptime-match many a (Yes _ _ _ _ _))
(comptime-match many c (No _ _ _ _ _))
(comptime-match many b (Yes _ _ _ _ p))
(MkU8 20 p)