|
|
@@ -243,7 +243,7 @@ TOKENS
|
|
|
|
|
|
PRODUCTIONS
|
|
|
M2
|
|
|
- = (. AST.Init; twoPhase := TRUE; astCur := AST.NoNode; astStmt := AST.NoNode; astDecl := AST.NoNode; astImp := AST.NoNode; astImpTail := AST.NoNode;
|
|
|
+ = (. twoPhase := TRUE; astCur := AST.NoNode; astStmt := AST.NoNode; astDecl := AST.NoNode; astImp := AST.NoNode; astImpTail := AST.NoNode;
|
|
|
astImp := AST.NoNode;
|
|
|
astImpTail := AST.NoNode; .)
|
|
|
Unit "." (. FileIO.WriteString(FileIO.StdOut, "ASTDUMP:"); FileIO.WriteLn(FileIO.StdOut); AST.Dump(astUnit, 0); .) .
|
|
|
@@ -257,7 +257,8 @@ PRODUCTIONS
|
|
|
(* Step 4.3: one session compiles DEFINITION, its IMPLEMENTATION
|
|
|
and one program (last) into one image. Units share the symbol
|
|
|
table; imports materialize exported names. *)
|
|
|
- DefUnit (. VAR m1, m2, pn: SymTab.Name; .)
|
|
|
+ DefUnit (. VAR m1, m2, pn: SymTab.Name;
|
|
|
+ astSeq, astTail, astProc: AST.Node; .)
|
|
|
= "DEFINITION" "MODULE"
|
|
|
GetIdent<m1> (. IF NOT SymTab.BeginDef(m1) THEN
|
|
|
SemError(200) END;
|
|
|
@@ -270,14 +271,29 @@ PRODUCTIONS
|
|
|
names are already exported
|
|
|
by the module scope *) .)
|
|
|
GetIdent<pn> { "," GetIdent<pn> } ";" ]
|
|
|
- { ConstBlock | TypeBlock<TRUE> | VarBlock
|
|
|
+ (. astSeq := AST.NoNode;
|
|
|
+ astTail := AST.NoNode; .)
|
|
|
+ { ConstBlock (. AstAppend(AST.NkDeclSeq,
|
|
|
+ astSeq, astTail, astDecl); .)
|
|
|
+ | TypeBlock<TRUE> (. AstAppend(AST.NkDeclSeq,
|
|
|
+ astSeq, astTail, astDecl); .)
|
|
|
+ | VarBlock (. AstAppend(AST.NkDeclSeq,
|
|
|
+ astSeq, astTail, astDecl); .)
|
|
|
| ProcHeading<pn, SymTab.InvalidType> ";"
|
|
|
- (. SymTab.CloseProc;
|
|
|
- QbeGen.AbortFunc; .) }
|
|
|
+ (. (* a heading only: record it so
|
|
|
+ Lower can replay it *)
|
|
|
+ astProc := AST.MakeNode(AST.NkProcDecl);
|
|
|
+ AST.SetOp(astProc, 0);
|
|
|
+ AST.SetChild(astProc, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, pn));
|
|
|
+ AstAppend(AST.NkDeclSeq,
|
|
|
+ astSeq, astTail, astProc);
|
|
|
+ SymTab.CloseProc;
|
|
|
+ QbeGen.AbortFunc; .) }
|
|
|
(. astUnit := AST.MakeNode(AST.NkUnit);
|
|
|
AST.SetChild(astUnit, 0,
|
|
|
AST.MakeLeaf(AST.NkIdent, m1));
|
|
|
- AST.SetChild(astUnit, 1, astDecl);
|
|
|
+ AST.SetChild(astUnit, 1, astSeq);
|
|
|
AST.SetChild(astUnit, 3, astImp);
|
|
|
astDecl := AST.NoNode;
|
|
|
astStmt := AST.NoNode; .)
|
|
|
@@ -384,10 +400,6 @@ PRODUCTIONS
|
|
|
AST.SetChild(astNode, 3, astImp);
|
|
|
astUnit := astNode;
|
|
|
QbeGen.EndModule(m1);
|
|
|
- IF lowerRequested
|
|
|
- AND Lower.CanLower(astNode) THEN
|
|
|
- Lower.LowerUnit(astNode)
|
|
|
- END;
|
|
|
SymTab.EndUnit; .) .
|
|
|
DeclSeq (. VAR astSeq, astTail: AST.Node; .)
|
|
|
= (. astSeq := AST.NoNode;
|