Compiler.eval() and Frobtads (Linux)

In my quest for barebones debug capability, I basically recreated the elegant work of this old post for a peek/poke capability. I spent an inordinate amount of time fighting a core dump under Frobtads (my main development engine), only to discover it works just fine under QTads.

Anyone successfully used DynFunc with Frobtads, and if so, was there any magic required? Given @RealNC presence in that initial thread, it feels like I’m on my own here.

FTR, here is my code:

#include <dynfunc.h>

#define v2s(Val) reflectionServices.valToSymbol(##Val)

DefineLiteralAction(Peek) 
    execAction() {
        "DEBUG:  <<gLiteral>> = <<v2s(Compiler.eval(gLiteral))>>\n";
    }
    /* this is a meta-command, so don't consume any time */
    actionTime = 0
;
VerbRule(Peek)
	('peek' | 'dx') singleLiteral  : PeekAction
	verbPhrase = 'peek/peeking (into what)'
;

And here is my very odd command line coreDump (note extreme leading spaces, actually wrapping on my screen):

>dx 'me.name'
                                                           S
egmentation fault (core dumped)

Less urgently, is there a way to override TADS’ period parsing? Just more friction than I want enclosing TADS properties/methods in quotes on the command line. I want this:

>peek me.location.name

but TADS requires this:

>peek 'me.location.name'
1 Like

So you’re saying your debug-print function works in QTads but not in FrobTADS? I’ll try to look at that later…
As for the quote marks, my function allows this (no final quote needed)…

>dp"me.location.name

but I believe Adv3Lite’s eval function does not require quotes so maybe you could check out how that was implemented…

1 Like

My debug-print/eval function works in FrobTADS as well. Do you want to compare the code?

1 Like

Adv3Lite uses a preparser. If the command line begins with "eval " (in Lite’s case), quotes will be spliced in if they’re not present.

1 Like

I don’t know if it causes an error or not, but I don’t think you need the token-pasting operator in your v2s #define. You should be able to just write valToSymbol(Val).

1 Like

Here’s how I implemented it… I don’t know if this will act differently or not.

   /* this dp can be dropped anywhere in code for debug
    * output in addition to powering the dynamic function
    */
#define dp(val) { \
   local str = '\n'## #@val ## ' = <<reflectionServices.valToSymbol(val)>> \n'; \
   if(gTranscript) \
      extraReport(str); \
   else say(str); }

/* action for your Eval/DebugPrint verb */

execAction() {
   Compiler.compile('function() { dp(' + gLiteral + '); }')();
}
1 Like

Ok, I am at a loss to explain WHY, but your solution worked in Frobtads where my original did not! Thanks so much! (Yes, my original worked in QTADS but not Frobtads)

Also, I can’t believe I forgot my good friend StringPreProcessor - I Iet myself get swayed by ‘holistic solutions’! :stuck_out_tongue_winking_eye:

1 Like

Yay! I don’t know why either.

JJMcC, if your need is monitoring a variable/flag, why not look into my “scroll of knowledge” ? IIRC you have seen a deployed one… :wink: IIRC, I have posted somewhere here its source, which seems to me good for both adv3 and adv3Lite (needing only changing the name from adv3Lite format to the adv3 format, I guess)

Best regards from Italy,
dott. Piergiorgio.

1 Like

UPDATE: @RealNC Based on some extensive experimentation I have concluded that it only (and always, at least for my experiments) fails Frobtads and not QTADS when I use Compiler.eval(<somecode>). Compiler.compile(<somecode>)() consistently works in both.

In deference to Frobtads, I will personally depricate the use of Compiler.eval

Does it work in Parchment?

I don’t know that this is the same issue, but Frobtads doesn’t have this big fix: CTcParser's local_symbtab_ wasn't being set in all types of dynamic compilation by curiousdannii · Pull Request #26 · tads-intfic/tads-runner · GitHub

2 Likes

Just checked it in parchment - works fine. Still only fails under Frobtads. Thanks for the inside info!

2 Likes