Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
A couple of minor fixes to the REPL
Browse files Browse the repository at this point in the history
 - table/sort -> sort!
 - debug/traceback -> urn/traceback/traceback
  • Loading branch information
SquidDev committed Aug 27, 2017
1 parent 9bc39b2 commit 4e50b2a
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 41 deletions.
19 changes: 9 additions & 10 deletions urn/analysis/warning/init.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down
6 changes: 2 additions & 4 deletions urn/backend/lua/init.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,7 +96,7 @@
(let* [(var (.> x :var))
(count (.> counts var))]
(when count (.<! counts var (succ count)))))))
(table/sort vars (lambda (x y) (> (.> counts x) (.> counts y))))
(sort! vars (lambda (x y) (> (.> counts x) (.> counts y))))

(w/append! out "local ")
(for i 1 100 1
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions urn/backend/markdown.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion urn/plugins.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
(with (func (.> pass :run))
(.<! pass :run
(lambda (&args)
(case (list (xpcall (lambda () (apply func args)) debug/traceback))
(case (list (xpcall (lambda () (apply func args)) traceback/traceback))
[(false ?msg) (fail! (traceback/remap-traceback (.> compiler :compile-state :mappings) msg))]
[(true . ?rest) (unpack rest 1 (n rest))]))))

Expand Down
5 changes: 2 additions & 3 deletions urn/resolve/loop.lisp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)) <>)
Expand Down
15 changes: 7 additions & 8 deletions urn/resolve/walk.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -285,9 +284,9 @@
(.<! state :compiler :active-scope scope)
(.<! state :compiler :active-node built)

(case (list (xpcall func debug/traceback))
(case (list (xpcall func traceback/traceback))
[(false ?msg)
(error-positions! (.> 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))
Expand Down Expand Up @@ -334,9 +333,9 @@
(.<! state :compiler :active-scope scope)
(.<! state :compiler :active-node built)

(case (list (xpcall func debug/traceback))
(case (list (xpcall func traceback/traceback))
[(false ?msg)
(error-positions! (.> 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)
Expand Down Expand Up @@ -477,10 +476,10 @@
(.<! state :compiler :active-node node)

;; Execute the macro
(case (list (xpcall (lambda () (builder (unpack node 2 (n node)))) debug/traceback))
(case (list (xpcall (lambda () (builder (unpack node 2 (n node)))) traceback/traceback))
;; The macro failed so remap the traceback and error
[(false ?msg)
(error-positions! (.> 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)
Expand Down
3 changes: 1 addition & 2 deletions urn/tools/gen-native.lisp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 (..
Expand Down
7 changes: 3 additions & 4 deletions urn/tools/repl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -259,7 +258,7 @@
(.<! visited name true)
(push-cdr! vars (string/sub name (succ (n contents))))))
(recur (.> 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.
Expand Down Expand Up @@ -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 <variable>")))]

Expand Down Expand Up @@ -456,7 +455,7 @@
(.<! vars-set name true)))
(set! current (.> current :parent)))

(table/sort vars)
(sort! vars)

(print! (concat vars " ")))]

Expand Down
9 changes: 4 additions & 5 deletions urn/tools/run.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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))))

(.<! element :children children)
(for-each child children (finish-stack child))))
Expand Down Expand Up @@ -311,7 +310,7 @@
(exit! 1))

(with (names (keys output))
(table/sort names)
(sort! names)

(for-each name names
(with (data (.> output name))
Expand Down Expand Up @@ -510,7 +509,7 @@
(.<! _G :arg (.> args :script-args))
(.<! _G :arg 0 (car (.> 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.")
Expand Down
7 changes: 7 additions & 0 deletions urn/traceback.lisp
Original file line number Diff line number Diff line change
@@ -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+$"))
Expand Down

0 comments on commit 4e50b2a

Please sign in to comment.