6.24. kink/TRACE

6.24.1. type trace

`trace` is an element of a stack trace.

A `trace` consists of the attributes.

• Sym: a `str` of the sym of the called fun.

• Location: a `location` where the invocation occurred.

• Tail?: a `bool` whether the trace is of a tail-call.

6.24.1.1. Trace.sym

`sym` returns `Sym` of `Trace`.

6.24.1.2. Trace.location

`location` returns `Location` of `Trace`.

6.24.1.3. Trace.tail?

`tail?` returns `Tail?` of `Trace`.

6.24.1.4. Trace.desc

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

If `Tail?` attribute is true, the first part of the result is enclosed by braces like "{...}".

If `Tail?` attribute is false, the first part of the result is enclosed by brackets like "[...]".

Example

:TRACE.require_from('kink/')
:LOCATION.require_from('kink/program/')
:PROGRAM.require_from('kink/program/')

:Loc <- LOCATION.new(PROGRAM.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){(:C) C.tail }.desc.repr)
# => "{bar}"

stdout.print_line(TRACE.new('' Loc).desc.repr)
# => "[foo.kn L1 C5] foo(-->bar)"

stdout.print_line(TRACE.new('' Loc){(:C) C.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..]"

6.24.1.5. Trace1 == Trace2

`==` operator, or `op_eq` method, returns whether `Trace1` and `Trace2` have the equal attributes.

Precondition

`Trace2` must be a `trace`.

6.24.2. TRACE.new(Sym Location ...[$config={}])

`new` returns a new `trace`.

Config method:

• C.tail

The result `trace` will have `Sym` and `Location` as the attributes of the same names. If C.tail is called, `Tail?` attribute will be true. If C.tail is not called, `Tail?` attribute will be false.

Preconditions

`Sym` must be a `str`.

`Location` must be a `location`.

Example

:TRACE.require_from('kink/')
:LOCATION.require_from('kink/program/')
:PROGRAM.require_from('kink/program/')

:T1 <- TRACE.new('op_add' LOCATION.new(PROGRAM.new('foo.kn' '10+20') 2))
stdout.print_line(T1.repr) # => (trace sym=op_add (location foo.kn L1 C3) tail?=false)

:T2 <- TRACE.new('bar' LOCATION.new(PROGRAM.new('bar.kn' 'bar(X)') 0)){(:C) C.tail }
stdout.print_line(T2.repr) # => (trace sym=bar (location bar.kn L1 C1) tail?=true)

6.24.3. TRACE.is?(Val)

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

6.24.4. TRACE.snip

`snip` returns a `trace` with Sym="", Location=LOCATION.empty, Tail?=true.

This `trace` value is used to replace snipped traces of tail-calls.

6.24.5. TRACE.current_traces

`current_traces` returns a `vec` of `trace` values of the stack of the abstract stack machine, from the bottom to the top.

At the tail of `current_traces`, the following sequence of abstract instructions is evaluated:

(traces)