google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.07k stars 129 forks source link

Is methods calling other methods supported? #8

Closed mvdan closed 6 years ago

mvdan commented 6 years ago

Whatever I try, I always hit errors like cannot convert Wuffs call "this.advance?(src:in.src)" to C. This leads me to the TODO in the Wuffs source code:

// TODO: fix this.
//
// This might involve calling g.writeExpr with replaceNothing??
return fmt.Errorf("cannot convert Wuffs call %q to C", n.Str(g.tm))

The code in question was the following:

pri struct backBitReader?(
        rem u32,
        cur u8,
        curbits u8[..8],
)

pri func backBitReader.advance?(src reader1)() {
        if this.rem == 0 {
                return error "TODO"
        }
        this.rem -= 1
        this.cur = in.src.read_u8?()
        this.curbits = 8
}

pri func backBitReader.skipPadding?(src reader1)() {
        this.advance?(src:in.src)
}

Am I missing something, or is this simply not supported yet?

nigeltao commented 6 years ago

It's simply not supported yet. The gen.writeCallSuspendibles method in statement.go is full of hard coded hacks at the moment. Sorry.

mvdan commented 6 years ago

Ah, that's unfortunate. It's going to be hard to write any non-trivial piece of code if I can't go beyond a single function body.

Is this up in your TODO list? Can I help in any way?

nigeltao commented 6 years ago

It's on my TODO list, but it's not the highest priority.

Can you help in any way? Right now, no. Later, yes. Soon, possibly.

It's not your fault, but when somebody else filed https://github.com/mvdan/zstd/issues/2 suggesting that you look at Wuffs, it was probably a bit too early, from Wuffs' point of view. Long term, I definitely want to have Wuffs code outside of the std directory in the Wuffs repo, but the language is still churning quite a lot and the toolchain still contains a bunch of TODOs like this one.

Yes, progress is slow. I work part time, and Wuffs is not my main project right now. Sorry.

mvdan commented 6 years ago

Oh, I didn't mean to shame you into getting this done faster - I understand this is a side project, and also a very early stage one.

I also don't think it's that early for me to use it. After all, I'm not expecting to get something usable or stable in the short term. My repository is more of an experiment to play with.

In any case, looking forward to having function calls working :)

mvdan commented 6 years ago

Thanks so much for this! It was definitely the number one reason blocking me from implementing anything non-trivial.