tinygo-org / playground

TinyGo playground and VS Code extension
https://play.tinygo.org/
BSD 3-Clause "New" or "Revised" License
30 stars 7 forks source link

print doesn't show anything on the console #8

Closed conejoninja closed 2 years ago

conejoninja commented 4 years ago

This doesn't show up in the console

print("ABC") // no output

This does

print("ABC\n")  // output: ABC

This works

println("ABC") // output: ABC

This "too"

print("ABC") 
print("DEF")  // output: ABCDEF
aykevl commented 4 years ago

Output is only written when you print a newline (or use println). I think it would be a good idea to fix that, the relevant function is here:

https://github.com/tinygo-org/playground/blob/558ca0c3d51a5bf8e00a1c367b598524222d7438/runner.js#L105

aykevl commented 2 years ago

The new/refactored playground doesn't have this issue anymore. Now it's a limitation of the TinyGo runtime for WebAssembly:

https://github.com/tinygo-org/tinygo/blob/cf0b7edc78e42038a0bb522b3f1a5b76928e730e/src/runtime/runtime_tinygowasm.go#L41-L50

func putchar(c byte) {
    putcharBuffer[putcharPosition] = c
    putcharPosition++

    if c == '\n' || putcharPosition >= putcharBufferSize {
        putcharIOVec.bufLen = putcharPosition
        fd_write(stdout, &putcharIOVec, 1, &putcharNWritten)
        putcharPosition = 0
    }
}

Closing because I don't think there is anything to fix in the playground.