@@ -166,11 +166,6 @@ VAL idris_concat(VM* vm, VAL l, VAL r) {
166 char *ls = GETSTR(l);
166 char *ls = GETSTR(l);
167 char *rs = GETSTR(r);
167 char *rs = GETSTR(r);
168 Closure* cl = allocate(vm, sizeof(Closure) + strlen(ls) + strlen(rs) + 1);
168 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.
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.
174 cl -> ty = STRING;
169 cl -> ty = STRING;
175 cl -> info.str = (char*)cl + sizeof(Closure);
170 cl -> info.str = (char*)cl + sizeof(Closure);
176 strcpy(cl -> info.str, ls);
171 strcpy(cl -> info.str, ls);
@@ -234,6 +229,45 @@ VAL idris_readStr(VM* vm, FILE* h) {
234 return str;
229 return str;
232+VAL idris_strHead(VM* vm, VAL str) {
233+ return MKINT(GETSTR(str)[0]);
236+VAL idris_strTail(VM* vm, VAL str) {
237+ return MKSTR(vm, GETSTR(str)+1);
240+VAL idris_strCons(VM* vm, VAL x, VAL xs) {
241+ char *xstr = GETSTR(xs);
242+ Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
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);
251+VAL idris_strIndex(VM* vm, VAL str, VAL i) {
252+ return MKINT(GETSTR(str)[GETINT(i)]);
255+VAL idris_strRev(VM* vm, VAL str) {
256+ char *xstr = GETSTR(str);
257+ Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
260+ cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
262+ int x = strlen(xstr);
264+ cl-> info.str[x+1] = '\0';
266+ cl -> info.str[y++] = xstr[--x];
238void stackOverflow() {
272void stackOverflow() {
239 fprintf(stderr, "Stack overflow");
273 fprintf(stderr, "Stack overflow");