duskos

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

commit 94b90abd07cf165c7ce32bdb395727c6e84e1d9d
parent 68f5fa6f8be788619166e5245e503e57c1749c77
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 17 Aug 2022 07:42:38 -0400

Replace structbind' with :self

Diffstat:
Mfs/doc/usage.txt | 5+++++
Mfs/sys/file.fs | 4++--
Mfs/tests/fs/fat.fs | 2+-
Mfs/xcomp/bootlo.fs | 20+++++++++++---------
4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/fs/doc/usage.txt b/fs/doc/usage.txt @@ -166,6 +166,11 @@ it to be rebinded. So, you can rebind structbinds and this is done with the word MyData1 :bleh . \ prints 7 someword . \ prints 4 +All structs have a ":self" method which is a noop, and thus return a reference +to the data. It can be used to get a structbind's data reference: + + data2 :self \ MyData1 is on PS TOS + You can also extend a previous struct with a new struct: extends Foo struct[ Bar diff --git a/fs/sys/file.fs b/fs/sys/file.fs @@ -9,14 +9,14 @@ struct[ FSInfo 26 const MAXFSCNT create filesystems MAXFSCNT CELLSZ * allot0 -' activefs structbind' @ filesystems ! \ record our boot FS in the list +activefs :self filesystems ! \ record our boot FS in the list 0 value curdir create _buf $100 allot 0 value _fs : findpathdir ( path -- dirid? name-or-0 ) - ['] activefs structbind' @ to _fs + activefs :self to _fs A>r 0 _buf c!+ >A c@+ ( a len ) over c@ '/' = if 1- >r 1+ 0 ( root ) else over 1+ c@ ':' = if ( a len ) diff --git a/fs/tests/fs/fat.fs b/fs/tests/fs/fat.fs @@ -7,7 +7,7 @@ testbegin 512 TOTSEC RAMDrive :new value mydrv mydrv 16 1 1 TOTSEC 17 - FAT newFAT12 mydrv FAT :mountvolume value myfat -' activefs structbind' @ value oldfs +activefs :self value oldfs myfat ' activefs rebind 0 S" foo.fs" activefs :newfile # S" /foo.fs" findpath# ( fsid ) \ found! diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -5,8 +5,9 @@ ," entry" 0 , sysdict @ , 5 c, here w>e sysdict ! ] dup 1+ swap c@ tuck move, nextmeta @ , over @ , c, here w>e swap ! 0 nextmeta ! ; -," :" 0 , sysdict @ , 1 c, here w>e sysdict ! ] - sysdict word entry ] ; +," code" 0 , sysdict @ , 4 c, here w>e sysdict ! ] + sysdict word entry ; +code : ] code ] ; : e>w 5 + ; : current sysdict @ e>w ; : immediate current 1- dup c@ $80 or swap c! ; @@ -70,16 +71,17 @@ : nc, ( n -- ) >r begin word runword c, next ; \ Compiling words -: code sysdict word entry ; : create code compile (cell) ; : value code compile (val) , ; : const code litn exit, ; 4 const CELLSZ -: alias ' code compile (alias) , ; -: doer code compile (does) CELLSZ allot ; \ TODO: 5 is hardcoded, might not work on all arches -: does> r> ( exit current definition ) current 5 + ! ; -: does' ( w -- 'data ) 5 + CELLSZ + ; +5 const CALLSZ +: alias ' code compile (alias) , ; +0 value _ +: doer code compile (does) here to _ CELLSZ allot ; +: does> r> ( exit current definition ) _ ! ; +: does' ( w -- 'data ) CALLSZ + CELLSZ + ; : &+ ( n -- ) doer , does> @ + ; : &@ ( n -- ) doer , does> @ @ ; : &w@ ( n -- ) doer , does> @ w@ ; @@ -185,6 +187,7 @@ alias noop [then] : struct[ doer 0 , _extends dup if _structsz' @ then , sysdict @ to _cur immediate + sysdict S" :self" entry exit, does> ( 'struct ) @ ( 'dict ) word swap ( str 'dict ) find ( 'word ) ?dup not if curword stype abort" not in namespace!" then @@ -207,8 +210,7 @@ does> ( 'struct ) : structbind ( 'data -- ) ' doer , , immediate does> ( 'bind -- *to* ) dup @ swap CELLSZ + ( 'struct ''data ) compiling if litn compile @ else @ swap then execute ; -: structbind' ( 'bind -- ) does' CELLSZ + ; -: rebind ( 'data 'bind -- ) structbind' ! ; +: rebind ( 'data 'bind -- ) does' CELLSZ + ! ; \ Drive API \ Anticipating lib/drive