diff options
Diffstat (limited to 'stdlib/source/lux/debug.lux')
-rw-r--r-- | stdlib/source/lux/debug.lux | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/stdlib/source/lux/debug.lux b/stdlib/source/lux/debug.lux index 8006c83dd..47d62fd34 100644 --- a/stdlib/source/lux/debug.lux +++ b/stdlib/source/lux/debug.lux @@ -79,7 +79,13 @@ (import: (tostring [.Any] host.String)) (import: math - (#static type [.Any] #? host.String)))})) + (#static type [.Any] #? host.String))) + + @.ruby + (as_is (import: Class) + + (import: Object + (type [] Class)))})) (def: Inspector (-> Any Text)) @@ -230,6 +236,41 @@ _ (..tostring value)) + + @.ruby + (template.with [(class_of <literal>) + (Object::type (:coerce ..Object <literal>))] + (let [value_class (Object::type (:coerce ..Object value))] + (`` (cond (~~ (template [<literal> <type> <format>] + [(is? (class_of <literal>) value_class) + (|> value (:coerce <type>) <format>)] + + [#0 Bit %.bit] + [#1 Bit %.bit] + [+123 Int %.int] + [+123.456 Frac %.frac] + ["+123.456" Text %.text] + [("ruby object nil") Any (new> "nil" [])] + )) + + (is? (class_of #.None) value_class) + (let [variant_tag ("ruby object get" "_lux_tag" value) + variant_flag ("ruby object get" "_lux_flag" value) + variant_value ("ruby object get" "_lux_value" value)] + (if (not (or ("ruby object nil?" variant_tag) + ("ruby object nil?" variant_flag) + ("ruby object nil?" variant_value))) + (|> (format (|> variant_tag (:coerce .Int) %.int) + " " (%.bit (not ("ruby object nil?" variant_flag))) + " " (inspect variant_value)) + (text.enclose ["(" ")"])) + (inspect_tuple inspect value))) + + (is? (class_of [[] []]) value_class) + (inspect_tuple inspect value) + + ## else + (:coerce Text ("ruby object do" "to_s" value)))))) }))) (exception: #export (cannot_represent_value {type Type}) |