[plt-scheme] Problem embedding scheme in real time application.
At Mon, 25 Jun 2007 08:32:45 +0100, Dan wrote:
> class SchemeInterface
> {
> private:
> Scheme_Env *e;
> Scheme_Object *curout, *v;
> Scheme_Config *config;
>
> mz_jmp_buf * volatile save, fresh;
> [...]
> SchemeInterface::SchemeInterface(void) {
>
> e = NULL;
> curout = NULL;
> v = NULL;
> config = NULL;
>
> save = NULL;
>
> MZ_GC_DECL_REG(5);
> MZ_GC_VAR_IN_REG(0, e);
> MZ_GC_VAR_IN_REG(1, curout);
> MZ_GC_VAR_IN_REG(2, save);
> MZ_GC_VAR_IN_REG(3, config);
> MZ_GC_VAR_IN_REG(4, v);
>
> # ifdef MZ_PRECISE_GC
> # define STACK_BASE &__gc_var_stack__
> # else
> # define STACK_BASE NULL
> # endif
>
> scheme_set_stack_base(STACK_BASE, 1);
I don't think that this will work. The MZ_GC_VAR_IN_REG() macros are
intended for use with local variables, only. They won't work for
fields.
I see that you're stack-allocating the instance of this class, so I
guess maybe it could work, in principle. Still, the extent of the
registration `MZ_GC_DECL_REG(5)' is just in the SchemeInterface
constructor. Maybe that's why you have a top-level MZ_GC_DECL_REG(5),
too, and you meant to remove this one? But MZ_GC_DECL_REG(5) needs to
live on the stack, not as a static (top-level) variable.
Also, scheme_set_stack_base() should be used around a function in which
all the other work is done. It could be in main(), for example.
> Scheme_Object * SchemeInterface::evaluate(const std::string& expression){
>
> Scheme_Object * v = 0;
> v = scheme_eval_string(expression.c_str(), e);
>
> // std::cout << "Output type:" << v->type << std::endl;
>
> scheme_display(v, curout);
> scheme_flush_output(curout);
> return v;
> }
Here, the local variable `v' isn't registered with the GC. This isn't
causing any crashes in the example, though, because you don't actually
use `v' after the call to scheme_display().
Matthew