3 constant STRING_NEXT 0;
7 constant STRING__SIZE (4*2);
9 ! Initialise the string store.
15 ! Returns false if the string is constant (i.e., it points to a literal in
16 ! the byte-code itself).
19 return ((s < store_bottom) || (s > store_eop));
22 ! Add an entry for a new string.
24 [ string_alloc str len s;
25 if (string_isvar(str))
27 ! Need to duplicate the string.
32 s = mem_alloc(STRING__SIZE);
33 s-->STRING_NEXT = string_first;
46 print (char) (s++)->0;
49 ! Compare two strings.
51 [ string_compare s1 s2 i;
53 if (i ~= s2-->STRING_LEN)
58 if ((s1++)->0 ~= (s2++)->0)
63 ! Garbage collection: clean.
74 ! Garbage collection: mark.
80 if (var-->VN_TYPE == TYPE_STRING)
81 var-->VN_VALUE-->STRING_REF = 1;
87 ! Garbage collection: list status.
93 print s, " ", s-->STRING_NEXT, " ";
95 print " ", s-->STRING_REF, "^";
101 ! Garbage collection: sweep.
103 [ string_sweep s olds news;
108 news = s-->STRING_NEXT;
109 if (s-->STRING_REF == 0)
111 if (string_isvar(s-->STRING_PTR))
112 mem_free(s-->STRING_PTR);
114 olds-->STRING_NEXT = news;
117 ! If olds is null, then we're on the first
118 ! string in the list; which means we need to
119 ! change string_first when we remove it.
141 ! Phase three: sweep.
145 ! Turn a string into an int.
147 [ string_toint s len i neg;
148 len = s-->STRING_LEN;
153 while (len && (s->0 == 32 or 9))
172 while (len && (s->0 >= '0') && (s->0 <= '9'))
174 i = i*10 + (s->0 - '0');