Skip to content

Commit

Permalink
Got rid of the extensions for Text embeddings of Dec(imal) values.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Aug 19, 2023
1 parent 6fff522 commit 9291b0f
Show file tree
Hide file tree
Showing 76 changed files with 1,426 additions and 1,314 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![Gitter](https://badges.gitter.im/LuxProgrammingLanguage/community.svg)](https://gitter.im/LuxProgrammingLanguage/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

# What is Lux?

Lux is a new programming language in the making.
Expand Down Expand Up @@ -86,8 +84,6 @@ Alternatively, you can use the `syntax` macro, which also offers monadic parsing

We have a Discord server: https://discord.gg/YPvEGANkch

Say hi at Gitter: https://gitter.im/LuxProgrammingLanguage/community

Come join the forum: http://luxlang.freeforums.net/

If you want to communicate with me directly, just email: luxlisp@gmail.com
Expand Down
25 changes: 1 addition & 24 deletions lux-bootstrapper/src/lux/analyser/proc/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,6 @@
["f64" "<"] analyse-f64-lt &type/Dec &type/Bit
)

(do-template [<encode> <encode-op> <decode> <decode-op> <type>]
(do (defn- <encode> [analyse exo-type ?values]
(|do [:let [(&/$Item x (&/$End)) ?values]
=x (&&/analyse-1 analyse <type> x)
_ (&type/check exo-type &type/Text)
_location &/location]
(return (&/|list (&&/|meta exo-type _location
(&&/$proc (&/T <encode-op>) (&/|list =x) (&/|list)))))))

(let [decode-type (&/$Apply <type> &type/Maybe)]
(defn- <decode> [analyse exo-type ?values]
(|do [:let [(&/$Item x (&/$End)) ?values]
=x (&&/analyse-1 analyse &type/Text x)
_ (&type/check exo-type decode-type)
_location &/location]
(return (&/|list (&&/|meta exo-type _location
(&&/$proc (&/T <decode-op>) (&/|list =x) (&/|list)))))))))

analyse-f64-encode ["f64" "encode"] analyse-f64-decode ["f64" "decode"] &type/Dec
)

(do-template [<name> <from-type> <to-type> <op>]
(defn- <name> [analyse exo-type ?values]
(|do [:let [(&/$Item x (&/$End)) ?values]
Expand Down Expand Up @@ -240,7 +219,7 @@

"f64_+#" "f64_-#" "f64_*#" "f64_/#" "f64_%#"
"f64_=#" "f64_<#"
"f64_int#" "f64_encoded#" "f64_decoded#"}]
"f64_int#"}]
(defn uses_new_format? [extension]
(if (extensions extension)
true
Expand Down Expand Up @@ -292,8 +271,6 @@
"f64_<#" (analyse-f64-lt analyse exo-type ?values)

"f64_int#" (analyse-f64-int analyse exo-type ?values)
"f64_encoded#" (analyse-f64-encode analyse exo-type ?values)
"f64_decoded#" (analyse-f64-decode analyse exo-type ?values)

;; else
(&/fail-with-loc (str "[Analyser Error] Unknown host procedure: " proc)))
Expand Down
20 changes: 0 additions & 20 deletions lux-bootstrapper/src/lux/compiler/jvm/proc/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,6 @@
^:private compile-dec-lt Opcodes/DCMPG -1 &&/unwrap-double
)

(defn ^:private compile-dec-encode [compile ?values special-args]
(|do [:let [(&/$Item ?input (&/$End)) ?values]
^MethodVisitor *writer* &/get-writer
_ (compile ?input)
:let [_ (doto *writer*
&&/unwrap-double
(.visitMethodInsn Opcodes/INVOKESTATIC "java/lang/Double" "toString" "(D)Ljava/lang/String;"))]]
(return nil)))

(defn ^:private compile-dec-decode [compile ?values special-args]
(|do [:let [(&/$Item ?input (&/$End)) ?values]
^MethodVisitor *writer* &/get-writer
_ (compile ?input)
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/CHECKCAST "java/lang/String")
(.visitMethodInsn Opcodes/INVOKESTATIC &rt/runtime-class "decode_dec" "(Ljava/lang/String;)[Ljava/lang/Object;"))]]
(return nil)))

