
header "sys" as sys

~ global error_code : u32
~ global error_msg : String ("")
- global error_trace_index : uint
- global error_trace : [String x 100]

global cli_args : Array[String] (@undefined)

+ fn exit(code: i32) $exit {
    sys:exit(code.@cast(i32))
}

+ fn panic(msg: String) $exit {
    println(msg)
    exit(1)
}

+ fn raise(code: i32) $exit {
    sys:raise(code.@cast(i32))
}

+fn get_error_trace() Array[String] {
    let arr = Array[String]{}
    let i = error_trace_index
    while true {
        let msg = error_trace[i]
        arr.append(msg)
        if i == 0 : break
        i--
    }
    return arr
}

+fn print_error_trace() {
    println("------------- ERROR TRACE -------------")
    let i = error_trace_index
    while true {
        let msg = error_trace[i]
        println(msg)
        if i == 0 : break
        i--
    }
    println("-------------- END TRACE --------------")
}