Immutable infered types
This commit is contained in:
@@ -12,7 +12,6 @@ uses
|
||||
Myc.Ast.Visitor,
|
||||
Myc.Ast.Scope,
|
||||
Myc.Ast.Analyzer,
|
||||
Myc.Ast.Types,
|
||||
Myc.Ast;
|
||||
|
||||
type
|
||||
@@ -162,7 +161,6 @@ begin
|
||||
Result := TAst.Block([]);
|
||||
|
||||
// Set the type of the root expression (e.g., the final 'do' block)
|
||||
(Result as TAstNode).StaticType := TTypes.Unknown;
|
||||
Descriptor := FCurrentDescriptor;
|
||||
finally
|
||||
ExitScope;
|
||||
@@ -195,7 +193,7 @@ begin
|
||||
begin
|
||||
var keywordNode := (Node.Callee as TKeywordNode);
|
||||
if Length(Node.Arguments) <> 1 then
|
||||
raise ETypeException.CreateFmt(
|
||||
raise EArgumentException.CreateFmt(
|
||||
'Keyword :%s expects exactly one argument (the record/map), but got %d',
|
||||
[keywordNode.Value.Name, Length(Node.Arguments)]);
|
||||
|
||||
@@ -264,18 +262,18 @@ begin
|
||||
EnterScope;
|
||||
try
|
||||
// Define <self> (slot 0)
|
||||
FCurrentDescriptor.Define('<self>', TTypes.Unknown);
|
||||
FCurrentDescriptor.Define('<self>');
|
||||
|
||||
// Define parameters
|
||||
for i := 0 to High(N.Parameters) do
|
||||
begin
|
||||
var paramNode := N.Parameters[i]; // This is a TIdentifierNode
|
||||
var slotIndex := FCurrentDescriptor.Define(paramNode.Name, TTypes.Unknown);
|
||||
var slotIndex := FCurrentDescriptor.Define(paramNode.Name);
|
||||
adr := TResolvedAddress.Create(akLocalOrParent, 0, slotIndex);
|
||||
|
||||
// --- Replace Node ---
|
||||
// Create a new TBoundIdentifierNode (implementation is in Myc.Ast)
|
||||
var boundParamNode := TBoundIdentifierNode.Create(paramNode.Name, adr);
|
||||
var boundParamNode := TAst.BoundIdentifier(paramNode.Name, adr);
|
||||
// Replace it in the parameter array
|
||||
N.Parameters[i] := boundParamNode;
|
||||
end;
|
||||
@@ -364,8 +362,7 @@ begin
|
||||
|
||||
// --- Replace Node ---
|
||||
// Create the new TBoundIdentifierNode (implementation is in Myc.Ast)
|
||||
Result := TBoundIdentifierNode.Create(Node.Name, adr);
|
||||
// StaticType remains TTypes.Unknown (default)
|
||||
Result := TAst.BoundIdentifier(Node.Name, adr);
|
||||
end
|
||||
else
|
||||
begin
|
||||
@@ -390,13 +387,12 @@ begin
|
||||
N.Initializer := Accept(N.Initializer);
|
||||
|
||||
// 2. Define variable in *current* scope
|
||||
slotIndex := FCurrentDescriptor.Define(N.Identifier.Name, TTypes.Unknown);
|
||||
slotIndex := FCurrentDescriptor.Define(N.Identifier.Name);
|
||||
address := TResolvedAddress.Create(akLocalOrParent, 0, slotIndex);
|
||||
|
||||
// 3. --- Replace Node ---
|
||||
// Replace the TIdentifierNode with a new TBoundIdentifierNode
|
||||
N.Identifier := TBoundIdentifierNode.Create(N.Identifier.Name, address);
|
||||
// StaticType remains TTypes.Unknown (default)
|
||||
N.Identifier := TAst.BoundIdentifier(N.Identifier.Name, address);
|
||||
|
||||
// 4. Mutate this declaration node
|
||||
N.IsBoxed := (FBoxedDeclarations <> nil) and FBoxedDeclarations.Contains(Node);
|
||||
|
||||
Reference in New Issue
Block a user