(defn ^:private compile-int-char [compile ?values special-args]
(|do [:let [(&/$Item ?x (&/$End)) ?values]
^MethodVisitor *writer* &/get-writer
Expand Down Expand Up @@ -459,8 +441,6 @@
"=" (compile-dec-eq compile ?values special-args)
"<" (compile-dec-lt compile ?values special-args)
"i64" (compile-dec-int compile ?values special-args)
"encode" (compile-dec-encode compile ?values special-args)
"decode" (compile-dec-decode compile ?values special-args)
)

;; else
Expand Down
28 changes: 1 addition & 27 deletions lux-bootstrapper/src/lux/compiler/jvm/rt.clj
Original file line number Diff line number Diff line change
Expand Up @@ -264,31 +264,6 @@
(.visitInsn Opcodes/POP2) ;; Y2, X1
))

(do-template [<name> <method> <class> <parse-method> <signature> <wrapper>]
(defn <name> [^ClassWriter =class]
(do (let [$from (new Label)
$to (new Label)
$handler (new Label)]
(doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) <method> "(Ljava/lang/String;)[Ljava/lang/Object;" nil nil)
(.visitCode)
(.visitTryCatchBlock $from $to $handler "java/lang/Exception")
(.visitLabel $from)
(.visitVarInsn Opcodes/ALOAD 0)
(.visitMethodInsn Opcodes/INVOKESTATIC <class> <parse-method> <signature>)
<wrapper>
(.visitMethodInsn Opcodes/INVOKESTATIC runtime-class "make_some" "(Ljava/lang/Object;)[Ljava/lang/Object;")
(.visitInsn Opcodes/ARETURN)
(.visitLabel $to)
(.visitLabel $handler)
(.visitMethodInsn Opcodes/INVOKESTATIC runtime-class "make_none" "()[Ljava/lang/Object;")
(.visitInsn Opcodes/ARETURN)
(.visitMaxs 0 0)
(.visitEnd)))
nil))

^:private compile-Runtime-dec-methods "decode_dec" "java/lang/Double" "parseDouble" "(Ljava/lang/String;)D" &&/wrap-double
)

(defn peekI [^MethodVisitor writer]
(doto writer
(.visitLdcInsn (int 0))
Expand Down Expand Up @@ -429,7 +404,6 @@
(.visitEnd)))
_ (doto =class
(compile-Runtime-pm-methods)
(compile-Runtime-adt-methods)
(compile-Runtime-dec-methods))]]
(compile-Runtime-adt-methods))]]
(&&/save-class! (-> &&/lux-utils-class (string/split #"/") (nth 2))
(.toByteArray (doto =class .visitEnd)))))
90 changes: 45 additions & 45 deletions lux-js/source/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
(-> (I64 Any) java/lang/Integer)
(|>> .int
ffi.as_long
java/lang/Long::intValue))
(java/lang/Long::intValue [])))

(the (js_int value)
(-> Int org/openjdk/nashorn/api/scripting/JSObject)
Expand Down Expand Up @@ -228,13 +228,13 @@
[] (call self [this java/lang/Object
args [java/lang/Object]])
java/lang/Object
(|> (java/util/Arrays::copyOfRange value
(|> args
(array.item 0)
maybe.trusted
(as Int)
ffi.as_int)
(ffi.as_int (.int (array.size value))))
(|> (java/util/Arrays::copyOfRange [value
(|> args
(array.item 0)
try.trusted
(as Int)
ffi.as_int)
(ffi.as_int (.int (array.size value)))])
(as java/lang/Object)
js_object
(ffi.is java/lang/Object)))
Expand Down Expand Up @@ -293,20 +293,20 @@
runtime.variant_tag_field
(|> value
(array.item 0)
maybe.trusted)
try.trusted)

