[plt-scheme] compiled Scheme code in C

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Wed May 30 10:49:01 EDT 2007

Hi all,

I have this C program that Embeds MzScheme (section 1.3 of Inside MzScheme).

It looks like this


 proc = scheme_make_prim_w_arity(foo, "foo", 2, 2);
   scheme_add_global("foo", proc, e);

// where FOOs are functions that do low level thing, so they are in C

 proc = scheme_eval_string_all( "a big String of Scheme code", e, 1);

// where the big String first defines some things (most procedures), and ends with a thunk which calls those defined things
// obviously foo is used everywhere in this String

// in the main loop

 mz_jmp_buf * volatile save, fresh;
 save = scheme_current_thread->error_buf;
 scheme_current_thread->error_buf = &fresh;
 if (scheme_setjmp(scheme_error_buf))
  if (scheme_jumping_to_continuation)
   scheme_longjmp(*save, 1);
  _scheme_apply( proc, 0, NULL);
 scheme_current_thread->error_buf = save;

I'm using PLT v370 here. The "big String" contains most of the computation, so I want it to be compiled. Now I managed to do

 proc = scheme_eval_string( "(eval (load/use-compiled (string->path \"d:/bar.scm\")))", e);

where d:/bar.scm is exactlly that big string, and actually the .zo file of it is loaded. Here I want to ask whether I could do better? Should I use a unit inside of a module for this bar.scm? Must I use a separate file for Scheme code? It will be nice if I can just put compiled Scheme code directly in the .c file (say, a C String start with #~), so that I don't have to specify the absolute path of the scm/zo file.

Many thanks.


Posted on the users mailing list.