From 0dcd3513a633479ce228f24826db4f09e4c0fc8b Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 16 Nov 2026 14:25:14 -0800 Subject: Phi fix Fix Phi/Add refactoring peephole to canonicalize regardless of peephole order. Treat class fcns as having `self` be the class pointer --- chapter32/docs/32-grammar.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'chapter32/docs') diff --git a/chapter32/docs/32-grammar.md b/chapter32/docs/32-grammar.md index 2628f566..4a794341 100644 --- a/chapter32/docs/32-grammar.md +++ b/chapter32/docs/32-grammar.md @@ -69,6 +69,7 @@ constructorParameter : type '^'? bindingModifier? IDENTIFIER ; // A method is an ordinary fixed function binding in a struct definition. // The compiler supplies self; it is not written in parameterList. // Function types and expressions both receive their implicit receiver here. +// Global functions use their owning class singleton as self. methodDeclaration : 'val' bindingModifier? memberName '=' functionExpression ';' ; memberName : IDENTIFIER | primitiveType ; @@ -254,10 +255,11 @@ one-pass IR builder: - A statement beginning with `{` might be a block or a function-type binding. `Declarations` and `Types` use speculative parsing and cursor restore; qualified type lookup also stops before a suffix that belongs to an expression. -- Bare assignment, field assignment, and compound updates share the grammar's - precedence but use different IR paths. `References` decides between an SSA - local, a constructor field's local value, and an actual memory access. A - function-valued field may also supply an implicit receiver to a call. +- `References` resolves bare fields through their receiver, so assignments, + reads, and updates share the field-access path. Locals use SSA; class + initializer declarations retain their Scope values until initializer exit. + Global functions receive their owning class singleton as `self`, including + when invoked through a callback. Instance methods receive their object. - `for` updates are scanned first and parsed after the body, where their effects belong. Explicit constructor bodies are scanned first and parsed after field discovery, so later fields have local slots. Both use `Lexer.skipTo`, which -- cgit v1.2.3