Panic: panic: modulo operand register cannot be R0 #46

Closed
opened 2026-09-02 17:46:53 +00:00 by Furkan · 1 comment

Code:

import io
import fs

const {
    TOTAL   = 4096
    L_BOUND = 65536
}

global {
    freq []uint
    cumul []uint
}

encode(input []byte, output []byte) -> int {
    state := L_BOUND
    pos := 0

    loop i := 0..input.len {
        s := input[i]
        f := freq[s]
        c := cumul[s]

        loop {
            if state < f * 4096 {
                loop.stop()
            }

            output[pos] = (state & 255) as byte
            pos += 1
            state >>= 8
        }

        io.writeLine(state)
        state = (state / f) * TOTAL + c + (state % f)
    }

    return 0
}

main() {
    freq = new(uint, 256)
    cumul = new(uint, 256)

    input, err := fs.readFile("enwik8")
    assert err == 0

    encoded := new(byte, input.len)
    encoded_len := encode(input, encoded)
}

Compiler error

panic: modulo operand register cannot be R0

goroutine 1 [running]:
git.urbach.dev/cli/q/src/asm.(*compilerX86).Compile(0x39fe1a5022b8, {0x7ff6dec25750?, 0x39fe1a5105b6})
	C:/Furkan/Dev/q/src/asm/compilerX86.go:298 +0x4047
git.urbach.dev/cli/q/src/asm.(*Assembler).Compile(0x39fe1a12dca8, 0x39fe1a0e2600)
	C:/Furkan/Dev/q/src/asm/Assembler.go:60 +0x425
git.urbach.dev/cli/q/src/linker.Write({0x7ff6dec740a8, 0x39fe1a502280}, 0x39fe1a0e4750)
	C:/Furkan/Dev/q/src/linker/Write.go:32 +0x27b
git.urbach.dev/cli/q/src/cli.run({0x39fe1a140050?, 0x0?, 0x70?})
	C:/Furkan/Dev/q/src/cli/run.go:29 +0x7a
git.urbach.dev/cli/q/src/cli.Exec({0x39fe1a140050?, 0x7ff6dec76978?, 0x39fe1a126000?})
	C:/Furkan/Dev/q/src/cli/Exec.go:33 +0x2b2
main.main()
	C:/Furkan/Dev/q/main.go:10 +0x45
Code: ``` import io import fs const { TOTAL = 4096 L_BOUND = 65536 } global { freq []uint cumul []uint } encode(input []byte, output []byte) -> int { state := L_BOUND pos := 0 loop i := 0..input.len { s := input[i] f := freq[s] c := cumul[s] loop { if state < f * 4096 { loop.stop() } output[pos] = (state & 255) as byte pos += 1 state >>= 8 } io.writeLine(state) state = (state / f) * TOTAL + c + (state % f) } return 0 } main() { freq = new(uint, 256) cumul = new(uint, 256) input, err := fs.readFile("enwik8") assert err == 0 encoded := new(byte, input.len) encoded_len := encode(input, encoded) } ``` Compiler error ``` panic: modulo operand register cannot be R0 goroutine 1 [running]: git.urbach.dev/cli/q/src/asm.(*compilerX86).Compile(0x39fe1a5022b8, {0x7ff6dec25750?, 0x39fe1a5105b6}) C:/Furkan/Dev/q/src/asm/compilerX86.go:298 +0x4047 git.urbach.dev/cli/q/src/asm.(*Assembler).Compile(0x39fe1a12dca8, 0x39fe1a0e2600) C:/Furkan/Dev/q/src/asm/Assembler.go:60 +0x425 git.urbach.dev/cli/q/src/linker.Write({0x7ff6dec740a8, 0x39fe1a502280}, 0x39fe1a0e4750) C:/Furkan/Dev/q/src/linker/Write.go:32 +0x27b git.urbach.dev/cli/q/src/cli.run({0x39fe1a140050?, 0x0?, 0x70?}) C:/Furkan/Dev/q/src/cli/run.go:29 +0x7a git.urbach.dev/cli/q/src/cli.Exec({0x39fe1a140050?, 0x7ff6dec76978?, 0x39fe1a126000?}) C:/Furkan/Dev/q/src/cli/Exec.go:33 +0x2b2 main.main() C:/Furkan/Dev/q/main.go:10 +0x45 ```
ed self-assigned this 2026-09-02 19:57:44 +00:00
Owner

Fixed in b9825483f6.

Fixed in https://git.urbach.dev/cli/q/commit/b9825483f6dae769bd46041bb7d8b7e142c3645e.
ed added spent time 2026-09-03 11:12:03 +00:00
30 minutes
Sign in to join this conversation.
No milestone
No assignees
2 participants
Notifications
Total time spent: 30 minutes
ed
30 minutes
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
cli/q#46
No description provided.