3.22. kink/TRACE

The companion mod for trace vals.

3.22.1. type trace

A trace val is an element of a stack trace.

A trace val consists of the following components. Both are optional.

• sym: a str val; usually the sym of the called fun.

• loc: a loc val; usually the loc where the invocation occurred.

Trace.snip?

`snip?` returns whether the `Trace` is a SNIP trace, which does not have a sym nor a loc, and it is of a tail trace.

Trace.have_sym?

`have_sym?` returns whether the `Trace` has a sym.

Trace.sym

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

Precondition:

• `Trace` must have a sym

Trace.have_loc?

`have_loc?` returns whether the `Trace` has a loc.

Trace.loc

`loc` returns the loc of the `Trace`.

Precondition:

• `Trace` must have a loc.

Trace.tail?

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

Trace1.op_eq(Trace2)

`op_eq` returns whether the two traces are equal.

Two traces are equal when and only when the following calculated properties of the traces are equal.

• `if(T.have_sym? { [T.sym] } { []})`

• `if(T.have_loc? { [T.loc] } { []})`

• `T.tail?`

Trace.desc

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

Example:

:LOC.require_from('kink/')
:TRACE.require_from('kink/')

:Loc <- LOC.new('foo.kn' 'foo(bar)' 4)

stdout.print_line(TRACE.new{(:T) T.sym('bar') T.loc(Loc) }.desc.repr)
# => "[foo.kn L1 C5 bar] foo(-->bar)"

stdout.print_line(TRACE.new{(:T) T.sym('bar') }.desc.repr)
# => "[bar]"

stdout.print_line(TRACE.new{(:T) T.sym('bar') T.on_tail }.desc.repr)
# => "{bar}"

stdout.print_line(TRACE.new{(:T) T.loc(Loc) }.desc.repr)
# => "[foo.kn L1 C5] foo(-->bar)"

stdout.print_line(TRACE.snip.desc.repr)
# => "{..snip..}"

stdout.print_line(TRACE.new{}.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 "[...]".

3.22.2. TRACE.is?(Val)

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

3.22.3. TRACE.snip

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

3.22.4. TRACE.new(...[$config = {}])

`new` makes a trace.

$config is called with a `Conf`, to configure the trace.

The `Conf` has two methods.

• Conf.sym(Sym) : gives the sym of the trace.

• Conf.loc(Loc) : gives the loc of the trace.

• Conf.on_tail : the trace is of a tail-call.

Example:

:TRACE.require_from('kink/')
:LOC.require_from('kink/')
:Trace <- TRACE.new{(:T)
  T.sym('op_add')
  T.loc(LOC.new('foo.kn' '10+20' 2))
}
stdout.print_line(Trace.repr) # => (trace op_add (loc foo.kn L1 C3) tail?=false)