diff options
Diffstat (limited to 'src/runtime/nonhosted.go')
-rw-r--r-- | src/runtime/nonhosted.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/runtime/nonhosted.go b/src/runtime/nonhosted.go new file mode 100644 index 000000000..61f5023df --- /dev/null +++ b/src/runtime/nonhosted.go @@ -0,0 +1,48 @@ +// +build baremetal js + +package runtime + +// This file is for non-hosted environments, that don't support command line +// parameters or environment variables. To still be able to run certain tests, +// command line parameters and environment variables can be passed to the binary +// by setting the variables `runtime.osArgs` and `runtime.osEnv`, both of which +// are strings separated by newlines. +// +// The primary use case is `tinygo test`, which takes some parameters (such as +// -test.v). + +var env []string + +//go:linkname syscall_runtime_envs syscall.runtime_envs +func syscall_runtime_envs() []string { + return env +} + +var osArgs string +var osEnv string + +func init() { + if osArgs != "" { + s := osArgs + start := 0 + for i := 0; i < len(s); i++ { + if s[i] == 0 { + args = append(args, s[start:i]) + start = i + 1 + } + } + args = append(args, s[start:]) + } + + if osEnv != "" { + s := osEnv + start := 0 + for i := 0; i < len(s); i++ { + if s[i] == 0 { + env = append(env, s[start:i]) + start = i + 1 + } + } + env = append(env, s[start:]) + } +} |