runtime.variant_flag_field
(when (array.item 1 value)
{.#Some set!}
{try.#Success set!}
set!

_
{try.#Failure _}
(ffi.null))

runtime.variant_value_field
(|> value
(array.item 2)
maybe.trusted
try.trusted
js_object
(ffi.is java/lang/Object))

Expand All @@ -316,8 +316,8 @@
[] (getSlot self [idx int])
java/lang/Object
(|> value
(array.item (|> idx java/lang/Integer::longValue (as Nat)))
maybe.trusted
(array.item (|> idx (java/lang/Integer::longValue []) (as Nat)))
try.trusted
js_object
(as java/lang/Object)))
))))
Expand All @@ -327,12 +327,12 @@
(exception.the (unknown_kind_of_host_object object)
(Exception java/lang/Object)
(exception.report
(list ["Class" (ffi.of_string (java/lang/Object::toString (java/lang/Object::getClass object)))]
["Object" (ffi.of_string (java/lang/Object::toString object))]
(list ["Class" (ffi.of_string (java/lang/Object::toString [] (java/lang/Object::getClass [] object)))]
["Object" (ffi.of_string (java/lang/Object::toString [] object))]
["Keys" (when (ffi.as org/openjdk/nashorn/api/scripting/ScriptObjectMirror object)
{.#Some object}
(|> object
(org/openjdk/nashorn/api/scripting/ScriptObjectMirror::getOwnKeys true)
(org/openjdk/nashorn/api/scripting/ScriptObjectMirror::getOwnKeys [true])
(array.list {.#None})
(%.list (|>> ffi.of_string %.text)))

Expand All @@ -345,7 +345,7 @@
(org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string half)])
(maybe#each (|>> (ffi.as java/lang/Number)))
maybe#conjoint
(maybe#each (|>> java/lang/Number::longValue ffi.of_long))))
(maybe#each (|>> (java/lang/Number::longValue []) ffi.of_long))))

(the (check_int js_object)
(-> org/openjdk/nashorn/api/scripting/ScriptObjectMirror
Expand All @@ -371,7 +371,7 @@
(^.multi [{.#Some tag} ?flag {.#Some value}]
[[(ffi.as java/lang/Number tag) (lux_object value)]
[{.#Some tag} {try.#Success value}]])
{.#Some [(java/lang/Number::intValue (as java/lang/Number tag))
{.#Some [(java/lang/Number::intValue [] (as java/lang/Number tag))
(maybe.else (ffi.null) ?flag)
value]}

Expand All @@ -382,13 +382,13 @@
(-> (-> java/lang/Object (Try Any))
org/openjdk/nashorn/api/scripting/ScriptObjectMirror
(Maybe (Array java/lang/Object)))
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isArray js_object))
(let [num_keys (.nat (ffi.of_int (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::size js_object)))]
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isArray [] js_object))
(let [num_keys (.nat (ffi.of_int (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::size [] js_object)))]
(loop (again [idx 0
output (is (Array java/lang/Object)
(array.empty num_keys))])
(if (n.< num_keys idx)
(when (org/openjdk/nashorn/api/scripting/JSObject::getMember (ffi.as_string (%.nat idx)) js_object)
(when (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string (%.nat idx))] js_object)
{.#Some member}
(when (ffi.as org/openjdk/nashorn/internal/runtime/Undefined member)
{.#Some _}
Expand Down Expand Up @@ -427,13 +427,13 @@
(,, (with_template [<class> <method>]
[(when (ffi.as <class> js_object)
{.#Some js_object}
{try.#Success (<method> js_object)}
{try.#Success (|> js_object <method>)}

{.#None})]

[java/lang/Number java/lang/Number::doubleValue]
[StructureValue StructureValue::getValue]
[IntValue IntValue::getValue]))
[java/lang/Number (java/lang/Number::doubleValue [])]
[StructureValue (StructureValue::getValue [])]
[IntValue (IntValue::getValue [])]))
(when (ffi.as org/openjdk/nashorn/api/scripting/ScriptObjectMirror js_object)
{.#Some js_object}
(when (check_int js_object)
Expand All @@ -451,7 +451,7 @@
{try.#Success value}

{.#None}
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction js_object))
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction [] js_object))
{try.#Success js_object}
... (exception.except ..unknown_kind_of_host_object [(as java/lang/Object js_object)])
{try.#Success js_object}
Expand All @@ -468,7 +468,7 @@
[function (|> function
(as java/lang/Object)
(ffi.as org/openjdk/nashorn/api/scripting/JSObject))]
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction function))
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction [] function))
{.#Some function}
{.#None})))
)
Expand All @@ -482,17 +482,17 @@
(let [to_js (is (-> Any java/lang/Object)
(|>> (as (Array java/lang/Object)) js_structure (as java/lang/Object)))]
(<| (as (Try (Try [Lux (List Code)])))
(org/openjdk/nashorn/api/scripting/JSObject::call {.#None}
(|> (array.empty 2)
(is (Array java/lang/Object))
(array.has! 0 (to_js inputs))
(array.has! 1 (to_js lux)))
(org/openjdk/nashorn/api/scripting/JSObject::call [{.#None}
(|> (array.empty 2)
(is (Array java/lang/Object))
(array.has! 0 (to_js inputs))
(array.has! 1 (to_js lux)))]
macro))))

(exception.the (cannot_apply_a_non_function object)
(Exception java/lang/Object)
(exception.report
(list ["Object" (ffi.of_string (java/lang/Object::toString object))])))
(list ["Object" (ffi.of_string (java/lang/Object::toString [] object))])))

(the (expander macro inputs lux)
Expander
Expand Down Expand Up @@ -522,7 +522,7 @@
(these (the (evaluate! interpreter input)
(-> javax/script/ScriptEngine _.Expression (Try Any))
(do try.monad
[?output (javax/script/ScriptEngine::eval (ffi.as_string (_.code input)) interpreter)]
[?output (javax/script/ScriptEngine::eval [(ffi.as_string (_.code input))] interpreter)]
(when ?output
{.#Some output}
(..lux_object output)
Expand All @@ -533,7 +533,7 @@
(the (execute! interpreter input)
(-> javax/script/ScriptEngine _.Statement (Try Any))
(do try.monad
[?output (javax/script/ScriptEngine::eval (ffi.as_string (_.code input)) interpreter)]
[?output (javax/script/ScriptEngine::eval [(ffi.as_string (_.code input))] interpreter)]
(in [])))

(the (define! interpreter context custom input)
Expand All @@ -549,8 +549,8 @@

(the host
(IO (Host _.Expression _.Statement))
(io (let [interpreter (javax/script/ScriptEngineFactory::getScriptEngine
(org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory::new))]
(io (let [interpreter (|> (org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory::new [])
(javax/script/ScriptEngineFactory::getScriptEngine []))]
(is (Host _.Expression _.Statement)
(implementation
(the (evaluate [_ input]) (..evaluate! interpreter input))
Expand Down Expand Up @@ -693,13 +693,13 @@
(..ensure_function handler))
.let [to_js (is (-> Any java/lang/Object)
(|>> (as (Array java/lang/Object)) js_structure (as java/lang/Object)))]
output (org/openjdk/nashorn/api/scripting/JSObject::call {.#None}
(|> (array.empty 4)
(is (Array java/lang/Object))
(array.has! 0 (as java/lang/Object ..phase_wrapper))
(array.has! 1 (to_js archive))
(array.has! 2 (to_js parameters))
(array.has! 3 (to_js state)))
output (org/openjdk/nashorn/api/scripting/JSObject::call [{.#None}
(|> (array.empty 4)
(is (Array java/lang/Object))
(array.has! 0 (as java/lang/Object ..phase_wrapper))
(array.has! 1 (to_js archive))
(array.has! 2 (to_js parameters))
(array.has! 3 (to_js state)))]
handler)]
(lux_object (as java/lang/Object output)))))

Expand Down
Loading

0 comments on commit 9291b0f

Please sign in to comment.