Fixed up!

This commit is contained in:
Nathan Braswell
2021-10-19 02:45:56 -04:00
parent e0c4366771
commit c0a07b54ce

View File

@@ -103,9 +103,9 @@
) (idx args -1))])))
print_strip (lambda (& args) (println (lapply str_strip args)))
strip (let (helper (rec-lambda recurse (x need_value de_sym)
strip (let (helper (rec-lambda recurse (x need_value)
(cond (val? x) (.val x)
(marked_array? x) (let (stripped_values (map (lambda (x) (recurse x need_value de_sym)) (.marked_array_values x)))
(marked_array? x) (let (stripped_values (map (lambda (x) (recurse x need_value)) (.marked_array_values x)))
(if (.marked_array_is_val x) (if need_value (error (str "needed value for this strip but got" x)) (cons array stripped_values))
stripped_values))
(marked_symbol? x) (if (.marked_symbol_is_val x) (if need_value (error (str "needed value for this strip but got" x)) [quote (.marked_symbol_value x)])
@@ -115,24 +115,24 @@
final_params (if variadic (concat (slice params 0 -2) '& [(idx params -1)]) params)
; Honestly, could trim down the env to match what could be evaluated in the comb
; Also if this isn't real, lower to a call to vau
se_env (if (marked_env_real? se) (recurse se true de_sym) nil)
body_v (recurse body false de?)
se_env (if (marked_env_real? se) (recurse se true) nil)
body_v (recurse body false)
ve (concat [vau] de_entry [final_params] [body_v])
fe ((rec-lambda recurse (x i) (if (= i 0) x (recurse [wrap x] (- i 1)))) ve wrap_level)
) (if se_env (eval fe se_env) fe))
(prim_comb? x) (idx x 2)
; env emitting doesn't pay attention to real value right now, not sure if that makes sense
; TODO: properly handle de Bruijn indexed envs
(marked_env? x) (cond (and de_sym (= 0 (.marked_env_idx x))) de_sym
true (let (_ (if (not (marked_env_real? x)) (error (str_strip "trying to emit fake env! " de_sym " " (.marked_env_idx x) " " x)))
upper (idx (.env_marked x) -1)
upper_env (if upper (recurse upper true de_sym) empty_env)
just_entries (slice (.env_marked x) 0 -2)
vdict (map (lambda ([k v]) [k (recurse v true de_sym)]) just_entries)
) (add-dict-to-env upper_env vdict)))
(marked_env? x) (cond (and (not need_value) (= 0 (.marked_env_idx x))) [current-env]
true (let (_ (if (not (marked_env_real? x)) (error (str_strip "trying to emit fake env!" x)))
upper (idx (.env_marked x) -1)
upper_env (if upper (recurse upper true) empty_env)
just_entries (slice (.env_marked x) 0 -2)
vdict (map (lambda ([k v]) [k (recurse v true)]) just_entries)
) (add-dict-to-env upper_env vdict)))
true (error (str "some other strip? " x))
)
)) (lambda (x) (let (_ (print_strip "stripping: " x) r (helper x false nil) _ (println "result of strip " r)) r)))
)) (lambda (x) (let (_ (print_strip "stripping: " x) r (helper x false) _ (println "result of strip " r)) r)))
; A bit wild, but what if instead of is_value we had an evaluation level integer, kinda like wrap?
; when lowering, it could just turn into multiple evals or somesuch, though we'd have to be careful of envs...