wiz-lang / wiz

A high-level assembly language for writing homebrew software and games on retro console platforms.
http://wiz-lang.org/
Other
405 stars 40 forks source link

Feature request: Marking a label as "global" #140

Open shinymerlyn opened 2 years ago

shinymerlyn commented 2 years ago

I'd like to have a flag for labels that lets me hoist them from some inner scope to a top-level scope.

I don't think I'd necessarily write code this way, but existing assembly code often has hairy control flow, and Wiz is a pretty nice target for manual disassembly. Code that's been optimized for binary size is often especially patchy when it comes to control flow. Breaking up the code into a bunch of tiny fallthrough functions always "works", but it doesn't necessarily capture the semantics in some cases as my proposal would.

Examples of what I'd like to see working:

TestOne:
    y = 16;
    do {
        // some stuff here...
        global PartWayThroughLoop:  // inside do/while loop scope, would be hoisted to top-level scope
        // maybe some more here...
        --y;
    } while !negative;

TestTwo:
    // ...
    y = 4;
    goto PartWayThroughLoop;
func SomeFunction() {
    // some code...
    global SomeLabel:  // inside function scope, would be hoisted to top-level scope
    // some more code...
}

SomeOtherFunction:
    // ...
    goto SomeLabel;
shinymerlyn commented 2 years ago

In the Wiz Discord, @Bananattack also suggested putting function-hoisted labels in some sort of "namespace". e.g. in the second case, the syntax would be goto SomeFunction.SomeLabel.

I think this wouldn't really affect the first case. It should probably still be goto PartWayThroughLoop for that use case I think?