4.23. kink/TRACE¶
The companion mod for trace vals.
4.23.1. type trace¶
A trace val is an element of a stack trace.
A trace val consists of the following components.
• sym: a str val; usually the sym of the called fun.
• location: a location val; usually the location where the invocation occurred.
• tail?: whether the trace is on the tail.
4.23.1.1. Trace.snip?¶
`snip?` returns whether the `Trace` is a SNIP trace, whose sym and location are empty, and it is of a tail trace.
4.23.1.2. Trace.sym¶
`sym` returns the sym of the `Trace`.
4.23.1.3. Trace.location¶
`location` returns the location of the `Trace`.
4.23.1.4. Trace.tail?¶
`tail?` returns whether the `Trace` is of a tail-call.
4.23.1.5. Trace.on_tail¶
`on_tail` returns a trace with the same sym and the location with `Trace`, and on the tail.
4.23.1.6. Trace1.op_eq(Trace2)¶
`op_eq` returns whether the two traces are equal.
Two traces are equal when and only when sym, location, and tai? properties are equal.
4.23.1.7. Trace.desc¶
`desc` returns a str which describes the `Trace`.
Example:
:LOCATION.require_from('kink/')
:TRACE.require_from('kink/')
:Loc <- LOCATION.new('foo.kn' 'foo(bar)' 4)
stdout.print_line(TRACE.new('bar' Loc).desc.repr)
# => "[foo.kn L1 C5 bar] foo(-->bar)"
stdout.print_line(TRACE.new('bar' LOCATION.empty).desc.repr)
# => "[bar]"
stdout.print_line(TRACE.new('bar' LOCATION.empty).on_tail.desc.repr)
# => "{bar}"
stdout.print_line(TRACE.new('' Loc).desc.repr)
# => "[foo.kn L1 C5] foo(-->bar)"
stdout.print_line(TRACE.new('' Loc).on_tail.desc.repr)
# => "{foo.kn L1 C5} foo(-->bar)"
stdout.print_line(TRACE.snip.desc.repr)
# => "{..snip..}"
stdout.print_line(TRACE.new('' LOCATION.empty).desc.repr)
# => "[..empty..]"
If the `Trace` is of a tail call, the first part is enclosed by "{...}". If the `Trace` is not of a tail call, the first part is enclosed by "[...]".
4.23.2. TRACE.is?(Val)¶
`is?` returns whether the `Val` is a trace val.
4.23.3. TRACE.snip¶
`snip` returns the snip trace, which is equal to `TRACE.new{(:C) C.on_tail }`.
4.23.4. TRACE.new(Sym Loc)¶
`new` makes a trace not on the trace.
Preconditions:
• `Sym` must be str
• `Location` must be location
Example:
:TRACE.require_from('kink/')
:LOCATION.require_from('kink/')
:Trace <- TRACE.new('op_add' LOCATION.new('foo.kn' '10+20' 2))
stdout.print_line(Trace.repr) # => (trace sym=op_add (location foo.kn L1 C3) tail?=false)
4.23.5. TRACE.current_traces¶
`current_traces` returns a vec of traces of the stack of the abstract stack machine, from the bottom to the top.
At the tail of `current_traces`, the following sequence off abstract instructions is evaluated:
(traces)