Wiki

Ticket #52 (assigned enhancement)

Opened 9 years ago

Last modified 8 years ago

Provide a compile-time form that emits an expression's source and value

Reported by: Chuck Owned by: Chuck
Priority: medium Milestone: Cobra 0.9
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

...without location/trace information.

This ticket was broken out from ticket:32

See discussion at  Tracing new expression and suppression

Attachments

percent-internal-macro.patch Download (9.2 KB) - added by hopscc 9 years ago.
dts-as-expr.patch Download (4.8 KB) - added by hopscc 9 years ago.

Change History

Changed 9 years ago by Chuck

Regarding the syntax, as discussed in the forums:

Syntax:

  • It's difficult, or even impossible, to use : at the beginning or ending of an expression syntax because : is already used in slicing which delimits expressions with :
  • Likewise, I think %foo(arg) is ambiguous with the % arithmetic operator
  • I was hoping to reserve $ for future language level regex support, like $1 or $name would refer to a regex matching var.
  • There are other needs for compile-time phenomena like C#'s default(T) so we should come up with a general form. And if we make it syntactically distinct, then we can add more compile-time functions in the future without breaking code.
  • Perhaps @foo(args)? Or foo$(args) as mentioned in hopscc post

Naming:

  • The name for this thing should probably not be trace because the very word implies knowing something about the source of what's being traced (file:line).
  • I'm thinking expr or watch. I got the idea for watch from IDEs which let you add "watches". Maybe that's misleading because it doesn't get updated.

Changed 9 years ago by Chuck

Naming:

  • Another idea is @debug(foo) since this is used for debugging and it shows source code which is only relevant for debugging.

Changed 9 years ago by hopscc

Changed 9 years ago by hopscc

  • status changed from new to assigned
  • owner set to Chuck

patch for the expression-expansion-to-string capability.
Its implemented as a generic macro facility taking '@' as the leading character (thought that was the best choice of the suggested options) for a named macro expansion driven from an internal table of macro names and text expansions.
It should be relatively simple to provide capability to augment the macro table with programmer generated macros on this structure if desired. Theres some (commented) possible examples in the test file

I used @debug in both the macro table and tests but I dont think its a particularly
good choice as it doesnt 'debug' anything - just generates a string representation of the provided expression.

Theres an alternative in the internal table %dts (descriptive-tech-string) which does the same expansion -short and sweet.
And also perhaps another useful shortcut: %toTS expanding to CobraCore.toTechString.

Note that this capability is deficient wrt the original patch on the ticket that this ticket was broken out from in that it would be used from a print statement

print %debug(aVar)
# instead of
# trace print aVar

( since if its used in a trace you will get the sourceline info plus duplicated text)
In which case these statements have to be manually removed/commented/disabled as
they arent suppressed from the commandline with the trace suppression option which was part of the original point of doing this....
suppressible emitting of just variable value info.....

Changed 9 years ago by Chuck

  • I'm currently thinking @show(exp)
  • There's already a .toTechString extension on Object so you don't have to bother going through CobraCore.
  • I haven't made a decision regarding "trace print ..." / "print trace ...", but since you are still interested in that, I suggest a new ticket to track it.

Changed 9 years ago by hopscc

@show - hmm same objection as @debug - doesnt really show anything it just makes a
string expression out of it... however bearable I guess

Have Just put up ticket:57 and a patch for what was 'trace print' - same idea implemented slightly differently (dirtier: string literal switches as args to trace statement).

The CobraCore.toTechString macro was just an idea for implementing short cut syntax for common lengthy syntax sequences (%CC for CobraCore for example). Probably more useful if/when allow developers to install their own macros.

I've got an implementation of @debug/@dts/@show as an Expr (dTs).
Makes it look like a function call except its not defined in user code anywhere

form is either as an expression or a template with an expression to be fitted into it

 x=10
 v= dTs(x+1) # v gets string 'x+1=11'
 print dTs(r'[expr.str] has toString value [expr] TechString [expr.tts]', x)
# prints x has toString value 10 TechString '10'

I'll add the patch here for examination.

Changed 9 years ago by hopscc

Changed 9 years ago by hopscc

Sample patch and example of use as a test file..
Recognition is hacked into CobraParser? directly - should be done properly in Tokeniser but its as far as I got noodling between multi-arg assign patches.

Did this cos I didnt think it was going to be possible to get this handled properly without some form of token stream fiddling (as in earlier patch) but turned out I could, with some runtime assistance which I hadnt thought of before...
You might find this approach (suitably tweaked re naming) is a better way of going about it....

(also thinking about this and looking at some annotated code I think the non special character leadin (dTs/debug/show vs @dTs/@debug/@show) is (cleaner looking and ) easier to scan/read in code - not make such a strong visual difference with
other calls)

Changed 9 years ago by Chuck

  • type changed from defect to enhancement

Changed 9 years ago by Chuck

  • milestone set to Cobra 0.9

Changed 8 years ago by hopscc

touch to lift into recent 50

Changed 8 years ago by hopscc

Touch to raise into last 50

Note: See TracTickets for help on using tickets.