This repository has been archived by the owner on Mar 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructs.f
75 lines (59 loc) · 1.9 KB
/
structs.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
also venery
0 value lastfield
struct %struct
%struct %node sembed struct>node
%struct svar struct.size
struct %field
%field %node sembed field>node
%field svar field.offset
%field svar field.size
%field svar field.inspector
: struct create %struct *struct /node ;
: (.field) ( adr size - )
bounds ?do i @ dup if . else i. then cell +loop ;
: create-field ( struct bytes - <name> ) ( - field )
swap >r
create
here to lastfield
%field *struct dup /node dup r@ push
r@ struct.size @ over field.offset !
['] (.field) over field.inspector ! \ initialize the inspector
udup field.size !
r> struct.size +! ;
previous
: sfield ( struct bytes - <name> ) ( adr - adr+n )
create-field
does> [ 0 field.offset ]# + @ + ;
: svar ( struct - <name> ) ( adr - adr+n )
cell sfield ;
: sizeof ( struct - size )
struct.size @ ;
: *struct ( struct - adr )
here swap sizeof /allot ;
: struct, ( struct - )
*struct drop ;
: is> ( - <code> ) ( adr size - )
r> code> lastfield field.inspector ! ;
: (.fields)
each> ( adr field )
normal
dup body> >name ccount type space
bright
2dup dup field.size @ swap field.inspector @ execute
field.size @ + \ go to next field in the passed instance
;
: .fields ( adr struct - )
dup node.first @ field.offset @ u+ (.fields) drop ;
[defined] h. [if]
: <hex is> drop @ dup 0= if #5 attribute then ." $" h. normal ;
: <adr <hex ;
[else]
: <adr ;
[then]
[defined] f. [if]
: <float is> drop sf@ f. ." e" ;
[then]
: <cstring is> drop count type ;
: <flag is> drop @ if ." true " else ." false " then ;
: <body is> drop @ .name ;
: <word is> drop @ dup if >body .name else i. then ;