UrForth: fixed some bugs, added simple benchmark
[urasm.git] / urflibs / stdlib / 70-pseudostructs-obsolete.f
blobea61430d872c6c2c8f0bafcf9ee0e7cc4c0463c1
1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; and now for something completely different...
3 ;; UrForth/C Forth Engine!
4 ;; Copyright (C) 2023 Ketmar Dark // Invisible Vector
5 ;; GPLv3 ONLY
6 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;; pseudostructs
8 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 simple-vocabulary (pseudostructs-internal)
12 also-defs: (pseudostructs-internal)
14 ;; create "record->name"
15 : (create-ofs-accessor) ( ofs-in-bytes addr count -- ofs-acc-cfa )
16 (create) latest-cfa swap
17 , does> ( info-addr pfa -- info-addr-with-offset ) @ +
20 ;; create "class->nameX"
21 : (create-accessor) ( addr count ofs-acc-cfa cfa-r/w char -- )
22 >r 2swap string:>pad r> string:pad+char
23 string:pad-cc@ compiler:(create-forth-header)
24 swap compile, compile, compile forth:(exit) compiler:smudge
27 : (create-peek-accessor) ( addr count ofs-acc-cfa -- ) ['] @ [char] @ (create-accessor) ;
28 : (create-poke-accessor) ( addr count ofs-acc-cfa -- ) ['] ! [char] ! (create-accessor) ;
30 prev-defs
33 usage:
35 new-accessors rec->field0
36 new-accessors rec->field1
37 constant rec-size
39 now, "rec-size" is record size in bytes. each field is a cell, and
40 have "rec->field" (offset), "rec->field@" and "rec->field!" accessors.
43 ;; create accessors
44 ;; trashes PAD
45 : new-accessors ( ofs -- ofs+4 ) \ name
46 parse-name 2>r ( ofs | addr count )
47 dup 2r@ (pseudostructs-internal):(create-ofs-accessor) ( ofs ofs-acc-cfa | addr count )
48 dup 2r@ rot (pseudostructs-internal):(create-peek-accessor)
49 2r> rot (pseudostructs-internal):(create-poke-accessor)
50 cell+