compiler, runtime: move constants into shared package

Use a single package for certain constants that must be the same between
the compiler and the runtime.

While just using the same values in both places works, this is much more
obvious and harder to mess up. It also avoids the need for comments
pointing to the other location the constant is defined. And having it in
code makes it possible for IDEs to analyze the source.

In the future, more such constants and maybe algorithms can be added.
This commit is contained in:
Ayke van Laethem
2024-11-15 09:09:04 +01:00
committed by Ayke
parent ac9f72be61
commit 6d4dfcf72f
7 changed files with 42 additions and 40 deletions
+3 -7
View File
@@ -3,6 +3,7 @@ package runtime
import (
"internal/task"
"runtime/interrupt"
"tinygo"
"unsafe"
)
@@ -22,11 +23,6 @@ func tinygo_longjmp(frame *deferFrame)
// Returns whether recover is supported on the current architecture.
func supportsRecover() bool
const (
panicStrategyPrint = 1
panicStrategyTrap = 2
)
// Compile intrinsic.
// Returns which strategy is used. This is usually "print" but can be changed
// using the -panic= compiler flag.
@@ -48,7 +44,7 @@ type deferFrame struct {
// Builtin function panic(msg), used as a compiler intrinsic.
func _panic(message interface{}) {
if panicStrategy() == panicStrategyTrap {
if panicStrategy() == tinygo.PanicStrategyTrap {
trap()
}
// Note: recover is not supported inside interrupts.
@@ -76,7 +72,7 @@ func runtimePanic(msg string) {
}
func runtimePanicAt(addr unsafe.Pointer, msg string) {
if panicStrategy() == panicStrategyTrap {
if panicStrategy() == tinygo.PanicStrategyTrap {
trap()
}
if hasReturnAddr {