Skip to content

Commit 97871bd

Browse files
committed
Compile match/case var
1 parent 85f14cb commit 97871bd

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
@@ -4444,6 +4444,7 @@ def record_each(obj: Object) -> Object:
44444444
"(" ++ (compile arg) ++ " => " ++ (compile body) ++ ")"
44454445
| {type="Apply", func=func, arg=arg} -> "(" ++ (compile func) ++ ")(" ++ (compile arg) ++ ")"
44464446
| {type="MatchFunction", cases=cases} ->
4447+
-- TODO(max): Figure out what to do about __arg. Gensym?
44474448
(foldr (case -> acc -> (compile_case case) ++ "\n" ++ acc)
44484449
"raise 'no matching cases';"
44494450
cases
@@ -4452,6 +4453,12 @@ def record_each(obj: Object) -> Object:
44524453
"if (__arg === " ++ ($$int_as_str value) ++ ") { return " ++ (compile body) ++ "; }"
44534454
| {type="MatchCase", pattern={type="String", value=value}, body=body} ->
44544455
"if (__arg === " ++ ($$str_as_str value) ++ ") { return " ++ (compile body) ++ "; }"
4456+
| {type="MatchCase", pattern={type="Var", name=name}, body=body} ->
4457+
"return (" ++ compile ({type="Where",
4458+
binding={type="Assign",
4459+
name={type="Var", name=name},
4460+
value={type="Var", name="__arg"}},
4461+
body=body}) ++ ");"
44554462
)
44564463
44574464
. join = sep ->

0 commit comments

Comments
 (0)