Skip to content

Type checker and interpreter refactors#85

Merged
figgleforth merged 20 commits intomainfrom
type-checker
Apr 7, 2026
Merged

Type checker and interpreter refactors#85
figgleforth merged 20 commits intomainfrom
type-checker

Conversation

@figgleforth
Copy link
Copy Markdown
Owner

Type Checker

The existing Type_Checker stub has been fleshed out into a real static analysis pass that runs before interpretation. It
checks:

  • Annotated assignments x: String = 123 raises Type_Mismatch
  • Typed function parameters with defaults go { x: Number = 'bad'; x } is caught at compile time
  • Call-site argument types, when a function has annotated params, argument types are verified at call sites

The checker does full AST traversal (functions, types, conditionals, loops, directives, etc.), and silently skips anything it can't statically infer (e.g., identifiers with unknown types). A new type_checker_test.rb covers 30+ cases across happy paths and mismatches at the top level, inside functions, types, and conditionals.

A new Type_Mismatch < Type_Checking_Failed error carries the declared and inferred types. Type_Checking_Failed now holds the list of errors it accumulated.

Interpreter Refactors

Several cleanup passes landed alongside the type checker:

  • #find_ruby_class_for_type — replaced two near-identical blocks of Ruby class resolution logic with a single helper
  • #track_static_declaration — deduplicated three copies of the ./ scope operator check into one method
  • #check_dot_access_permissions! — renamed with ! to signal it raises
  • @cd directive — now non-destructive: wraps the target in a Temporary < Scope scope with the target as a sibling, rather than pushing the target directly onto the stack (eliminates the cd_scopes set)
  • For loop stride — collapsed two parallel if stride / else blocks into a single unified chunks.each loop
  • While/until loops — extracted shared iteration logic into on_skip_handler and iteration_proc procs, removing duplicated catch :skip blocks
  • Standard library loading is simplified: no longer spawns a temporary Interpreter to load preload.ore; loads directly into the global scope
  • Ore::Return extracted to its own file, no longer subclass of Scope
  • Server_RunnerUser_Server
  • Extracted build_ore_request and build_ore_response helpers
  • Simplified the DOM onclick path to reuse interp_route_handler instead of manual scope push/pop.

bin/ore

Default invocation (ore <file>) now calls interp_file directly instead of hot-reload. Hot-reload moved to an explicit run subcommand.

- Changed `@cd` directive to use sibling_scopes
- Renamed check_dot_access_permissions to check_dot_access_permissions!  because it raises
- Improved bin/ore, fixing the broken bin/ore usage example in main readme
- Removed destructive assignment scope oddity
Removed unnecessary `cd_scopes` attr
Renamed Server_Runner to User_Server.
Method for collecting routes from an instance was overwriting Interpreter's routes collection by mistake.
Reduce duplicate code
Removed code that duplicates Interpreter#interp_func_call
- No need to pass routes, leftover copypaste hiccup from runtime refactor
- Request and Response objects had complex inits in two locations, factored out
- Removed Request and Response #initillize code since that is now handled in the now factored out builders
- Fix frozen string literal warning by thawing +str
`Return < Scope` is gone, replaced with `Return = Data.define(:value)`.
All tests pass.
Cleaning up unused code
There was no need for a temporary interpreter object here becaue #load_file_into_scope saves and restores state of the interpreter.
Document #load_file_into_scope
Factored out shared code in #interp_conditional
Ore::Dictionary access is now consistent with strings and symbols, and with dot access.

x = { :abc = 123 }
x.abc
x['abc']
x[:abc]

All return value 123.
Tests pass.
@figgleforth figgleforth merged commit cb6ee9a into main Apr 7, 2026
1 check passed
@figgleforth figgleforth deleted the type-checker branch April 7, 2026 23:01
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.

1 participant