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

Pages: 1-

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 14:00

pointer a
Started vomiting right there.

Name: Anonymous 2013-07-27 14:02

this is from tinyscheme by the way. Here's another.


/* allocate new cell segment */
static int alloc_cellseg(scheme *sc, int n) {
     pointer newp;
     pointer last;
     pointer p;
     char *cp;
     long i;
     int k;
     int adj=ADJ;

     if(adj<sizeof(struct cell)) {
       adj=sizeof(struct cell);
     }

     for (k = 0; k < n; k++) {
         if (sc->last_cell_seg >= CELL_NSEGMENT - 1)
              return k;
         cp = (char*) sc->malloc(CELL_SEGSIZE * sizeof(struct cell)+adj);
         if (cp == 0)
              return k;
         i = ++sc->last_cell_seg ;
         sc->alloc_seg[i] = cp;
         /* adjust in TYPE_BITS-bit boundary */
         if(((unsigned long)cp)%adj!=0) {
           cp=(char*)(adj*((unsigned long)cp/adj+1));
         }
         /* insert new segment in address order */
         newp=(pointer)cp;
         sc->cell_seg[i] = newp;
         while (i > 0 && sc->cell_seg[i - 1] > sc->cell_seg[i]) {
             p = sc->cell_seg[i];
             sc->cell_seg[i] = sc->cell_seg[i - 1];
             sc->cell_seg[--i] = p;
         }
         sc->fcells += CELL_SEGSIZE;
         last = newp + CELL_SEGSIZE - 1;
         for (p = newp; p <= last; p++) {
              typeflag(p) = 0;
              cdr(p) = p + 1;
              car(p) = sc->NIL;
         }
         /* insert new cells in address order on free list */
         if (sc->free_cell == sc->NIL || p < sc->free_cell) {
              cdr(last) = sc->free_cell;
              sc->free_cell = newp;
         } else {
               p = sc->free_cell;
               while (cdr(p) != sc->NIL && newp > cdr(p))
                    p = cdr(p);
               cdr(last) = cdr(p);
               cdr(p) = newp;
         }
     }
     return n;
}

Name: Anonymous 2013-07-27 14:37

ok, I'm never using tinyscheme again.


$ tinyscheme
TinyScheme 1.37
(and (make-vector 8000) #t)
#t
(and (make-vector 8000) (make-vector 8000) #t)
No memory!
$

Name: Anonymous 2013-07-27 14:39


$ tinyscheme
TinyScheme 1.37
(and (make-vector 8000) #t)
#t
$
$ tinyscheme
TinyScheme 1.37
(and (make-vector 8000) (make-vector 8000) #t)
No memory!
$

Name: Anonymous 2013-07-27 14:43

I know you decided on tinyscheme after some evaluation that it should be the easiest to review, have you taken a glimpse at some point at chibischeme which is the R7RS reference implementation? or scheme48?

Name: Anonymous 2013-07-27 14:44

>>5

I think it means you have no memory in your computer. Better check them in binary :D

Name: Anonymous 2013-07-27 14:45

>>6
I'll check out chibi scheme. At this point I'm leaning towards chicken. scheme48 was very rude to me once and I can never forgive it.

Name: Anonymous 2013-07-27 18:50

chibi scheme has 15K lines of c source. I think I can handle reviewing this /prog/. Although I am tempted to write tinier scheme. Wanna bet I can implement r5rs in < 4000 lines of c?

Name: Anonymous 2013-07-27 18:56

Definitely not beautiful in form.

Name: Anonymous 2013-07-27 18:58

I'll try for 2000. wish me luck

Name: Anonymous 2013-07-27 18:58

it'll be called scheme2000

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.

Name: Anonymous 2013-07-27 23:49

>>10
High-level languages have beautiful forms, but they're ugly on the inside, low-level languages have the opposite. Function versus form.

Name: Anonymous 2013-07-28 0:02

>>13
Also, all you have to do is re-implement chapter 5 from SICP to output LLVM IR instead of the SICP register machine. You don't even need to mess around with register allocation, the LLVM IR supports arbitrary numbers of named variables and the LLVM assembler does all of the optimization work for you.

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-30.html#%_chap_5

Name: Anonymous 2013-07-28 1:48

RACKET

Name: Anonymous 2013-07-28 4:40

I'm almost done with mark compact in 200 lines.

Name: Anonymous 2013-07-28 8:40

This code is incredibly ugly.

Name: Anonymous 2013-07-28 13:32

>>18
>>1 is the mark stage in a mark and sweep collector. It uses O(1) stack space to traverse any graph of object.

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