commit 0db6bee65b0d9253f79a9b656dfbd6163f5afa22
parent adbc5a7ffb4945caa89111eda7d8403a3e7c0c60
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 9 Aug 2022 21:57:39 -0400
Have struct fields hold their own offsets
This will help for the inheritance feature I want to add.
Diffstat:
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -172,6 +172,7 @@ alias noop [then]
\ 4b pointer to last instance used
\ Field's structure:
\ 4b next
+\ 4b offset
\ Xb string
\ Pointer to the last instance calling a struct. If nonzero, the struct will
@@ -184,23 +185,26 @@ alias noop [then]
_getinst + to? ?dup if execute else @ execute then ;
: _parens ( 'struct off )
compiling if litn litn compile (struct()) else swap (struct()) then ;
+: 'structsz ( 'struct -- sz ) llcnt CELLSZ * ;
+: structsz ( w -- sz ) does' 'structsz ;
: struct ( cnt -- )
- doer >r here 0 , 0 ,
- begin ( ll ) lladd word c@+ dup c, move, next drop immediate
+ doer >r here 0 , 0 , 0 begin ( ll off )
+ swap lladd swap dup , CELLSZ + word c@+ dup c, move, next
+ 2drop immediate
does> ( ??? 'struct -- ??? *to* )
word case ( 'struct R:str )
S" '(" of s= 0 _parens endof
- S" ')" of s= dup llcnt CELLSZ * ( 'struct off ) _parens endof
+ S" ')" of s= dup 'structsz ( 'struct off ) _parens endof
\ find field in list
- 0 over @ begin ( 'struct cnt ll )
+ dup @ begin ( 'struct ll )
?dup not if curword stype abort" field doesn't exist!" then
- dup 4 + curword s= if leave else llnext swap 1+ swap then
- next ( 'struct cnt ll ) drop CELLSZ * ( 'struct off )
+ dup 8 + curword s= if leave else llnext then next ( 'struct ll )
+ 4 + @ ( 'struct off )
curword 1+ c@ ':' = if ['] (struct:) else ['] (struct) then >r
compiling if litn litn r> execute, else swap r> execute then
endcase ;
: _inst! ( 'inst -- )
- dup CELLSZ + swap @ ( 'inst 'structword ) does' _getinst' ! ;
+ dup CELLSZ + swap @ ( 'inst w ) does' _getinst' ! ;
: instance ' doer here swap , _inst! immediate does>
dup compiling if litn compile _inst! else _inst! then @ execute ;