gbdev / gbdev/rgbds

[Feature request] Nested label scopes

Open
#916 4 comments 1 reaction 0 assignees View on GitHub
enhancement rgbasm
Dominant language
C++
Stars
1.6k
Forks
193
Avg merge
22h 17m
Merged PRs (30d)
26

Description

(Note this this is independent from the concept of "scopes" for symbols in general, which would allow shadowing of outer symbols and auto-purging when the scope ends; see #342.)

Currently there's only one level of symbol scoping: `.local` symbols are scoped to their preceding `Parent`. It might be useful to have more levels, in the manner [described by ax6](https://github.com/gbdev/rgbds/issues/913#issuecomment-889635639):

`..foo` to define a label in the second-level nested scope would be some simple syntax that could be used. Like so:

```
Main:
dw 1234
: ..label isn't allowed here (nonsensical nested label; no parent)
.foo
dw 5678
..bar ; defines Main.foo.bar
dw 9012
.baz ; defines Main.baz (up a level because it only has one dot)
dw 34567
```

Naturally, `...label` would be a third level, etc. Explicit definitions (`.foo.bar`, `Main.foo.bar:`) should also work.

It could autofill each upper level separately: so appending `Main..bar` there would become `Main.baz.bar`, appending `.baz.qux` would become `Main.baz.qux` (and then appending `.baz..spam` would become `Main.baz.qux.spam`).

Contributor guide

Open the contributing guide

Research direction

Read the linked discussion in #913 first, along with the distinction from #342, to clarify the intended nested-label semantics. Done means the proposed dotted syntax, explicit definitions, and independent upper-level autofill behavior are specified and supported consistently; the issue names no implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.