Re: Thoughts on eval()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jason Gade wrote:
> 
> Jason Gade wrote:
> > 
> > Matt Lewis wrote:
> > > If you examine how the interpreter does things, there's really no
> > > difference
> > > between 'Code' space and variable space.  SubPrograms (including one for
> > > TopLevel) contain a code section.  The CurrentSub is constantly changed,
> > > so that the interpreter executes code from different places all the time.
> > 
> > Okay.  I didn't quite get that far.  From what I could see is that all the
> > parsed IL
> > code went into the Code[] sequence.  Names of functions in SymTab[][] had a
> > field that
> > pointed to the proper place in the Code[] sequence.  I still don't have a
> > full understanding
> > of it, though.
> 
> Okay, I see now that code for subprograms is stored in SymTab[x][S_CODE]
> right?
> 
> So what I'm saying is that func() or proc() would add an entry to SymTab with
> the proper
> code and return a routine id that could be used to call it.  I haven't checked
> out
> the routine_id code yet.
> 
> I think you are saying that eval() would execute in place as if the statements
> were
> in the top level?

Basically.  Except that any procedure definitions would add a SubProgram
entry into SymTab which would be callable via another eval statement.
Routine_id might or might not work on these routines--I suspect that they
won't, unless inside another eval statement, or if the original eval was
done at the toplevel, simply because they'll have been defined 'later' 
in the source.

So you could do something like:
ok = eval( "procedure foo()\nputs(1,\"foo!\,\")\nend procedure" )
ok = eval( "foo()" )
ok = eval( "rid = routine_id(\"foo\")" )
call_proc( rid, {})


Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu