Skip to content

Commit 83311c4

Browse files
committed
Compile match/case var
1 parent 0a8b976 commit 83311c4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scrapscript.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4439,6 +4439,7 @@ def record_each(obj: Object) -> Object:
44394439
"(" ++ (compile arg) ++ " => " ++ (compile body) ++ ")"
44404440
| {type="Apply", func=func, arg=arg} -> "(" ++ (compile func) ++ ")(" ++ (compile arg) ++ ")"
44414441
| {type="MatchFunction", cases=cases} ->
4442+
-- TODO(max): Figure out what to do about __arg. Gensym?
44424443
(foldr (case -> acc -> (compile_case case) ++ "\n" ++ acc)
44434444
"raise 'no matching cases';"
44444445
cases
@@ -4447,6 +4448,12 @@ def record_each(obj: Object) -> Object:
44474448
"if (__arg === " ++ ($$int_as_str value) ++ ") { return " ++ (compile body) ++ "; }"
44484449
| {type="MatchCase", pattern={type="String", value=value}, body=body} ->
44494450
"if (__arg === " ++ ($$str_as_str value) ++ ") { return " ++ (compile body) ++ "; }"
4451+
| {type="MatchCase", pattern={type="Var", name=name}, body=body} ->
4452+
"return (" ++ compile ({type="Where",
4453+
binding={type="Assign",
4454+
name={type="Var", name=name},
4455+
value={type="Var", name="__arg"}},
4456+
body=body}) ++ ");"
44504457
)
44514458
44524459
. join = sep ->

0 commit comments

Comments
 (0)