blaise/docs
Graeme Geldenhuys 313619511c Add class instance methods (procedure, inline body, Self, method calls)
Lexer:
- Added tkProcedure keyword token.

AST:
- TMethodParam: stores parameter name, type string, and resolved type.
- TMethodDecl: method declaration with name, param list, and inline body
  (TBlock). Avoids TObject.MethodName collision by naming the field Name.
- TClassTypeDef.Methods: owned TObjectList of TMethodDecl.
- TMethodCallStmt: statement node for obj.Method(args) calls; ObjectName
  and Name fields; ResolvedClassType and ResolvedMethod set by semantic.
- TBlock forward-declared before TMethodDecl to break circular dependency.

Parser:
- ParseMethodDecl: parses 'procedure Name [(ParamList)] ; Block ;' inside
  a class body.
- ParseParamList: handles 'Name : Type [; Name : Type ...]' param groups.
- ParseClassDef: field parsing followed by method parsing before 'end'.
- ParseStmt: after 'IDENT.IDENT', dispatches to TFieldAssignment (':=')
  or TMethodCallStmt (everything else, optionally with arg list).
- ParseMethodCallArgList: argument list for method call statements.

Semantic:
- FMethodIndex: TStringList mapping 'TypeName.Name' -> TMethodDecl for
  O(log n) dispatch lookup.
- AnalyseTypeDecls: indexes methods and resolves param types after fields.
- AnalyseMethodBodies: analyses each method body after type registration.
- AnalyseMethodDecl: pushes a scope with Self (class type) and explicit
  params, then calls AnalyseBlock for the method body.
- AnalyseMethodCall: resolves object type, looks up method, checks arg
  count and types; sets ResolvedClassType and ResolvedMethod on the node.

Code generator:
- EmitMethodDefs: emits a QBE function for every method in every class
  type before the main function.
- EmitMethodDef: emits 'function $TypeName_Name(l %_par_Self, ...) {'.
- EmitParamAllocs: allocates stack slots for Self and explicit params.
- EmitMethodCall: loads Self from the caller's var slot, then emits
  'call $TypeName_Name(l selfTemp, ...)'.

Tests: 204 unit tests (24 new method tests), 0 failures.
Grammar: docs/grammar.ebnf updated with MethodDecl, ParamList, MethodCall.
2026-04-20 19:42:09 +01:00
..
design.adoc Add Phase 2: record/class types, ARC strings, RTL stubs, and grammar doc 2026-04-20 19:04:12 +01:00
grammar.ebnf Add class instance methods (procedure, inline body, Self, method calls) 2026-04-20 19:42:09 +01:00