[M3devel] M3 programming problem : GC efficiency / per-thread storage areas?

Mika Nystrom mika at async.caltech.edu
Fri Oct 17 08:50:13 CEST 2008


Jay writes:
...
>How do you manage okToFree?
...

I forgot to answer this q.

Well, the primitive evaluation in the interpreter is just a big
CASE statement.  I really just look at where it references the list
I am making, and if it references the list at all in a branch, I
insert the code "okToFree := FALSE".  The first two parameters are
passed in separately.  

Here's the code... since you ask!

This is the code for the special case of a two-argument Scheme procedure call,
such as (+ x 1) .

PROCEDURE Apply2(t : T; interp : Scheme.T; a1, a2 : Object) : Object
  VAR
      d1, d2 := GetCons();
      free := TRUE;
  BEGIN
      d1.first := a1; d1.rest := d2;
      d2.first := a2; d2.rest := NIL;

      WITH res = Prims(t, interp, d1, a1, a2, free) DO
        IF free THEN
          ReturnCons(d1); ReturnCons(d2)
        END;
        RETURN res
      END
  END Apply2;

PROCEDURE Prims(t : T; interp : Scheme.T; args, x, y : Object;
                VAR free : BOOLEAN) : Object =

   (* The (hopefully temporary) list of arguments is args.  x and
      y are the first two elements of args *)

   BEGIN
      CASE VAL(t.idNumber,P) OF
          P.Eq => RETURN NumCompare(args, '=')  (* known not to let args escape *)
        |
          P.List => free := FALSE; RETURN args  (* args escapes, dont know whither *)
        |
          P.Car => RETURN PedanticFirst(x)  (* doesn't even use args *)

        (* and about another 100 cases follow here *)

      END
   END Prims;

       Mika







More information about the M3devel mailing list