duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 441164c5d4f122d3a25ac10ed379c063e53b662e
parent 9d0d5210813171c49cac98c732cb55285341f5c2
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat,  7 Jan 2023 10:12:17 -0500

Add "type" field to struct fields metadata

Also, make methods "real" fields, that is, part of a struct fields LL. My goal
here is to be able to elegantly rebind struct methods.

Diffstat:
Mfs/doc/struct.txt | 9+++++++++
Mfs/lib/struct.fs | 1+
Mfs/tests/lib/struct.fs | 3+++
Mfs/xcomp/bootlo.fs | 24+++++++++++++++++-------
4 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/fs/doc/struct.txt b/fs/doc/struct.txt @@ -215,5 +215,14 @@ Struct Field next Next field (this is a linked list) + type STRUCTFIELD_* offset Offset, in bytes, of that field size Size, in bytes, of that field (1, 2 or 4) + +Field types: + +STRUCTFIELD_REFERENCE regular fields (sfield, sfieldw, sfieldb) +STRUCTFIELD_REGULAR sfield' +STRUCTFIELD_CONST sconst +STRUCTFIELD_METHOD smethod +STRUCTFIELD_STATICMETHOD ssmethod diff --git a/fs/lib/struct.fs b/fs/lib/struct.fs @@ -11,4 +11,5 @@ struct[ Field sfield next sfield offset sfield size \ 1, 2 or 4 + sfield type \ STRUCTFIELD_* ]struct diff --git a/fs/tests/lib/struct.fs b/fs/tests/lib/struct.fs @@ -12,6 +12,9 @@ struct[ Foo \ we can iterate fields of a struct ' Foo does' Struct lastfield S" bling" over wordname[] s[]= # +dup does' Field type STRUCTFIELD_REGULAR #eq +does' Field next S" :bleh" over wordname[] s[]= # +dup does' Field type STRUCTFIELD_METHOD #eq does' Field next S" baz" over wordname[] s[]= # does' Field next S" bar" over wordname[] s[]= # does' Field next 0 #eq diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -224,11 +224,17 @@ does> ( 'struct ) \ Rewind the sysdict to our struct _bkp sysdict @! _cur e>w structdict' ! ; +0 const STRUCTFIELD_REGULAR +1 const STRUCTFIELD_REFERENCE +2 const STRUCTFIELD_CONST +3 const STRUCTFIELD_METHOD +4 const STRUCTFIELD_STATICMETHOD + : sallot ( n -- ) _cur e>w structsz' +! ; -: _sfield ( sz -- ) +: _sfield ( sz type -- ) current _cur e>w structlastfield' @! ( next ) , - _cur e>w structsz , ( sz ) dup , sallot ; -: _svalue ( sz -- ) doer immediate _sfield + _cur e>w structsz , ( sz type ) over , , ( sz ) sallot ; +: _svalue ( sz -- ) doer immediate STRUCTFIELD_REGULAR _sfield does> CELLSZ + @+ swap @ swap ( a? sz off ) compiling if ( sz off ) litn compile + 0 toptr @! ( sz toptr ) @@ -239,10 +245,14 @@ does> ( 'struct ) : sfield CELLSZ _svalue ; : sfieldw 2 _svalue ; : sfieldb 1 _svalue ; -: sfield' ( sz -- ) doer _sfield does> CELLSZ + @ ( a off ) + ; -: sconst doer CELLSZ _sfield does> CELLSZ + @ ( a off ) + @ ; -: smethod doer _cur e>w structsz , CELLSZ sallot does> @ over + @ execute ; -: ssmethod doer _cur e>w structsz , CELLSZ sallot does> @ swap + @ execute ; +: sfield' ( sz -- ) doer STRUCTFIELD_REFERENCE _sfield + does> CELLSZ + @ ( a off ) + ; +: sconst doer CELLSZ STRUCTFIELD_CONST _sfield + does> CELLSZ + @ ( a off ) + @ ; +: smethod doer CELLSZ STRUCTFIELD_METHOD _sfield + does> CELLSZ + @ over + @ execute ; +: ssmethod doer CELLSZ STRUCTFIELD_STATICMETHOD _sfield + does> CELLSZ + @ swap + @ execute ; \ 4b link to struct \ 4b link to data