1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; and now
for something completely different
...
3 ;; UrForth
/C Forth Engine
!
4 ;; Copyright
(C
) 2023 Ketmar Dark
// Invisible Vector
6 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 end-accessors
-- defines constant
"rec-size"
18 now
, "rec-size" is record size in bytes
. each field is a cell
, and
19 have
"rec->field" (offset
), "rec->field@" and
"rec->field!" accessors
.
23 simple
-vocabulary
(struct
-accs
-internal
)
24 also
-defs
: (struct
-accs
-internal
)
26 ;; create
"record->name"
27 : (create
-ofs
-accessor
) ( addr count ofs
-in
-bytes
-- ofs
-in
-bytes
)
29 pad @
>r nrot
" ->" string
:pad
+cc string
:pad
+cc
30 string
:pad
-cc@
(create
) ,
33 does
> ( info
-addr pfa
-- info
-addr
-with
-offset
)
36 compiler
:comp?
if literal compile
+
41 ;; create
"record->nameX"
42 : (create
-accessor
) ( addr count ofs
do-write? char
-- )
43 pad @
>r
" ->" string
:pad
+cc
>r
2swap string
:pad
+cc r
> string
:pad
+char
44 string
:pad
-cc@
(create
)
45 ;; pfa
: ofs cfa
-r
/w
-compile ofs cfa
-r
/w
-exec
46 if , ['] forth:(direct:+:!) , ['] forth
:! ,
47 else , ['] forth:(direct:+:@) , ['] forth
:@
,
53 dup @ ?dup
if swap cell
+ @ compile
-start
, compile
-end,
54 else 2 +cells @ compile
, endif
55 else dup @ rot
+ swap
2 +cells @execute
-tail
59 : (create
-peek
-accessor
) ( addr count ofs
-- ) false
[char
] @
(create
-accessor
) ;
60 : (create
-poke
-accessor
) ( addr count ofs
-- ) true
[char
] ! (create
-accessor
) ;
65 simple
-vocabulary
(struct
-accs
-defs
)
66 also
-defs
: (struct
-accs
-defs
)
68 : def
: ( ofs
-- ofs
+4 ) \ name
70 parse
-name dup
" accessor name expected" ?not
-error
71 2dup r@
(struct
-accs
-internal
):(create
-ofs
-accessor
) >r
72 2dup r@
(struct
-accs
-internal
):(create
-peek
-accessor
)
73 r
> (struct
-accs
-internal
):(create
-poke
-accessor
)
77 : end-accessors
( ofs
-- )
80 " -size" string
:pad
+cc
81 string
:pad
-cc@ compiler
:(create
-header
)
82 compiler
:(cfaidx
-do-const
) compiler
:cfa
, ,
91 : define
-accessors
( -- 0 ) \ name
92 parse
-name string
:>pad
93 0 also
(struct
-accs
-defs
)
103 debug
:decompile boo
->second
!