commit dbe8de208e985ad151b10245a3de1c8bf80a4746
parent fe06e0668e247d4b060bbc69f965181ef59f37c1
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 3 Nov 2022 20:08:31 -0400
cc: clear the AST cache after each generation
... rather than in between units. Recent code consolidations allowed us to
generate parsed AST "on-the-fly", without waiting for the whole unit to be
parsed. All information needed for inter-symbols references in contained in
types, not in AST, so we really don't need the AST structures once they're
generated.
It reduces the memory used for DuskCC by an interesting amount. For example,
total system memory usage for running the test suite went to 340KB to 312KB.
Diffstat:
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -10,23 +10,14 @@
?f<< cc/type.fs
\ This arena contains AST structures for the unit being currently parsed.
-\ We reset it between units.
-
+\ We reset it once those structures have been generated.
Arena :new structbind Arena _arena
0 value _ccdebug
: _err ( -- ) abort" ast error" ;
: _assert ( f -- ) not if _err then ;
-\ Symbols are anything that an Ident node can refer to: function or variable.
-\ This dictionary below contain global symbols of the current unit
-create symbols 0 , 0 c, \ this is a dict link
-
-: addSymbol ( ctype -- )
- symbols over CType name dup c@ ( ctype 'dict name len )
- ENTRYSZ + 8 + _arena :[ entry , _arena :] drop ;
-: findSymbol ( name -- ctype-or-0 ) symbols find dup if @ then ;
-: ccast$ _arena :reset 0 symbols ! ;
+: ccast$ _arena :reset ;
\ Unary operators
7 const UOPSCNT
diff --git a/fs/cc/cc.fs b/fs/cc/cc.fs
@@ -9,15 +9,15 @@
\ Compiles input coming from the stdin alias and writes the
\ result to here. Aborts on error.
: cc1, ( -- )
- cctypes$ ccast$ begin ( )
+ cctypes$ begin ( )
nextt? ?dup while parseUnit ( node-or-0 ) ?dup if
_ccdebug if dup printast nl> then ( node )
dup trnode _ccdebug if dup printast nl> then ( node )
- gennode then repeat ;
+ gennode ccast$ then repeat ;
: :c
nextt parseUnit ?dup if
_ccdebug if dup printast nl> then
- dup trnode _ccdebug if dup printast nl> then gennode then ;
+ dup trnode _ccdebug if dup printast nl> then gennode ccast$ then ;
: cc<< ( -- ) ['] cc1, word with-stdin-file ;
diff --git a/fs/cc/type.fs b/fs/cc/type.fs
@@ -144,7 +144,17 @@ create globaldefs 0 , 0 c,
: addGlobalTypedef ( ctype -- ) globaldefs over CType name entry , ;
: findTypedef ( name -- type-or-0 )
dup localdefs find ?dup if nip @ else globaldefs find dup if @ then then ;
-: cctypes$ 0 localdefs ! _arena :reset ;
+
+\ Symbols are anything that an Ident node can refer to: function or variable.
+\ This dictionary below contain global symbols of the current unit
+create symbols 0 , 0 c, \ this is a dict link
+
+: addSymbol ( ctype -- )
+ symbols over CType name dup c@ ( ctype 'dict name len )
+ ENTRYSZ + 8 + _arena :[ entry , _arena :] drop ;
+: findSymbol ( name -- ctype-or-0 ) symbols find dup if @ then ;
+
+: cctypes$ 0 localdefs ! 0 symbols ! _arena :reset ;
: printType* ( type -- ) type*lvl begin ?dup while '*' emit 1- repeat ;