google / schism

A self-hosting Scheme to WebAssembly compiler
Apache License 2.0
1.27k stars 65 forks source link

bug related to tail-call-indirect #112

Open jitwit opened 4 years ago

jitwit commented 4 years ago

I hit a bug. During write-bytes, the value #f gets passed to the else clause. The #f comes from encode-uleb. In the example that fails, this is what's passed:

(tail-call-indirect #f (get-local 0) (get-global 4) (get-global 8) (get-global 12) (call 30 (get-local 0)))

In the example where f appears in do-test:

(tail-call-indirect 15 (get-local 0) (get-global 4) (get-global 8) (get-global 12) (call 30 (get-local 0)))

is there instead.

The following library fails to compile:

(library (trivial)
  (export do-test)
  (import (rnrs))
  (define (f g)
    (g 1 2 3))
  (define (do-test) #t))

Both of the following pass:

(library (trivial)
  (export do-test)
  (import (rnrs))
  (define (f g)
    (g 1 2))
  (define (do-test) #t))
(library (trivial)
  (export do-test)
  (import (rnrs))
  (define (f g)
    (g 1 2 3))
  (define (do-test)
    (f (lambda (x y z) x)) 
    #t))