I think I'm getting closer. The read() portion seems to work, in that the
correct characters are consumed.
I can then doPrint() on what doRead() returns - although I don't see the
customary parentheses around the list I hand that to doEval().
doEval() returns a value (an "any" pointer, which when cast to a long is 6
which seems odd).
I then try to doPrint() on that value, where it seg faults.
any rv = doRead(Nil);
printf("read ok\n doPrint(rv):\n");
doPrint( rv );
printf("\n\n");
any ev = doEval( rv );
printf("eval ok, = %ld\n", (long)ev);
Env.get = getSave;
1 get: '('
2 get: '+'
3 get: ' '
4 get: '1'
5 get: ' '
6 get: '2'
7 get: ')'
8 get: '
'
read ok
doPrint(rv):
1 2
eval ok, = 6
...
Segmentation fault
But closer! :-)
Cheers,
Doug
--- On Tue, 6/21/11, Doug Snead <[email protected]> wrote:
> From: Doug Snead <[email protected]>
> Subject: Re: embedding minipicolisp
> To: [email protected]
> Date: Tuesday, June 21, 2011, 11:33 AM
> --- On Tue, 6/21/11, Alexander Burger
> <[email protected]>
> wrote:
> > Yes, the Apply* lines are needed (or what does the
> "??"
> > imply?).
>
> I wasn't sure if I needed that for my initialisation - you
> answered my question there.
>
> > I see one remaining problem: The 'ErrRst' global, the
> error
> > restart jump
> > buffer, is not initialized. This may cause a crash if
> a
> > runtime error
> > occurs. So I would include something like
> > if (setjmp(ErrRst))
> > error_Message_or_exit()
>
> Ah ha! That explains the crash that happens when it gets
> errors :-)
>
> > > return load(NULL, 0, mkStr(str));
> > Doesn't this have the disadvantage that 'str' must
> always
> > begin with a minus sign?
>
> Yes it does have that issue. What I want
> is to get similar eval/print behavior that we get from:
>
> while (!feof(stdin))
> load(NULL, ':', Nil);
>
> in main(), except I'd like to be able to hand it a
> s-expression in a string like "(+ 1 1)" for evaluation,
> leaving the I/O unaffected.
>
> I was hoping I could do this leaving Env.get/.put
> untouched.
>
> But due to the character-oriented way LISPs most often
> parse things, it is looking now like I really will indeed
> need to make Env.get (at least) read from a character
> buffer (And then doEval(doRead()) in place of the
> load() I am using now.)
>
> My goal is to be able to easily embed (mini)picolisp (and
> pilog) in C/C++ projects like people now embed lua in
> applications when they want to add scripting.
> :-)
>
> > Regarding the question of cleanup: I would write a
> function
> > void miniPicoLisp_stop(void)
> > which is identical to bye(), except for the exit() at
> the end.
>
> Thanks for the guidance!!
>
> Cheers,
>
> Doug
>
> --
> UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe
>
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe