wasm4 icon indicating copy to clipboard operation
wasm4 copied to clipboard

Using Go and append() make the cartridge fail at runtime

Open matm opened this issue 1 year ago • 3 comments

Adding this code snippet into the main.go just after a w4 init

var s = []int{1}

//go:export start
func start() {
        s = append(s, 2)
}

compiles fine but fails at runtime with the blue screen error

The cartridge has tried to import a missing function. See console for more details.

Unfortunately there is nothing in the console.

We recently merged this target.json for games written in Go, maybe we're missing something there, I don't know:

{
    "llvm-target": "wasm32-unknown-unknown",
    "cpu": "generic",
    "features": "+mutable-globals,+nontrapping-fptoint,+sign-ext,+bulk-memory",
    "build-tags": [
        "tinygo.wasm",
        "wasm_unknown"
    ],
    "goos": "linux",
    "goarch": "arm",
    "linker": "wasm-ld",
    "rtlib": "compiler-rt",
    "scheduler": "none",
    "cflags": [
        "-mno-bulk-memory",
        "-mnontrapping-fptoint",
        "-msign-ext"
    ],
    "ldflags": [
        "--allow-undefined",
        "--no-demangle",
        "--import-memory",
        "--initial-memory=65536",
        "--max-memory=65536",
        "--stack-first",
        "--no-entry",
        "-zstack-size=14752"
    ]
}

So for now, append() can't be used at all, which is very annoying :(

Using

$ tinygo version
tinygo version 0.34.0 linux/amd64 (using go version go1.23.3 and LLVM version 18.1.2)

matm avatar Dec 16 '24 06:12 matm

That means the current snake tutorial in Go fails at runtime.

matm avatar Dec 16 '24 06:12 matm

Okay, I think the current settings in target.json lead to missing features. I mean, some function calls don't work, append() can't be used without having a blue screen of the death. Same for the rand package which can be imported by raises runtime errors.

The current setup has to be wrong. I don't know tinygo much, maybe some of you can help guys? There is no way to make the current Snake tutorial work at all with these target.json parameters.

matm avatar Dec 17 '24 19:12 matm

I have the same problem. I have taken a hint from the previous thread https://github.com/aduros/wasm4/issues/595#issuecomment-1320522258 about this issue and added the following Code to the wasm4.go file:

//go:linkname getCurrentStackPointer tinygo_getCurrentStackPointer
func getCurrentStackPointer() uintptr {
	return 0
}

Of course fixing the target.json would be a better solution.

raytracer avatar Feb 10 '25 13:02 raytracer