WebAssembly/Goto

From Free Pascal wiki
Jump to navigationJump to search

This article is about the implementation of Goto for the WebAssembly target in FPC.

The problem

Goto is difficult to implement, due to WebAssembly's lack of labels and jumps. It requires all gotos to be converted to structured flow, such as loops and break/continue. This requires implementing a complex algorithm, such as Relooper or Stackifier. Useful read: [1]

FPC's implementation

Goto support was added in commit 376de92a50259f77e0dc0e1fc3f7d07135547bbc. The current implementation resolves goto and branches, using a state machine, which is correct, but not very good in terms of speed. In the future, we might implement a faster algorithm (Stackifier).

See Also