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
)
37 here
>r literal r
> compiler
:(after
-compile
-lit
)
38 here
>r compile
+ r
> compiler
:(after
-compile
-word
)
43 ;; create
"record->nameX"
44 : (create
-accessor
) ( addr count ofs
do-write? char
-- )
45 pad @
>r
" ->" string
:pad
+cc
>r
2swap string
:pad
+cc r
> string
:pad
+char
46 string
:pad
-cc@
(create
)
47 ;; pfa
: ofs cfa
-r
/w
-compile ofs cfa
-r
/w
-exec
48 if , ['] forth:(direct:+:!) , ['] forth
:! ,
49 else , ['] forth:(direct:+:@) , ['] forth
:@
,
55 dup @ ?dup
if swap cell
+ @ here
>r compile
, , r
> compiler
:(after
-compile
-word
)
56 else 2 +cells @ here
>r compile
, r
> compiler
:(after
-compile
-word
) endif
57 else dup @ rot
+ swap
2 +cells @execute
-tail
61 : (create
-peek
-accessor
) ( addr count ofs
-- ) false
[char
] @
(create
-accessor
) ;
62 : (create
-poke
-accessor
) ( addr count ofs
-- ) true
[char
] ! (create
-accessor
) ;
67 simple
-vocabulary
(struct
-accs
-defs
)
68 also
-defs
: (struct
-accs
-defs
)
70 : def
: ( ofs
-- ofs
+4 ) \ name
72 parse
-name dup
" accessor name expected" ?not
-error
73 2dup r@
(struct
-accs
-internal
):(create
-ofs
-accessor
) >r
74 2dup r@
(struct
-accs
-internal
):(create
-peek
-accessor
)
75 r
> (struct
-accs
-internal
):(create
-poke
-accessor
)
79 : end-accessors
( ofs
-- )
82 " -size" string
:pad
+cc
83 string
:pad
-cc@ compiler
:(create
-header
)
84 compiler
:(cfaidx
-do-const
) compiler
:cfa
, ,
93 : define
-accessors
( -- 0 ) \ name
94 parse
-name string
:>pad
95 0 also
(struct
-accs
-defs
)
105 debug
:decompile boo
->second
!