@@ -166,11 +166,6 @@ VAL idris_concat(VM* vm, VAL l, VAL r) {
166166 char *ls = GETSTR(l);
167167 char *rs = GETSTR(r);
168168 Closure* cl = allocate(vm, sizeof(Closure) + strlen(ls) + strlen(rs) + 1);
169− // Oops! problem if the second allocate triggers a gc because cl has
170− // to be a root. Fix by allocating all in one go.
171−
172− // Also note that l/r may be in from space, so don't delete after collection,
173− // rather, delete just before the next collection.
174169 cl -> ty = STRING;
175170 cl -> info.str = (char*)cl + sizeof(Closure);
176171 strcpy(cl -> info.str, ls);
@@ -234,6 +229,45 @@ VAL idris_readStr(VM* vm, FILE* h) {
234229 return str;
235230}
236231
232+VAL idris_strHead(VM* vm, VAL str) {
233+ return MKINT(GETSTR(str)[0]);
234+}
235+
236+VAL idris_strTail(VM* vm, VAL str) {
237+ return MKSTR(vm, GETSTR(str)+1);
238+}
239+
240+VAL idris_strCons(VM* vm, VAL x, VAL xs) {
241+ char *xstr = GETSTR(xs);
242+ Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
243+ strlen(xstr) + 2);
244+ cl -> ty = STRING;
245+ cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
246+ cl -> info.str[0] = (char)(GETINT(x));
247+ strcpy(cl -> info.str+1, xstr);
248+ return cl;
249+}
250+
251+VAL idris_strIndex(VM* vm, VAL str, VAL i) {
252+ return MKINT(GETSTR(str)[GETINT(i)]);
253+}
254+
255+VAL idris_strRev(VM* vm, VAL str) {
256+ char *xstr = GETSTR(str);
257+ Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
258+ strlen(xstr) + 1);
259+ cl -> ty = STRING;
260+ cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
261+ int y = 0;
262+ int x = strlen(xstr);
263+
264+ cl-> info.str[x+1] = '\0';
265+ while(x>0) {
266+ cl -> info.str[y++] = xstr[--x];
267+ }
268+ return cl;
269+}
270+
237271
238272void stackOverflow() {
239273 fprintf(stderr, "Stack overflow");