News for hackers. Stuff that matters.
Re:My experience crafting an interpreter with Rust (2021) by mughinn on Saturday March 25, 2023 @08:34PM (#35309222)
As someone not versed in Virtual Machine development, is goto so important? What do you gain by using it?
Re:My experience crafting an interpreter with Rust (2021) by c0balt on Saturday March 25, 2023 @09:12PM (#35309549)
Goto is quite a powerful tool for having a full, imperative grip on control flow. It is quite often useful due it's simple yet powerful ability to "just" work. Virtual machines may often encounter situations where a tight control over the flow can be advantagous for performance etc. reasons.

Goto has been iirc a point of discussion from the language design pov for Rust. I don't think it promotes good design for most applications but ymmv.

Re:My experience crafting an interpreter with Rust (2021) by nsajko on Sunday March 26, 2023 @01:39AM (#35311381)
> What do you gain by using it?

Performance, although this possibly depends on your compiler, whether you use PGO, and similar finicky issues.

Example: https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e...

Some prior HN discussion: https://news.ycombinator.com/item?id=18678920

Another example where goto is relevant is implementing finite automata. A (very short) paper from 1988 that discusses three different ways of implementing a finite state machine is "How (Not) to Code a Finite State Machine". The documentation of RE2C may be even more interesting: https://re2c.org

RE2C is a program that compiles finite automata into C, Go, or Rust code. It provides many implementation strategies: it can make use of computed or labelled gotos when the language provides them.

Implementing pushdown automata comes with similar issues.