4.22. kink/TRACE

The companion mod for trace vals.

4.22.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. Trace.snip?

`snip?` returns whether the `Trace` is a SNIP trace, whose sym and location are empty, and it is of a tail trace. Trace.sym

`sym` returns the sym of the `Trace`. Trace.location

`location` returns the location of the `Trace`. Trace.tail?

`tail?` returns whether the `Trace` is of a tail-call. Trace.on_tail

`on_tail` returns a trace with the same sym and the location with `Trace`, and on the tail. 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. Trace.desc

`desc` returns a str which describes the `Trace`.



: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)"

# => "{..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.22.2. TRACE.is?(Val)

`is?` returns whether the `Val` is a trace val.

4.22.3. TRACE.snip

`snip` returns the snip trace, which is equal to `TRACE.new{(:C) C.on_tail }`.

4.22.4. TRACE.new(Sym Loc)

`new` makes a trace not on the trace.


• `Sym` must be str

• `Location` must be location


: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.22.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: