aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler
diff options
context:
space:
mode:
authorEduardo Julian2022-02-22 16:29:17 -0400
committerEduardo Julian2022-02-22 16:29:17 -0400
commitf07effd9faf3fdaa677f659d6bbccf98931c5e5a (patch)
tree0b51a4b8492d06db6b3eca38a3b9143de1c1d735 /stdlib/source/library/lux/tool/compiler
parent2d1348a73159ec87fa0da2bd3768d641236693fb (diff)
No more automatic conversions of primitive types in JVM FFI.
Diffstat (limited to 'stdlib/source/library/lux/tool/compiler')
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/analysis/inference.lux6
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux190
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/complex.lux39
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/archive/artifact/category.lux2
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux15
5 files changed, 126 insertions, 126 deletions
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/inference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/inference.lux
index 6ca7137d2..fa9e2e0fb 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/inference.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/inference.lux
@@ -80,9 +80,9 @@
([.#UnivQ]
[.#ExQ])
- (^or {.#Parameter @}
- {.#Ex @}
- {.#Named name anonymous})
+ (^or {.#Parameter _}
+ {.#Ex _}
+ {.#Named _})
:it:))
... Type-inference works by applying some (potentially quantified) type
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
index 657096c10..085e071a7 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
@@ -10,6 +10,8 @@
["%" format {"+" format}]]
[collection
["[0]" list]]]
+ [macro
+ ["[0]" code]]
[math
[number
["n" nat]]]
@@ -33,105 +35,97 @@
[meta
[archive {"+" Archive}]]]]]])
-(exception: .public (unrecognized_syntax [code Code])
+(exception: .public (invalid [syntax Code])
(exception.report
- ["Code" (%.code code)]))
-
-... TODO: Had to split the 'compile' function due to compilation issues
-... with old-luxc. Must re-combine all the code ASAP
-
-(type: (Fix a)
- (-> a a))
-
-(def: (compile|literal archive compile else code')
- (-> Archive Phase (Fix (-> (Code' (Ann Location)) (Operation Analysis))))
- (case code'
- (^template [<tag> <analyser>]
- [{<tag> value}
- (<analyser> value)])
- ([.#Bit /simple.bit]
- [.#Nat /simple.nat]
- [.#Int /simple.int]
- [.#Rev /simple.rev]
- [.#Frac /simple.frac]
- [.#Text /simple.text])
-
- (^ {.#Variant (list& [_ {.#Symbol tag}]
- values)})
- (case values
- {.#Item value {.#End}}
- (/complex.variant compile tag archive value)
-
- _
- (/complex.variant compile tag archive (` [(~+ values)])))
-
- (^ {.#Variant (list& [_ {.#Nat lefts}] [_ {.#Bit right?}]
- values)})
- (case values
- {.#Item value {.#End}}
- (/complex.sum compile lefts right? archive value)
-
- _
- (/complex.sum compile lefts right? archive (` [(~+ values)])))
-
- (^ {.#Tuple elems})
- (/complex.record compile archive elems)
-
- _
- (else code')))
-
-(def: (compile|others expander archive compile code')
- (-> Expander Archive Phase (-> (Code' (Ann Location)) (Operation Analysis)))
- (case code'
- {.#Symbol reference}
- (/reference.reference reference)
-
- (^ {.#Form (list [_ {.#Variant branches}] input)})
- (case (list.pairs branches)
- {.#Some branches}
- (/case.case compile branches archive input)
-
- {.#None}
- (//.except ..unrecognized_syntax [location.dummy code']))
-
- (^ {.#Form (list& [_ {.#Text extension_name}] extension_args)})
- (//extension.apply archive compile [extension_name extension_args])
-
- (^ {.#Form (list [_ {.#Tuple (list [_ {.#Symbol ["" function_name]}]
- [_ {.#Symbol ["" arg_name]}])}]
- body)})
- (/function.function compile function_name arg_name archive body)
-
- (^ {.#Form (list& functionC argsC+)})
- (do [! //.monad]
- [[functionT functionA] (/type.inferring
- (compile archive functionC))]
- (case functionA
- {/.#Reference {reference.#Constant def_name}}
- (do !
- [?macro (//extension.lifted (meta.macro def_name))]
- (case ?macro
- {.#Some macro}
- (do !
- [expansion (//extension.lifted (/macro.single_expansion expander def_name macro argsC+))]
- (compile archive expansion))
-
- _
- (/function.apply compile argsC+ functionT functionA archive functionC)))
-
- _
- (/function.apply compile argsC+ functionT functionA archive functionC)))
-
- _
- (//.except ..unrecognized_syntax [location.dummy code'])))
+ ["Syntax" (%.code syntax)]))
+
+(template: (variant_analysis analysis archive tag values)
+ ... (-> Phase Archive Symbol (List Code) (Operation Analysis))
+ [(case values
+ (^ (list value))
+ (/complex.variant analysis tag archive value)
+
+ _
+ (/complex.variant analysis tag archive (code.tuple values)))])
+
+(template: (sum_analysis analysis archive lefts right? values)
+ ... (-> Phase Archive Nat Bit (List Code) (Operation Analysis))
+ [(case values
+ (^ (list value))
+ (/complex.sum analysis lefts right? archive value)
+
+ _
+ (/complex.sum analysis lefts right? archive (code.tuple values)))])
+
+(template: (case_analysis analysis archive input branches code)
+ ... (-> Phase Archive Code (List Code) Code (Operation Analysis))
+ [(case (list.pairs branches)
+ {.#Some branches}
+ (/case.case analysis branches archive input)
+
+ {.#None}
+ (//.except ..invalid [code]))])
+
+(template: (apply_analysis expander analysis archive functionC argsC+)
+ ... (-> Expander Phase Archive Code (List Code) (Operation Analysis))
+ [(do [! //.monad]
+ [[functionT functionA] (/type.inferring
+ (analysis archive functionC))]
+ (case functionA
+ (^ (/.constant def_name))
+ (do !
+ [?macro (//extension.lifted (meta.macro def_name))]
+ (case ?macro
+ {.#Some macro}
+ (do !
+ [expansion (//extension.lifted (/macro.single_expansion expander def_name macro argsC+))]
+ (analysis archive expansion))
+
+ _
+ (/function.apply analysis argsC+ functionT functionA archive functionC)))
+
+ _
+ (/function.apply analysis argsC+ functionT functionA archive functionC)))])
(def: .public (phase expander)
(-> Expander Phase)
- (function (compile archive code)
- (let [[location code'] code]
- ... The location must be set in the state for the sake
- ... of having useful error messages.
- (/.with_location location
- (compile|literal archive compile
- (compile|others expander archive compile)
- code')))))
+ (function (analysis archive code)
+ (<| (let [[location code'] code])
+ ... The location must be set in the state for the sake
+ ... of having useful error messages.
+ (/.with_location location)
+ (case code
+ (^template [<tag> <analyser>]
+ [[_ {<tag> value}]
+ (<analyser> value)])
+ ([.#Symbol /reference.reference]
+ [.#Text /simple.text]
+ [.#Nat /simple.nat]
+ [.#Bit /simple.bit]
+ [.#Frac /simple.frac]
+ [.#Int /simple.int]
+ [.#Rev /simple.rev])
+
+ (^code [(~+ elems)])
+ (/complex.record analysis archive elems)
+
+ (^code {(~ [_ {.#Symbol tag}]) (~+ values)})
+ (..variant_analysis analysis archive tag values)
+
+ (^code ({(~+ branches)} (~ input)))
+ (..case_analysis analysis archive input branches code)
+
+ (^code ([(~ [_ {.#Symbol ["" function_name]}]) (~ [_ {.#Symbol ["" arg_name]}])] (~ body)))
+ (/function.function analysis function_name arg_name archive body)
+
+ (^code ((~ [_ {.#Text extension_name}]) (~+ extension_args)))
+ (//extension.apply archive analysis [extension_name extension_args])
+
+ (^code ((~ functionC) (~+ argsC+)))
+ (..apply_analysis expander analysis archive functionC argsC+)
+
+ (^code {(~ [_ {.#Nat lefts}]) (~ [_ {.#Bit right?}]) (~+ values)})
+ (..sum_analysis analysis archive lefts right? values)
+
+ _
+ (//.except ..invalid [code])))))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/complex.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/complex.lux
index 1bf6a48b9..54b2cf1dd 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/complex.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/complex.lux
@@ -134,15 +134,17 @@
_
(/.except ..cannot_infer_sum [expectedT lefts right? valueC])))
- (^template [<tag> <instancer>]
- [{<tag> _}
- (do !
- [[@instance :instance:] (/type.check <instancer>)]
- (<| (/type.expecting (maybe.trusted (type.applied (list :instance:) expectedT)))
- (again valueC)))])
- ([.#UnivQ check.existential]
- [.#ExQ check.var])
-
+ {.#UnivQ _}
+ (do !
+ [[@instance :instance:] (/type.check check.existential)]
+ (<| (/type.expecting (maybe.trusted (type.applied (list :instance:) expectedT)))
+ (again valueC)))
+ {.#ExQ _}
+ (<| /type.with_var
+ (function (_ [@instance :instance:]))
+ (/type.expecting (maybe.trusted (type.applied (list :instance:) expectedT)))
+ (again valueC))
+
{.#Apply inputT funT}
(case funT
{.#Var funT_id}
@@ -247,14 +249,17 @@
(type.tuple (list#each product.left membersTA))))]
(in (/.tuple (list#each product.right membersTA))))))
- (^template [<tag> <instancer>]
- [{<tag> _}
- (do !
- [[@instance :instance:] (/type.check <instancer>)]
- (<| (/type.expecting (maybe.trusted (type.applied (list :instance:) expectedT)))
- (product analyse archive membersC)))])
- ([.#UnivQ check.existential]
- [.#ExQ check.var])
+ {.#UnivQ _}
+ (do !
+ [[@instance :instance:] (/type.check check.existential)]
+ (<| (/type.expecting (maybe.trusted (type.applied (list :instance:) expectedT)))
+ (product analyse archive membersC)))
+
+ {.#ExQ _}
+ (<| /type.with_var
+ (function (_ [@instance :instance:]))
+ (/type.expecting (maybe.trusted (type.applied (list :instance:) expectedT)))
+ (product analyse archive membersC))
{.#Apply inputT funT}
(case funT
diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/artifact/category.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/artifact/category.lux
index 526a8bce1..61698487d 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/archive/artifact/category.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/archive/artifact/category.lux
@@ -17,7 +17,7 @@
(type: .public Definition
[Text (Maybe [Arity [Nat Nat]])])
-(def: definition_equivalence
+(def: .public definition_equivalence
(Equivalence Definition)
($_ product.equivalence
text.equivalence
diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux
index 7f672fd92..4b5a82a43 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux
@@ -148,7 +148,7 @@
(do try.monad
[_ (java/util/jar/JarOutputStream::putNextEntry (java/util/jar/JarEntry::new class_path) sink)]
(in (do_to sink
- (java/util/zip/ZipOutputStream::write content +0 (.int (binary.size content)))
+ (java/util/zip/ZipOutputStream::write content (ffi.as_int +0) (ffi.as_int (.int (binary.size content))))
(java/io/Flushable::flush)
(java/util/zip/ZipOutputStream::closeEntry))))))
@@ -168,16 +168,16 @@
(-> java/util/jar/JarInputStream [Nat Binary])
(let [chunk (binary.empty ..mebi_byte)
chunk_size (.int ..mebi_byte)
- buffer (java/io/ByteArrayOutputStream::new chunk_size)]
+ buffer (java/io/ByteArrayOutputStream::new (ffi.as_int chunk_size))]
(loop [so_far 0]
- (case (java/io/InputStream::read chunk 0 chunk_size input)
+ (case (ffi.of_int (java/io/InputStream::read chunk (ffi.as_int +0) (ffi.as_int chunk_size) input))
-1
[so_far
(java/io/ByteArrayOutputStream::toByteArray buffer)]
bytes_read
(exec
- (java/io/OutputStream::write chunk +0 bytes_read buffer)
+ (java/io/OutputStream::write chunk (ffi.as_int +0) (ffi.as_int bytes_read) buffer)
(again (|> bytes_read .nat (n.+ so_far))))))))
(def: (read_jar_entry_with_known_size expected_size input)
@@ -185,7 +185,8 @@
(let [buffer (binary.empty expected_size)]
(loop [so_far 0]
(let [so_far' (|> input
- (java/io/InputStream::read buffer (.int so_far) (.int (n.- so_far expected_size)))
+ (java/io/InputStream::read buffer (ffi.as_int (.int so_far)) (ffi.as_int (.int (n.- so_far expected_size))))
+ ffi.of_int
.nat
(n.+ so_far))]
(if (n.= expected_size so_far')
@@ -241,7 +242,7 @@
(again (set.has entry_path entries)
duplicates
(do_to sink
- (java/util/zip/ZipOutputStream::write entry_data +0 (.int entry_size))
+ (java/util/zip/ZipOutputStream::write entry_data (ffi.as_int +0) (ffi.as_int (.int entry_size)))
(java/io/Flushable::flush)
(java/util/zip/ZipOutputStream::closeEntry)))))
(again entries
@@ -254,7 +255,7 @@
(do [! try.monad]
[.let [necessary_dependencies (cache/artifact.necessary_dependencies archive)]
order (cache/module.load_order $.key archive)
- .let [buffer (java/io/ByteArrayOutputStream::new (.int ..mebi_byte))]
+ .let [buffer (java/io/ByteArrayOutputStream::new (ffi.as_int (.int ..mebi_byte)))]
sink (|> order
(list#each (function (_ [module [module_id entry]])
[module_id (value@ archive.#output entry)]))