1 global store_bottom = 0;
8 constant VN__SIZE = (3*2);
10 global store_firstvar = 0;
12 ! Initialise the program store.
14 [ store_init bottom top;
15 store_bottom = bottom;
18 store_eop = store_bottom;
22 ! --- Heap management -------------------------------------------------------
24 ! Heap reinitialisation; all heap pointers are invalidated.
30 ! Create a new variable.
32 [ store_newvar varname type value node;
33 node = mem_alloc(VN__SIZE + strlen(varname) + 1);
34 node-->VN_NEXT = store_firstvar;
35 node-->VN_TYPE = type;
36 node-->VN_VALUE = value;
37 strcpy(node+VN__SIZE, varname);
38 store_firstvar = node;
41 ! Look for an old variable.
43 [ store_searchvar varname node;
44 node = store_firstvar;
47 if (strcmp(varname, node+VN__SIZE) == 0)
49 node = node-->VN_NEXT;
54 ! Assign a value to a variable.
56 [ store_assign varname type value node;
57 node = store_searchvar(varname);
60 node-->VN_TYPE = type;
61 node-->VN_VALUE = value;
64 store_newvar(varname, type, value);
67 ! Get the contents of a variable.
69 [ store_lookup varname node val;
70 node = store_searchvar(varname);
74 val-->0 = node-->VN_TYPE;
75 val-->1 = node-->VN_VALUE;
83 [ store_listvars var count;
89 print " ", (astring) var+VN__SIZE;
90 switch (var-->VN_TYPE)
93 print " integer ", var-->VN_VALUE;
98 string_print(var-->VN_VALUE);
103 print " unknown type";
110 print "Total: ", count, "^";
113 ! --- Program storage -------------------------------------------------------
115 ! List the current program.
117 [ store_listprogram line linelen;
119 while (linelen = line->0)
121 print " ", (line+1)-->0;
122 detokenise_stream(line+3);
123 line = line + linelen;
127 [ store_listprogramhex line linelen;
129 while (linelen = line->0)
131 print " ", (line+1)-->0;
132 detokenise_stream(line+3);
134 hexdump(line, linelen);
135 line = line + linelen;
139 ! Add a line to the program.
141 [ store_addline linenum cmd linelen line i;
145 if ((line+1)-->0 >= linenum)
147 line = line + line->0;
150 ! Do we need to append this line to the end of the program?
157 store_eop->(linelen+3) = 0;
158 store_eop = store_eop + linelen + 3;
162 ! Do we need to remove an existing line first?
164 if ((line+1)-->0 == linenum)
167 memcpy(line, line+i, store_eop-line-i);
168 store_eop = store_eop - i;
172 ! If there's no actual data in the new line, give up.
177 ! Open up space for the new line.
179 memcpy(line+linelen+3, line, store_eop-line);
180 store_eop = store_eop + linelen + 3;
187 (line+1)-->0 = linenum;
188 memcpy(line+3, cmd, linelen);
193 ! Find a line, by number.
195 [ store_findline lineno line;
197 while (line->0 && ((line+1)-->0 ~= lineno))
198 line = line + line->0;