diff --git a/urn/analysis/warning/init.lisp b/urn/analysis/warning/init.lisp index df9ef72..b02e912 100644 --- a/urn/analysis/warning/init.lisp +++ b/urn/analysis/warning/init.lisp @@ -7,8 +7,6 @@ (import urn/range (get-source)) (import urn/resolve/scope scope) -(import lua/table table) - (import urn/analysis/warning/order warning) (defpass check-arity (state nodes lookup) @@ -110,14 +108,15 @@ (and (/= (.> var :tag) "macro") (not (.> var :scope :exported (.> var :name))))) (push-cdr! unused (list var def)))))) - (table/sort unused (lambda (node1 node2) - (let [(source1 (get-source (cadr node1))) - (source2 (get-source (cadr node2)))] - (if (= (.> source1 :name) (.> source2 :name)) - (if (= (.> source1 :start :line) (.> source2 :start :line)) - (< (.> source1 :start :column) (.> source2 :start :column)) - (< (.> source1 :start :line) (.> source2 :start :line))) - (< (.> source1 :name) (.> source2 :name)) )))) + (sort! unused (lambda (node1 node2) + (let [(source1 (get-source (cadr node1))) + (source2 (get-source (cadr node2)))] + (if (= (.> source1 :name) (.> source2 :name)) + (if (= (.> source1 :start :line) (.> source2 :start :line)) + (< (.> source1 :start :column) (.> source2 :start :column)) + (< (.> source1 :start :line) (.> source2 :start :line))) + (< (.> source1 :name) (.> source2 :name)) )))) + (for-each pair unused (logger/put-node-warning! (.> state :logger) (string/format "%s is not used." (string/quoted (.> (car pair) :name))) diff --git a/urn/backend/lua/init.lisp b/urn/backend/lua/init.lisp index 64a72e9..418f1c8 100644 --- a/urn/backend/lua/init.lisp +++ b/urn/backend/lua/init.lisp @@ -8,8 +8,6 @@ (import extra/assert (assert!)) (import lua/basic (load)) -(import lua/debug debug) -(import lua/table table) (defun create-state (meta) { ;; [[run-pass]] options @@ -98,7 +96,7 @@ (let* [(var (.> x :var)) (count (.> counts var))] (when count (. (.> counts x) (.> counts y)))) + (sort! vars (lambda (x y) (> (.> counts x) (.> counts y)))) (w/append! out "local ") (for i 1 100 1 @@ -176,7 +174,7 @@ (push-cdr! buffer (string/format format i (nth lines i)))) (fail! (.. msg ":\n" (concat buffer "\n"))))] [(?fun) - (case (list (xpcall fun debug/traceback)) + (case (list (xpcall fun traceback/traceback)) [(false ?msg) (fail! (traceback/remap-traceback (.> back-state :mappings) msg))] [(true ?tbl) diff --git a/urn/backend/markdown.lisp b/urn/backend/markdown.lisp index d971d41..ac1b144 100644 --- a/urn/backend/markdown.lisp +++ b/urn/backend/markdown.lisp @@ -4,8 +4,6 @@ (import urn/resolve/scope scope) (import urn/resolve/builtins (builtins)) -(import lua/table table) - (defun format-range (range) "Format a range." :hidden @@ -14,8 +12,7 @@ (defun sort-vars! (list) "Sort a list of variables" :hidden - (table/sort list (lambda (a b) - (< (car a) (car b))))) + (sort! list (lambda (a b) (< (car a) (car b))))) (defun format-definition (var) "Format a variable VAR, including it's kind and the position it was defined at." diff --git a/urn/plugins.lisp b/urn/plugins.lisp index bf26241..1a8170a 100644 --- a/urn/plugins.lisp +++ b/urn/plugins.lisp @@ -67,7 +67,7 @@ (with (func (.> pass :run)) (. compiler :compile-state :mappings) msg))] [(true . ?rest) (unpack rest 1 (n rest))])))) diff --git a/urn/resolve/loop.lisp b/urn/resolve/loop.lisp index 60656f9..788a3f9 100644 --- a/urn/resolve/loop.lisp +++ b/urn/resolve/loop.lisp @@ -1,7 +1,6 @@ (import lua/coroutine co) (import lua/debug debug) (import extra/term term) -(import lua/table table) (import urn/backend/lua backend) (import urn/logger logger) @@ -309,8 +308,8 @@ (set! scope (.> scope :parent))) - (table/sort vars) - (table/sort var-dis (lambda (a b) (< (.> distances a) (.> distances b)))) + (sort! vars) + (sort! var-dis (lambda (a b) (< (.> distances a) (.> distances b)))) (with (elems (-> var-dis (filter (lambda (x) (<= (.> distances x) 0.5)) <>) diff --git a/urn/resolve/walk.lisp b/urn/resolve/walk.lisp index 0985b2c..df9e79b 100644 --- a/urn/resolve/walk.lisp +++ b/urn/resolve/walk.lisp @@ -7,14 +7,13 @@ (import lua/basic (type#)) (import lua/coroutine co) -(import lua/debug debug) (import urn/logger logger) (import urn/range range) (import urn/resolve/builtins (builtins)) (import urn/resolve/scope scope) (import urn/resolve/state state) -(import urn/traceback (remap-traceback)) +(import urn/traceback traceback) (defun error-positions! (log node message) "Fail resolution at NODE with the given MESSAGE." @@ -285,9 +284,9 @@ (. state :logger) node (remap-traceback (.> state :mappings) msg))] + (error-positions! (.> state :logger) node (traceback/remap-traceback (.> state :mappings) msg))] [(true . ?replacement) (cond [(= i (n node)) @@ -334,9 +333,9 @@ (. state :logger) node (remap-traceback (.> state :mappings) msg))] + (error-positions! (.> state :logger) node (traceback/remap-traceback (.> state :mappings) msg))] [(true . ?replacement) (with (result (car replacement)) (unless (list? result) @@ -477,10 +476,10 @@ (. state :logger) first (remap-traceback (.> state :mappings) msg))] + (error-positions! (.> state :logger) first (traceback/remap-traceback (.> state :mappings) msg))] ;; The macro worked, we'll gather the output and continue. [(true . ?replacement) diff --git a/urn/tools/gen-native.lisp b/urn/tools/gen-native.lisp index cecc913..490f8d9 100644 --- a/urn/tools/gen-native.lisp +++ b/urn/tools/gen-native.lisp @@ -1,7 +1,6 @@ (import extra/argparse arg) (import lua/io io) (import lua/math math) -(import lua/table table) (import string (quoted)) (import urn/logger logger) @@ -35,7 +34,7 @@ (set! max-quot (math/max max-quot (n (quoted (dot-quote prefix name))))) (set! max-pref (math/max max-pref (n (dot-quote escaped name))))))) - (table/sort natives) + (sort! natives) (let* [(handle (io/open (.. (.> lib :path) ".meta.lua") "w")) (format (.. diff --git a/urn/tools/repl.lisp b/urn/tools/repl.lisp index efc697d..5bc6291 100644 --- a/urn/tools/repl.lisp +++ b/urn/tools/repl.lisp @@ -5,7 +5,6 @@ (import lua/debug debug) (import lua/io io) (import lua/os os) -(import lua/table table) (import urn/backend/lua lua) (import urn/backend/writer writer) @@ -259,7 +258,7 @@ (. scope :parent))) - (table/sort vars) + (sort! vars) vars) '()))] ;; EOF errors within the lexer only occur in strings, thus we do not need to complete them. @@ -396,7 +395,7 @@ (print! (coloured 92 "Exported symbols")) (with (vars '()) (for-pairs (name) (.> mod :scope :exported) (push-cdr! vars name)) - (table/sort vars) + (sort! vars) (print! (concat vars " ")))])) (logger/put-error! logger ":module ")))] @@ -456,7 +455,7 @@ (. current :parent))) - (table/sort vars) + (sort! vars) (print! (concat vars " ")))] diff --git a/urn/tools/run.lisp b/urn/tools/run.lisp index a1f2484..5de5d43 100644 --- a/urn/tools/run.lisp +++ b/urn/tools/run.lisp @@ -3,7 +3,6 @@ (import lua/basic b) (import lua/debug debug) (import lua/os os) -(import lua/table table) (import urn/analysis/nodes (builtins builtin?)) (import urn/analysis/visitor visitor) @@ -70,7 +69,7 @@ (debug/sethook) (with (out (values stats)) - (table/sort out (lambda (a b) (> (.> a :inner-time) (.> b :inner-time)))) + (sort! out (lambda (a b) (> (.> a :inner-time) (.> b :inner-time)))) (print! (string/format "| %20s | %-60s | %8s | %8s | %7s |" "Method" @@ -177,7 +176,7 @@ (when (table? child) (push-cdr! children child))) - (table/sort children (lambda (a b) (> (.> a :n) (.> b :n)))) + (sort! children (lambda (a b) (> (.> a :n) (.> b :n)))) (. output name)) @@ -510,7 +509,7 @@ (. args :script-args)) (. args :input))) (with (exec (lambda () - (case (list (xpcall (cut apply fun (.> args :script-args)) debug/traceback)) + (case (list (xpcall (cut apply fun (.> args :script-args)) traceback/traceback)) [(true . _)] [(false ?msg) (logger/put-error! logger "Execution failed.") diff --git a/urn/traceback.lisp b/urn/traceback.lisp index a59b4c0..2aa2ffe 100644 --- a/urn/traceback.lisp +++ b/urn/traceback.lisp @@ -1,3 +1,10 @@ +(import lua/debug debug) + +(defun traceback (msg) + "An alternative for [[debug/traceback]] which correctly remaps the error." + (unless (string? msg) (set! msg (pretty msg))) + (debug/traceback msg 2)) + (defun unmangle-ident (ident) "Attempt to unmangle IDENT, converting it from the escaped form to the unescaped form." (with (esc (string/match ident "^(.-)%d+$"))