[plt-scheme] embedding with 3m
This is from my embedding 3m program, the beginging part of main();
static Scheme_Env *e = NULL;
#ifdef MZ_PRECISE_GC
MZ_GC_DECL_REG(0);
GC_init_type_tags(_scheme_last_type_, scheme_pair_type, scheme_weak_box_type, scheme_ephemeron_type, scheme_rt_weak_array);
scheme_set_stack_base( &__gc_var_stack__, 1);
#else
scheme_set_stack_base( NULL, 1);
#endif
MZ_REGISTER_STATIC(e);
MZ_REGISTER_STATIC(proc);
e = scheme_basic_env();
scheme_set_can_break(1);
Hope it helps.
----- Original Message -----
From: "dave" <dave at pawfal.org>
To: <plt-scheme at list.cs.brown.edu>
Sent: Saturday, January 27, 2007 4:50 AM
Subject: [plt-scheme] embedding with 3m
> Hi all,
>
> Is there an embedding example using 3m anywhere? I've hit a problem
> using the 3m garbage collector (as I'm now porting my app to that) I'm
> using yesterday's svn build (on linux). I've got it down to a few lines
> of code (below). It runs ok for a minute or so, then I get:
>
> #f::0: compile: bad syntax; function application is not allowed, because
> no #%app syntax transformer is bound in: (display "hello")
>
> Of course it may have nothing to do with 3m, but do I need to register
> the Scheme_Env with the garbage collector? I tried that in my main app,
> but it doesn't seem to make a difference.
>
> Compile with: g++ mz.cpp -o mz -L/usr/local/lib
> -I/usr/local/include/plt -lmzscheme3m -ldl
>
> mz.cpp:
> ---8<---
>
> // if this is uncommented, scheme_setjmp won't compile?
> //#define MZ_PRECISE_GC
> #include <scheme.h>
MZ_PRECISE_GC will be added by mzc automatically.
>
> void interpret(Scheme_Env *e, char *code)
> {
> mz_jmp_buf * volatile save, fresh;
> save = scheme_current_thread->error_buf;
> scheme_current_thread->error_buf = &fresh;
>
> if (scheme_setjmp(scheme_error_buf))
> {
> scheme_current_thread->error_buf = save;
> exit(-1);
> }
> else
> {
> scheme_eval_string_all(code, e, 1);
> scheme_current_thread->error_buf = save;
> }
> }
This is also from my program:
mz_jmp_buf * volatile save, fresh;
MZ_GC_DECL_REG(0);
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);
else
//C code when Scheme error happens here
else
_scheme_apply( proc, 0, NULL); //this is the same as your scheme_eval_string
scheme_current_thread->error_buf = save;
> int main(int argc, char *argv[])
> {
> void *stack_start;
> stack_start = (void *)&stack_start;
> scheme_set_stack_base(stack_start, 1);
>
> Scheme_Env *e=NULL;
> e=scheme_basic_env();
>
> while(1)
> {
> interpret(e,"(display \"hello\")(newline)");
> }
>
> return 0;
> }
>
> --->8---
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>