Skip to content

Commit 986a450

Browse files
committed
Compile match/case int literals
1 parent 01a1b71 commit 986a450

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
@@ -4438,6 +4438,14 @@ def record_each(obj: Object) -> Object:
44384438
| {type="Function", arg=arg, body=body} ->
44394439
"(" ++ (compile arg) ++ " => " ++ (compile body) ++ ")"
44404440
| {type="Apply", func=func, arg=arg} -> "(" ++ (compile func) ++ ")(" ++ (compile arg) ++ ")"
4441+
| {type="MatchFunction", cases=cases} ->
4442+
(foldr (case -> acc -> (compile_case case) ++ "\n" ++ acc)
4443+
"raise 'no matching cases';"
4444+
cases
4445+
. compile_case =
4446+
| {type="MatchCase", pattern={type="Int", value=value}, body=body} ->
4447+
"if (__arg == " ++ ($$int_as_str value) ++ ") { return " ++ (compile body) ++ "; }"
4448+
)
44414449
44424450
. join = sep ->
44434451
| [] -> ""

0 commit comments

Comments
 (0)