Invoking sclang methods from primitives?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Invoking sclang methods from primitives?

jamshark70-2
Bringing a few questions to the mailing list, to avoid polluting a PR discussion at github.

I'm trying to modify the Event:delta primitive (prEvent_Delta in PyrListPrim.cpp) to "dereference" Rest objects -- that is, currently, "(dur: Rest(1)).delta" throws a wrong type error, but I want it to ".value" the dur object -- desired behavior: "(dur: Rest(1)).delta" --> 1.

As a kind of proof of concept:

                SetSymbol(&key, s_dur);
                identDict_lookup(slotRawObject(a), &key, calcHash(&key), &dur);

                err = slotDoubleVal(&dur, &fdur);
                if (err) {
                  if (NotNil(&dur)) {
                    ++g->sp; SetObject(g->sp, slotRawObject(&dur));
                    runInterpreter(g, s_value, 1);
                    err = slotDoubleVal(g->sp, &fdur);
                    if (err) return err;
                  } else {
                        SetNil(g->sp);
                        return errNone;
                  }
                }

That is: In other places in the code, we can push items onto the stack ("++g->sp; SetObject(g->sp, ...)") and call a method by runInterpreter(g, selector, numArgsPushed). I *think* that's what I've done here... pushed the single raw "dur" object and called "value" with a single argument (the receiver). But it's crashing in runInterpreter (call stack from debug build below).

Question: Is it even valid to use runInterpreter within a primitive that is being invoked from within the interpreter? (runInterpreter appears in C++ functions that are called by external actions like MIDI, HID or OSC, but I haven't found a use in a primitive.)

Question: If it's not valid, is there any way to invoke a method from within a primitive? Or, is it rather that once you enter a primitive, then the primitive has to do everything and there's no way to get back to the class library without returning from the primitive?

I have a feeling that what I thought to do is just not permitted, but I haven't found clear documentation on that. (Even Stefan Kersten's otherwise enlightening sclang chapter in The Book gives up at this point and refers the reader to examples in the source code!) If it's not valid, I guess I would have to check specifically for the Rest class and access its member variable directly.

Thanks in advance,
hjh

#0  0x00000000004eb9fd in IsInt (slot=0xf8)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/PyrSlot64.h:97
#1  0x00000000004fdc94 in slotRawInt (slot=0xf8)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/PyrSlot64.h:274
#2  0x00000000005780cc in Interpret (g=0xae1f40 <gVMGlobals>)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/PyrInterpreter3.cpp:2492
#3  0x0000000000567a8c in runInterpreter (g=0xae1f40 <gVMGlobals>,
    selector=0xca82c8, numArgsPushed=1)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/PyrInterpreter3.cpp:127
#4  0x000000000057ee1a in runLibrary (selector=0xca82c8)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/PyrLexer.cpp:2188
#5  0x00000000005d7076 in SC_LanguageClient::runLibrary (this=0xc47800,
    symbol=0xca82c8)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/SC_LanguageClient.cpp:198
#6  0x00000000004e4a7c in SC_TerminalClient::interpretCmdLine (this=0xc47800,
    cmdLine=0xc31f50 "(dur: Rest(1)).delta;\f", size=21, silent=false)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/SC_TerminalClient.cpp:317
#7  0x00000000004e4b43 in SC_TerminalClient::interpretInput (this=0xc47800)
    at /home/dlm/share/sc-hjh.git/lang/LangSource/SC_TerminalClient.cpp:333
... piles of Qt and boost stack frames omitted for brevity


_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/
Reply | Threaded
Open this post in threaded view
|

Re: Invoking sclang methods from primitives?

Tim Blechmann-2
> That is: In other places in the code, we can push items onto the
> stack ("++g->sp; SetObject(g->sp, ...)") and call a method by
> runInterpreter(g, selector, numArgsPushed). I *think* that's what
> I've done here... pushed the single raw "dur" object and called
> "value" with a single argument (the receiver). But it's crashing in
> runInterpreter (call stack from debug build below).

you are in uncharted territory. conceptually `runInterpreter` can
probably be made reentrant, but it would surprise me, if it currently is
the case (the use of setjmp/longjmp certainly isn't)



_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/
Reply | Threaded
Open this post in threaded view
|

Re: Invoking sclang methods from primitives?

jamshark70-2
On March 16, 2017 13:02:55 Tim Blechmann <[hidden email]> wrote:

> you are in uncharted territory. conceptually `runInterpreter` can
> probably be made reentrant, but it would surprise me, if it currently is
> the case (the use of setjmp/longjmp certainly isn't)

Thanks, the combination of "not an established practice" + "it crashes" +
solid technical reason why it's likely to crash is enough for me to abandon
that approach.

hjh

Sent with AquaMail for Android
http://www.aqua-mail.com




_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/