Skip to content

Commit 8471aa2

Browse files
committed
Compile match/case int literals
1 parent 3bc09d1 commit 8471aa2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

scrapscript.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4443,6 +4443,14 @@ def record_each(obj: Object) -> Object:
44434443
| {type="Function", arg=arg, body=body} ->
44444444
"(" ++ (compile arg) ++ " => " ++ (compile body) ++ ")"
44454445
| {type="Apply", func=func, arg=arg} -> "(" ++ (compile func) ++ ")(" ++ (compile arg) ++ ")"
4446+
| {type="MatchFunction", cases=cases} ->
4447+
(foldr (case -> acc -> (compile_case case) ++ "\n" ++ acc)
4448+
"raise 'no matching cases';"
4449+
cases
4450+
. compile_case =
4451+
| {type="MatchCase", pattern={type="Int", value=value}, body=body} ->
4452+
"if (__arg == " ++ ($$int_as_str value) ++ ") { return " ++ (compile body) ++ "; }"
4453+
)
44464454
44474455
. join = sep ->
44484456
| [] -> ""

0 commit comments

Comments
 (0)