-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Whenever a function is called, a 64-bit integer value is pushed onto an "array" - this array is actually just a stack-allocated global of bytes that is meant to emulate the callstack. The 64-bit integer represents an encoding of the function being called, the file in which it was called, and the line within that file on which it was called. After the function returns, the value is "popped" from this array.
- Loading branch information
Showing
8 changed files
with
559 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import foo from "process" | ||
import "process" as process | ||
|
||
println(foo()) | ||
func foo() { | ||
print("hello ") | ||
bar() | ||
} | ||
|
||
var capturedInt = 11 | ||
type FooWithCaptures { | ||
i: Int | ||
func bar() { | ||
print("world") | ||
baz() | ||
} | ||
|
||
func foo_(self): Int = self.i + capturedInt | ||
func foo2(self, a = capturedInt): Int = self.i + a | ||
func fooStatic(): Int = capturedInt | ||
func baz() { | ||
println("!") | ||
println(process.callstack()) | ||
} | ||
|
||
val fooWithCaptures = FooWithCaptures(i: 12) | ||
/// Expect: 23 | ||
println(fooWithCaptures.foo_()) | ||
capturedInt = 17 | ||
println(capturedInt) | ||
val arr = [1].map((i, _) => { | ||
foo() | ||
i + 1 | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import "process" as process | ||
|
||
func foo() { | ||
print("hello ") | ||
bar() | ||
} | ||
|
||
func bar() { | ||
print("world") | ||
baz() | ||
} | ||
|
||
func baz() { | ||
println("!") | ||
println(process.getStackTrace()) | ||
} | ||
|
||
val arr = [1].map((i, _) => { | ||
foo() | ||
i + 1 | ||
}) | ||
|
||
/// Expect: hello world! | ||
/// Expect: Stack trace: | ||
/// Expect: at getStackTrace (%TEST_DIR%/compiler/process_callstack.abra:15) | ||
/// Expect: at baz (%TEST_DIR%/compiler/process_callstack.abra:10) | ||
/// Expect: at bar (%TEST_DIR%/compiler/process_callstack.abra:5) | ||
/// Expect: at foo (%TEST_DIR%/compiler/process_callstack.abra:19) | ||
/// Expect: at <expression> (%STD_DIR%/prelude.abra:592) | ||
/// Expect: at Array.map (%TEST_DIR%/compiler/process_callstack.abra:18) | ||
|
||
type OneTwoThreeIterator { | ||
_count: Int = 1 | ||
|
||
func next(self): Int? { | ||
val v = self._count | ||
if v > 3 { | ||
println(process.getStackTrace()) | ||
None | ||
} else { | ||
self._count += 1 | ||
return Some(v) | ||
} | ||
} | ||
} | ||
|
||
val iter = OneTwoThreeIterator() | ||
for i in iter { | ||
println(i) | ||
} | ||
|
||
/// Expect: 1 | ||
/// Expect: 2 | ||
/// Expect: 3 | ||
/// Expect: Stack trace: | ||
/// Expect: at getStackTrace (%TEST_DIR%/compiler/process_callstack.abra:38) | ||
/// Expect: at OneTwoThreeIterator.next (%TEST_DIR%/compiler/process_callstack.abra:48) | ||
|
||
func returnOneButAlsoPrintStackTraceForSomeReason(): Int { | ||
println(process.getStackTrace()) | ||
1 | ||
} | ||
|
||
type TypeWithFieldInitializer { | ||
i: Int = returnOneButAlsoPrintStackTraceForSomeReason() | ||
} | ||
|
||
val _ = TypeWithFieldInitializer(i: 14) | ||
val _ = TypeWithFieldInitializer() | ||
|
||
/// Expect: Stack trace: | ||
/// Expect: at getStackTrace (%TEST_DIR%/compiler/process_callstack.abra:60) | ||
/// Expect: at returnOneButAlsoPrintStackTraceForSomeReason (%TEST_DIR%/compiler/process_callstack.abra:65) | ||
/// Expect: at TypeWithFieldInitializer (%TEST_DIR%/compiler/process_callstack.abra:69) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters