mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user