-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnstruc.mud
109 lines (105 loc) · 4.17 KB
/
nstruc.mud
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
;<PACKAGE "NEWSTRUC">
;<RENTRY MSETG NEWSTRUC>
"Does SETG and MANIFEST"
<DEFINE MSETG ("TUPLE" DEFS)
<COND (<NOT <0? <MOD <LENGTH .DEFS> 2>>>
<ERROR BAD-ARGUMENT-LIST!-ERRORS MSETG>)
(T
<REPEAT ((EXPSPLICE <AND <ASSIGNED? EXPSPLICE> .EXPSPLICE>)
(REDEFINE <AND <ASSIGNED? REDEFINE> .REDEFINE>)
(HEAD (T)) (TAIL .HEAD) DEF VAL)
<SET VAL <2 .DEFS>>
<COND (<GASSIGNED? <SET DEF <1 .DEFS>>>
<COND (<OR .REDEFINE <=? .VAL ,.DEF>
<ERROR MSETG .DEF ALREADY-GASSIGNED ,.DEF>>
<GUNASSIGN .DEF>
<UNMANIFEST .DEF>
<AGAIN>)>)
(.EXPSPLICE
<PUTREST .TAIL
(<FORM SETG .DEF .VAL> <FORM MANIFEST .DEF>)>
<SET TAIL <REST .TAIL 2>>)
(T
<SETG .DEF .VAL>
<MANIFEST .DEF>)>
<COND (<EMPTY? <SET DEFS <REST .DEFS 2>>>
<COND (.EXPSPLICE
<MAPF <> ,EVAL <REST .HEAD>>
<RETURN <CHTYPE <REST .HEAD> SPLICE>>)
(<RETURN>)>)>>)>>
"Set up structure definitions. Takes name, primtype, pairs (sort of)
of name & type for slots in structure"
<DEFINE NEWSTRUC (NAM PRIM
"ARGS" ELEM
"AUX" (RPRIM <COND (<TYPE? .PRIM LIST><1 .PRIM>)
(.PRIM)>)
(LL <FORM <FORM PRIMTYPE .RPRIM>>)
(L .LL) OFFS DEC
R RR (CNT 1)
(EXPSPLICE <AND <ASSIGNED? EXPSPLICE> .EXPSPLICE>))
<REPEAT ((HEAD (T)) (TAIL .HEAD))
<COND
(<EMPTY? .ELEM>
<COND (<ASSIGNED? RR> <PUTREST .R (<VECTOR !.RR>)>)>
<COND
(<TYPE? .NAM ATOM>
<COND (<TYPE? .PRIM LIST>
<COND (.EXPSPLICE
<SET TAIL
<REST <PUTREST .TAIL
(<FORM PUT-DECL .NAM
<FORM QUOTE .LL>>)>>>)>
<PUT-DECL .NAM .LL>)
(T
<COND (.EXPSPLICE
<SET TAIL
<REST <PUTREST .TAIL
(<FORM NEWTYPE .NAM .RPRIM
<FORM QUOTE .LL>>)>>>
<NEWTYPE .NAM .RPRIM .LL>)
(T
<NEWTYPE .NAM .RPRIM .LL>)>)>)
(T
<1 .LL .RPRIM>
<EVAL <FORM GDECL .NAM .LL>>
<SET NAM <1 .NAM>>)>
<COND (.EXPSPLICE
<RETURN <CHTYPE <REST .HEAD> SPLICE>>)
(<RETURN .NAM>)>)
(<LENGTH? .ELEM 1> <ERROR NEWSTRUC>)>
<SET OFFS <1 .ELEM>>
<SET DEC <2 .ELEM>>
<COND (<OR <NOT .OFFS> <TYPE? .OFFS FORM>>
<SET CNT <+ .CNT 1>>
<SET ELEM <REST .ELEM>>
<AGAIN>)>
<COND (<AND <TYPE? .OFFS STRING> <=? .OFFS "REST">>
<AND <ASSIGNED? RR> <ERROR NEWSTRUC TWO-RESTS>>
<SET R .L>
<SET RR <SET L <LIST REST>>>
<SET ELEM <REST .ELEM>>
<AGAIN>)
(<TYPE? .OFFS ATOM>
<SETG .OFFS <OFFSET .CNT .NAM ;.DEC>>
<MANIFEST .OFFS>
<COND (.EXPSPLICE
<PUTREST .TAIL
(<FORM SETG .OFFS ,.OFFS>
<FORM MANIFEST .OFFS>)>
<SET TAIL <REST .TAIL 2>>)>)
(<TYPE? .OFFS LIST>
<MAPF <>
<FUNCTION (A)
<SETG .A <OFFSET .CNT .NAM ;.DEC>>
<MANIFEST .A>
<COND (.EXPSPLICE
<PUTREST .TAIL
(<FORM SETG .A ,.A>
<FORM MANIFEST .OFFS>)>
<SET TAIL <REST .TAIL 2>>)>>
.OFFS>)
(T <ERROR NEWSTRUC>)>
<SET CNT <+ .CNT 1>>
<SET L <REST <PUTREST .L (.DEC)>>>
<SET ELEM <REST .ELEM 2>>>>
;<ENDPACKAGE>