Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass0: fix the pass crashing for CheckedCallAsgn #84

Merged
merged 5 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions passes/pass0.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ proc genCall(c; tree; call: NodeIndex,

# the proc value is pushed to the stack last
c.genExpr(tree, tree.child(call, start + 1))
c.instr(opcIndCall, int32 c.signatures[][tree[call, 0].typ], numArgs(1))
c.instr(opcIndCall, int32 c.signatures[][tree[call, start].typ],
numArgs(1))

proc signExtend(c; typ: Type0) =
if typ.size < 8:
Expand Down Expand Up @@ -489,7 +490,7 @@ proc genExit(c; tree; exit: NodeIndex) =
of CheckedCallAsgn:
c.genCall(tree, exit, 1, ^3)
c.genEh(tree, tree.last(exit))
c.instr(opcPopLocal, tree[exit, 1].id)
c.instr(opcPopLocal, tree[exit, 0].id)
c.exit(tree[tree.child(exit, ^2), 0].imm)
of Unreachable:
c.instr(opcUnreachable)
Expand Down
12 changes: 12 additions & 0 deletions tests/pass0/t03_checked_call_with_result.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.type t0 () -> int
.start t0 p0
LdImmInt 100
Ret
.end
.start t0 p1
.local lo0 int
Call p0 0
PopLocal lo0
GetLocal lo0
Ret
.end
21 changes: 21 additions & 0 deletions tests/pass0/t03_checked_call_with_result.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
discard """
output: "(Done 100)"
"""
(TypeDefs
(ProcTy (Int 8)))
(GlobalDefs)
(ProcDefs
(ProcDef (Type 0) (Locals)
(Continuations
(Continuation (Params) 0
(Continue 1 (IntVal 100)))
(Continuation (Params (Int 8)))))
(ProcDef (Type 0)
(Locals (Int 8))
(Continuations
(Continuation (Params) 0
(CheckedCallAsgn (Local 0) (Proc 0) (Continue 1) (Unwind)))
(Continuation (Params) 0
(Continue 2
(Copy (Local 0))))
(Continuation (Params (Int 8))))))
9 changes: 9 additions & 0 deletions tests/pass0/t03_checked_indirect_call.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.type t0 () -> void
.start t0 p0
Ret
.end
.start t0 p1
LdImmInt 1
IndCall t0 0
Ret
.end
15 changes: 15 additions & 0 deletions tests/pass0/t03_checked_indirect_call.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
discard """
output: "(Done)"
"""
(TypeDefs
(ProcTy (Void)))
(GlobalDefs)
(ProcDefs
(ProcDef (Type 0) (Locals)
(Continuations
(Continuation (Params))))
(ProcDef (Type 0) (Locals)
(Continuations
(Continuation (Params) 0
(CheckedCall (Type 0) (ProcVal 0) (Continue 1) (Unwind)))
(Continuation (Params)))))
13 changes: 13 additions & 0 deletions tests/pass0/t03_checked_indirect_call_with_result.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.type t0 () -> int
.start t0 p0
LdImmInt 100
Ret
.end
.start t0 p1
.local lo0 int
LdImmInt 1
IndCall t0 0
PopLocal lo0
GetLocal lo0
Ret
.end
22 changes: 22 additions & 0 deletions tests/pass0/t03_checked_indirect_call_with_result.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
discard """
output: "(Done 100)"
"""
(TypeDefs
(ProcTy (Int 8)))
(GlobalDefs)
(ProcDefs
(ProcDef (Type 0) (Locals)
(Continuations
(Continuation (Params) 0
(Continue 1 (IntVal 100)))
(Continuation (Params (Int 8)))))
(ProcDef (Type 0)
(Locals (Int 8))
(Continuations
(Continuation (Params) 0
(CheckedCallAsgn (Local 0) (Type 0) (ProcVal 0)
(Continue 1) (Unwind)))
(Continuation (Params) 0
(Continue 2
(Copy (Local 0))))
(Continuation (Params (Int 8))))))