diff options
author | Ayke van Laethem <[email protected]> | 2024-11-15 09:09:04 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2024-11-15 10:11:57 +0100 |
commit | 6d4dfcf72fb5dd4cc9130c3b883fd313a5b8dac3 (patch) | |
tree | 95845071ea74b4a29f455be3afeac633edba905e /compiler/compiler.go | |
parent | ac9f72be617e6e72423fa7afd6bcd2aaf9377d27 (diff) | |
download | tinygo-6d4dfcf72fb5dd4cc9130c3b883fd313a5b8dac3.tar.gz tinygo-6d4dfcf72fb5dd4cc9130c3b883fd313a5b8dac3.zip |
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.
Diffstat (limited to 'compiler/compiler.go')
-rw-r--r-- | compiler/compiler.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go index 981993fe7..8b5f0d1cb 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -17,6 +17,7 @@ import ( "github.com/tinygo-org/tinygo/compiler/llvmutil" "github.com/tinygo-org/tinygo/loader" + "github.com/tinygo-org/tinygo/src/tinygo" "golang.org/x/tools/go/ssa" "golang.org/x/tools/go/types/typeutil" "tinygo.org/x/go-llvm" @@ -1869,10 +1870,9 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error) } return llvm.ConstInt(b.ctx.Int1Type(), supportsRecover, false), nil case name == "runtime.panicStrategy": - // These constants are defined in src/runtime/panic.go. panicStrategy := map[string]uint64{ - "print": 1, // panicStrategyPrint - "trap": 2, // panicStrategyTrap + "print": tinygo.PanicStrategyPrint, + "trap": tinygo.PanicStrategyTrap, }[b.Config.PanicStrategy] return llvm.ConstInt(b.ctx.Int8Type(), panicStrategy, false), nil case name == "runtime/interrupt.New": |