Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (optional) fully lexically scoped blocks to the MOO language #366

Merged
merged 7 commits into from
Aug 13, 2024

Conversation

rdaum
Copy link
Owner

@rdaum rdaum commented Aug 12, 2024

#281

  • Introduces new begin / end blocks.
  • Adds new variable declaration syntaxes:
    • let declares a lexically scoped variable in the current block context (begin, try, while, if, for)
    • global refers explicitly to a verb-global variable, which are the existing LambdaMOO defaults
    • const creates a variable binding which can only be assigned to once, at its declaration
  • Feature can be disabled with --lexical-scopes=false to the daemon

@rdaum rdaum requested review from nnunley and abesto August 12, 2024 21:41
Copy link
Collaborator

@abesto abesto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(About halfway through, got interrupted; LGTM so far, submitting comments)

crates/compiler/src/builtins.rs Outdated Show resolved Hide resolved
crates/compiler/src/builtins.rs Outdated Show resolved Hide resolved
As new options are added, the granularity needs to better and more descriptive.
Rework variable name binding to have a notion of pre-compilation
declarations (UnboundNames) and post-compilation bound names (Names).
Adds a new notion of block scoped variables, declared using new syntax
"let x =".
Adds new block scope with "begin" and "end" keywords.
Existing block structures like while/if-elseif-else/try/for are also
lexically scopable.
Also adds explicit global variable assignment / declaration via
"global"
By default variables are global, to keep backwards compatibility with
LambdaMOO.
* Adds new keyword 'const' which should in theory allow a variable to be
assigned to only once in the given lexical scope.
* Add a test for disabled lexical scoping
* Also clarifies the CompileError more specifically
Introduces a new-type "BuiltinId" to get away from using usize offsets
explicitly throughout the code.
PC jumps between scopes was not properly popping out the scopes in the
stack inbetween.
@rdaum rdaum merged commit 25b1a3f into main Aug 13, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants