Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Isn t it beautifu

Name: Anonymous 2013-07-27 13:58

Scheme may be elegant but you don't get mind twisters like this. The hacks. The optimizations. They are works of art. They're almost more interesting than the original problem being addressed.


/* ========== garbage collector ========== */

/*--
 *  We use algorithm E (Knuth, The Art of Computer Programming Vol.1,
 *  sec. 2.3.5), the Schorr-Deutsch-Waite link-inversion algorithm,
 *  for marking.
 */
static void mark(pointer a) {
     pointer t, q, p;

     t = (pointer) 0;
     p = a;
E2:  setmark(p);
     if(is_vector(p)) {
          int i;
          int num=ivalue_unchecked(p)/2+ivalue_unchecked(p)%2;
          for(i=0; i<num; i++) {
               /* Vector cells will be treated like ordinary cells */
               mark(p+1+i);
          }
     }
     if (is_atom(p))
          goto E6;
     /* E4: down car */
     q = car(p);
     if (q && !is_mark(q)) {
          setatom(p);  /* a note that we have moved car */
          car(p) = t;
          t = p;
          p = q;
          goto E2;
     }
E5:  q = cdr(p); /* down cdr */
     if (q && !is_mark(q)) {
          cdr(p) = t;
          t = p;
          p = q;
          goto E2;
     }
E6:   /* up.  Undo the link switching from steps E4 and E5. */
     if (!t)
          return;
     q = t;
     if (is_atom(q)) {
          clratom(q);
          t = car(q);
          car(q) = p;
          p = q;
          goto E5;
     } else {
          t = cdr(q);
          cdr(q) = p;
          p = q;
          goto E6;
     }
}

Name: Anonymous 2013-07-27 23:44

Best way to write a modern Scheme is to write a Scheme compiler in Scheme that generates LLVM IR, with a very minimal yet fast GC and FFI library written in C (compiled with Clang) that hooks into the LLVM GC interface. Then bootstrap it.

After you complete the minimal subset of builtin Scheme forms, you can extend the compiler with more as necessary to make it perform better.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List