From d2d6e69133ccfe7b2ee1723d1785e8cb3458678d Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 12 Apr 2019 21:47:02 -0400 Subject: Added some debugging machinery. --- lux-js/source/program.lux | 49 ++-------------------------- lux-lua/source/program.lux | 58 +-------------------------------- lux-python/source/program.lux | 60 +--------------------------------- lux-ruby/source/program.lux | 58 ++------------------------------- stdlib/source/lux/debug.lux | 75 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 219 deletions(-) create mode 100644 stdlib/source/lux/debug.lux diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux index a55c29aa6..1a2bfc8d8 100644 --- a/lux-js/source/program.lux +++ b/lux-js/source/program.lux @@ -20,6 +20,7 @@ ["." template]] [world ["." file]] + ["." debug] ["." host (#+ import: interface: do-to object) ["_" js]] [tool @@ -123,52 +124,6 @@ (error! (exception.construct unknown-member [member (:coerce java/lang/Object value)])))) )) -(def: (inspect object) - (-> java/lang/Object Text) - (<| (case (host.check java/lang/Boolean object) - (#.Some value) - (%b value) - #.None) - (case (host.check java/lang/String object) - (#.Some value) - (%t value) - #.None) - (case (host.check java/lang/Long object) - (#.Some value) - (%i (.int value)) - #.None) - (case (host.check java/lang/Number object) - (#.Some value) - (%f (java/lang/Number::doubleValue value)) - #.None) - (case (host.check (Array java/lang/Object) object) - (#.Some value) - (let [value (:coerce (Array java/lang/Object) value)] - (case (array.read 0 value) - (^multi (#.Some tag) - [(host.check java/lang/Integer tag) - (#.Some tag)] - [[(array.read 1 value) - (array.read 2 value)] - [last? - (#.Some choice)]]) - (let [last? (case last? - (#.Some _) #1 - #.None #0)] - (|> (format (%n (.nat (java/lang/Integer::longValue tag))) - " " (%b last?) - " " (inspect choice)) - (text.enclose ["(" ")"]))) - - _ - (|> value - array.to-list - (list/map inspect) - (text.join-with " ") - (text.enclose ["[" "]"])))) - #.None) - (java/lang/Object::toString object))) - (def: (::toString js-object) (-> Any jdk/nashorn/api/scripting/JSObject) (object [] jdk/nashorn/api/scripting/AbstractJSObject [] @@ -178,7 +133,7 @@ #1) (jdk/nashorn/api/scripting/AbstractJSObject (call {this java/lang/Object} {args (Array java/lang/Object)}) java/lang/Object - (inspect (:coerce java/lang/Object js-object))) + (debug.inspect js-object)) )) (def: (::slice js-object value) diff --git a/lux-lua/source/program.lux b/lux-lua/source/program.lux index c49f15a4a..13d6862b0 100644 --- a/lux-lua/source/program.lux +++ b/lux-lua/source/program.lux @@ -44,71 +44,15 @@ (import: #long java/lang/String) -(import: #long (java/lang/Class a) - (getCanonicalName [] java/lang/String)) +(import: #long (java/lang/Class a)) (import: #long java/lang/Object - (new []) (toString [] java/lang/String) (getClass [] (java/lang/Class java/lang/Object))) -(import: #long java/lang/Integer - (longValue [] java/lang/Long)) - (import: #long java/lang/Long (intValue [] java/lang/Integer)) -(import: #long java/lang/Number - (intValue [] java/lang/Integer) - (longValue [] long) - (doubleValue [] double)) - -(def: (inspect object) - (-> java/lang/Object Text) - (<| (case (host.check java/lang/Boolean object) - (#.Some value) - (%b value) - #.None) - (case (host.check java/lang/String object) - (#.Some value) - (%t value) - #.None) - (case (host.check java/lang/Long object) - (#.Some value) - (%i (.int value)) - #.None) - (case (host.check java/lang/Number object) - (#.Some value) - (%f (java/lang/Number::doubleValue value)) - #.None) - (case (host.check (Array java/lang/Object) object) - (#.Some value) - (let [value (:coerce (Array java/lang/Object) value)] - (case (array.read 0 value) - (^multi (#.Some tag) - [(host.check java/lang/Integer tag) - (#.Some tag)] - [[(array.read 1 value) - (array.read 2 value)] - [last? - (#.Some choice)]]) - (let [last? (case last? - (#.Some _) #1 - #.None #0)] - (|> (format (%n (.nat (java/lang/Integer::longValue tag))) - " " (%b last?) - " " (inspect choice)) - (text.enclose ["(" ")"]))) - - _ - (|> value - array.to-list - (list@map inspect) - (text.join-with " ") - (text.enclose ["[" "]"])))) - #.None) - (java/lang/Object::toString object))) - (import: #long net/sandius/rembulan/StateContext) (import: #long net/sandius/rembulan/impl/StateContexts diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux index 3fbd8ccd6..41a720b36 100644 --- a/lux-python/source/program.lux +++ b/lux-python/source/program.lux @@ -41,71 +41,13 @@ (import: #long java/lang/String) -(import: #long (java/lang/Class a) - (getCanonicalName [] java/lang/String)) +(import: #long (java/lang/Class a)) (import: #long java/lang/Object (new []) (toString [] java/lang/String) (getClass [] (java/lang/Class java/lang/Object))) -(import: #long java/lang/Integer - (longValue [] java/lang/Long)) - -(import: #long java/lang/Long - (intValue [] java/lang/Integer)) - -(import: #long java/lang/Number - (intValue [] java/lang/Integer) - (longValue [] long) - (doubleValue [] double)) - -(def: (inspect object) - (-> java/lang/Object Text) - (<| (case (host.check java/lang/Boolean object) - (#.Some value) - (%b value) - #.None) - (case (host.check java/lang/String object) - (#.Some value) - (%t value) - #.None) - (case (host.check java/lang/Long object) - (#.Some value) - (%i (.int value)) - #.None) - (case (host.check java/lang/Number object) - (#.Some value) - (%f (java/lang/Number::doubleValue value)) - #.None) - (case (host.check (Array java/lang/Object) object) - (#.Some value) - (let [value (:coerce (Array java/lang/Object) value)] - (case (array.read 0 value) - (^multi (#.Some tag) - [(host.check java/lang/Integer tag) - (#.Some tag)] - [[(array.read 1 value) - (array.read 2 value)] - [last? - (#.Some choice)]]) - (let [last? (case last? - (#.Some _) #1 - #.None #0)] - (|> (format (%n (.nat (java/lang/Integer::longValue tag))) - " " (%b last?) - " " (inspect choice)) - (text.enclose ["(" ")"]))) - - _ - (|> value - array.to-list - (list@map inspect) - (text.join-with " ") - (text.enclose ["[" "]"])))) - #.None) - (java/lang/Object::toString object))) - (import: #long org/python/core/PyNone) (import: #long org/python/core/PyBoolean) (import: #long org/python/core/PyInteger) diff --git a/lux-ruby/source/program.lux b/lux-ruby/source/program.lux index b9b576f29..0eeed48ec 100644 --- a/lux-ruby/source/program.lux +++ b/lux-ruby/source/program.lux @@ -44,71 +44,17 @@ (import: #long java/lang/String) -(import: #long (java/lang/Class a) - (getCanonicalName [] java/lang/String)) +(import: #long (java/lang/Class a)) (import: #long java/lang/Object - (new []) (toString [] java/lang/String) (getClass [] (java/lang/Class java/lang/Object))) -(import: #long java/lang/Integer - (longValue [] java/lang/Long)) +(import: #long java/lang/Integer) (import: #long java/lang/Long (intValue [] java/lang/Integer)) -(import: #long java/lang/Number - (intValue [] java/lang/Integer) - (longValue [] long) - (doubleValue [] double)) - -(def: (inspect object) - (-> java/lang/Object Text) - (<| (case (host.check java/lang/Boolean object) - (#.Some value) - (%b value) - #.None) - (case (host.check java/lang/String object) - (#.Some value) - (%t value) - #.None) - (case (host.check java/lang/Long object) - (#.Some value) - (%i (.int value)) - #.None) - (case (host.check java/lang/Number object) - (#.Some value) - (%f (java/lang/Number::doubleValue value)) - #.None) - (case (host.check (Array java/lang/Object) object) - (#.Some value) - (let [value (:coerce (Array java/lang/Object) value)] - (case (array.read 0 value) - (^multi (#.Some tag) - [(host.check java/lang/Integer tag) - (#.Some tag)] - [[(array.read 1 value) - (array.read 2 value)] - [last? - (#.Some choice)]]) - (let [last? (case last? - (#.Some _) #1 - #.None #0)] - (|> (format (%n (.nat (java/lang/Integer::longValue tag))) - " " (%b last?) - " " (inspect choice)) - (text.enclose ["(" ")"]))) - - _ - (|> value - array.to-list - (list@map inspect) - (text.join-with " ") - (text.enclose ["[" "]"])))) - #.None) - (java/lang/Object::toString object))) - (import: #long org/jruby/RubyArray (getLength [] int) (get [int] #? Object)) diff --git a/stdlib/source/lux/debug.lux b/stdlib/source/lux/debug.lux new file mode 100644 index 000000000..63a46aff4 --- /dev/null +++ b/stdlib/source/lux/debug.lux @@ -0,0 +1,75 @@ +(.module: + [lux #* + [data + ["." text + format] + [collection + ["." array (#+ Array)] + ["." list ("#@." functor)]]] + [macro + ["." template]] + ["." host (#+ import:)]]) + +(import: #long java/lang/String) + +(import: #long (java/lang/Class a) + (getCanonicalName [] java/lang/String)) + +(import: #long java/lang/Object + (new []) + (toString [] java/lang/String) + (getClass [] (java/lang/Class java/lang/Object))) + +(import: #long java/lang/Integer + (longValue [] java/lang/Long)) + +(import: #long java/lang/Long + (intValue [] java/lang/Integer)) + +(import: #long java/lang/Number + (intValue [] java/lang/Integer) + (longValue [] long) + (doubleValue [] double)) + +(def: #export (inspect value) + (-> Any Text) + (let [object (:coerce java/lang/Object value)] + (`` (<| (~~ (template [ ] + [(case (host.check object) + (#.Some value) + (`` (|> value (~~ (template.splice )))) + #.None)] + + [java/lang/Boolean [%b]] + [java/lang/String [%t]] + [java/lang/Long [.int %i]] + [java/lang/Number [java/lang/Number::doubleValue %f]] + )) + (case (host.check (Array java/lang/Object) object) + (#.Some value) + (let [value (:coerce (Array java/lang/Object) value)] + (case (array.read 0 value) + (^multi (#.Some tag) + [(host.check java/lang/Integer tag) + (#.Some tag)] + [[(array.read 1 value) + (array.read 2 value)] + [last? + (#.Some choice)]]) + (let [last? (case last? + (#.Some _) #1 + #.None #0)] + (|> (format (%n (.nat (java/lang/Integer::longValue tag))) + " " (%b last?) + " " (inspect choice)) + (text.enclose ["(" ")"]))) + + _ + (|> value + array.to-list + (list@map inspect) + (text.join-with " ") + (text.enclose ["[" "]"])))) + #.None) + (java/lang/Object::toString object))) + )) -- cgit v1.2.3