aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--documentation/research/Graphic User Interface (GUI).md4
-rw-r--r--documentation/research/Probabilistic data-structure.md1
-rw-r--r--documentation/research/chemistry.md4
-rw-r--r--documentation/research/floating point.md4
-rw-r--r--documentation/research/game_programming.md1
-rw-r--r--documentation/research/math.md1
-rw-r--r--documentation/research/operating_system.md1
-rw-r--r--documentation/research/text_editor & ide.md1
-rw-r--r--new-luxc/source/luxc/lang/directive/jvm.lux263
-rw-r--r--new-luxc/source/program.lux112
-rw-r--r--stdlib/source/lux/target/jvm/attribute.lux20
-rw-r--r--stdlib/source/lux/target/jvm/attribute/constant.lux8
-rw-r--r--stdlib/source/lux/target/jvm/bytecode.lux22
-rw-r--r--stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux303
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/jvm/host.lux (renamed from new-luxc/source/luxc/lang/translation/jvm.lux)111
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/jvm/packager.lux (renamed from new-luxc/source/luxc/lang/packager.lux)11
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/jvm/program.lux143
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux17
18 files changed, 580 insertions, 447 deletions
diff --git a/documentation/research/Graphic User Interface (GUI).md b/documentation/research/Graphic User Interface (GUI).md
index 32f391764..210cf4756 100644
--- a/documentation/research/Graphic User Interface (GUI).md
+++ b/documentation/research/Graphic User Interface (GUI).md
@@ -1,3 +1,7 @@
+# Widget
+
+1. [Progress bar.js](https://kimmobrunfeldt.github.io/progressbar.js/)
+
# Design
1. [Ant Design](https://ant.design/)
diff --git a/documentation/research/Probabilistic data-structure.md b/documentation/research/Probabilistic data-structure.md
index 2b4609c0e..f7c025de2 100644
--- a/documentation/research/Probabilistic data-structure.md
+++ b/documentation/research/Probabilistic data-structure.md
@@ -5,6 +5,7 @@
# Reference
+1. [Xor Filters: Faster and Smaller Than Bloom Filters](https://lemire.me/blog/2019/12/19/xor-filters-faster-and-smaller-than-bloom-filters/)
1. [Morton Filters: Faster, Space-Efficient Cuckoo Filters via Biasing, Compression, and Decoupled Logical Sparsity](http://www.vldb.org/pvldb/vol11/p1041-breslow.pdf)
1. https://github.com/efficient/SuRF
1. https://medium.com/orbs-network/constructing-bloom-filters-without-false-positives-7aaf50b92f3b
diff --git a/documentation/research/chemistry.md b/documentation/research/chemistry.md
new file mode 100644
index 000000000..96feafe20
--- /dev/null
+++ b/documentation/research/chemistry.md
@@ -0,0 +1,4 @@
+# Reference
+
+1. [Cando chemistry language](https://github.com/cando-developers/cando)
+
diff --git a/documentation/research/floating point.md b/documentation/research/floating point.md
new file mode 100644
index 000000000..9268449d9
--- /dev/null
+++ b/documentation/research/floating point.md
@@ -0,0 +1,4 @@
+# Algorithm
+
+1. [Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm)
+
diff --git a/documentation/research/game_programming.md b/documentation/research/game_programming.md
index 6f8c9f561..f1bcced0f 100644
--- a/documentation/research/game_programming.md
+++ b/documentation/research/game_programming.md
@@ -24,6 +24,7 @@
# Noise
+1. https://github.com/KdotJPG/New-Simplex-Style-Gradient-Noise
1. [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise)
1. [Gradient noise](https://en.wikipedia.org/wiki/Gradient_noise)
1. [Value noise](https://en.wikipedia.org/wiki/Value_noise)
diff --git a/documentation/research/math.md b/documentation/research/math.md
index 36071c92b..69f045c43 100644
--- a/documentation/research/math.md
+++ b/documentation/research/math.md
@@ -64,6 +64,7 @@
# _Compendium of resources_
+1. [Free and Open-Source Textbooks](http://danaernst.com/resources/free-and-open-source-textbooks/)
1. [ALL IN ONE MATHEMATICS CHEAT SHEET](https://ourway.keybase.pub/mathematics_cheat_sheet.pdf)
1. https://github.com/llSourcell/learn_math_fast
1. https://www.algorithm-archive.org/
diff --git a/documentation/research/operating_system.md b/documentation/research/operating_system.md
index 527d7d04f..dcd6c0977 100644
--- a/documentation/research/operating_system.md
+++ b/documentation/research/operating_system.md
@@ -18,6 +18,7 @@
## Operating system
+1. [CLOSOS: Specication of a Lisp operating system.](http://metamodular.com/closos.pdf)
1. https://medium.com/@jasonyuan/introducing-mercury-os-f4de45a04289
1. http://lsneff.me/why-nebulet/ ||| https://github.com/nebulet/nebulet
1. http://exposnitc.github.io/index.html
diff --git a/documentation/research/text_editor & ide.md b/documentation/research/text_editor & ide.md
index 0f6ccf128..5788c8003 100644
--- a/documentation/research/text_editor & ide.md
+++ b/documentation/research/text_editor & ide.md
@@ -129,6 +129,7 @@
# Collaborative editing
+1. https://github.com/gsilvamartin/RTCode
1. https://hackernoon.com/building-conclave-a-decentralized-real-time-collaborative-text-editor-a6ab438fe79f
1. https://github.com/xi-editor/xi-editor/issues/1187
diff --git a/new-luxc/source/luxc/lang/directive/jvm.lux b/new-luxc/source/luxc/lang/directive/jvm.lux
deleted file mode 100644
index 5c1ddee0d..000000000
--- a/new-luxc/source/luxc/lang/directive/jvm.lux
+++ /dev/null
@@ -1,263 +0,0 @@
-(.module:
- [lux (#- Type Definition)
- [abstract
- ["." monad (#+ do)]]
- [control
- ["<>" parser
- ["<c>" code (#+ Parser)]
- ["<t>" text]]]
- [data
- ["." product]
- [text
- ["%" format (#+ format)]]
- [collection
- ["." list ("#@." functor fold)]
- ["." dictionary]]]
- [type
- ["." check (#+ Check)]]
- [target
- [jvm
- ["." type (#+ Type Constraint Argument Typed)
- [category (#+ Void Value Return Method Primitive Object Class Array Var Parameter)]
- [".T" lux]
- ["." signature]
- ["." descriptor (#+ Descriptor)]
- ["." parser]]]]
- [tool
- [compiler
- ["." directive (#+ Handler Bundle)]
- ["." phase
- ["." generation]
- [analysis
- [".A" type]]
- ["." extension
- ["." bundle]
- [analysis
- ["." jvm]]
- [directive
- ["/" lux]]]]]]]
- [luxc
- [lang
- [host
- ["$" jvm (#+ Anchor Inst Definition Operation Phase)
- ["_." def]]]]])
-
-(def: signature (|>> type.signature signature.signature))
-
-(type: Declaration
- [Text (List (Type Var))])
-
-(def: declaration
- (Parser Declaration)
- (<c>.form (<>.and <c>.text (<>.some jvm.var))))
-
-(type: Inheritance
- #FinalI
- #AbstractI
- #DefaultI)
-
-(def: inheritance
- (Parser Inheritance)
- ($_ <>.or
- (<c>.text! "final")
- (<c>.text! "abstract")
- (<c>.text! "default")))
-
-(type: State
- #VolatileS
- #FinalS
- #DefaultS)
-
-(def: state
- (Parser State)
- ($_ <>.or
- (<c>.text! "volatile")
- (<c>.text! "final")
- (<c>.text! "default")))
-
-(type: Annotation Any)
-
-(def: annotation
- (Parser Annotation)
- <c>.any)
-
-(def: field-type
- (Parser (Type Value))
- (<t>.embed parser.value <c>.text))
-
-(type: Constant
- [Text (List Annotation) (Type Value) Code])
-
-(def: constant
- (Parser Constant)
- (<| <c>.form
- (<>.after (<c>.text! "constant"))
- ($_ <>.and
- <c>.text
- (<c>.tuple (<>.some ..annotation))
- ..field-type
- <c>.any
- )))
-
-(type: Variable
- [Text jvm.Visibility State (List Annotation) (Type Value)])
-
-(def: variable
- (Parser Variable)
- (<| <c>.form
- (<>.after (<c>.text! "variable"))
- ($_ <>.and
- <c>.text
- jvm.visibility
- ..state
- (<c>.tuple (<>.some ..annotation))
- ..field-type
- )))
-
-(type: Field
- (#Constant Constant)
- (#Variable Variable))
-
-(def: field
- (Parser Field)
- ($_ <>.or
- ..constant
- ..variable
- ))
-
-(type: Method-Definition
- (#Constructor (jvm.Constructor Code))
- (#Virtual-Method (jvm.Virtual-Method Code))
- (#Static-Method (jvm.Static-Method Code))
- (#Overriden-Method (jvm.Overriden-Method Code)))
-
-(def: method
- (Parser Method-Definition)
- ($_ <>.or
- jvm.constructor-definition
- jvm.virtual-method-definition
- jvm.static-method-definition
- jvm.overriden-method-definition
- ))
-
-(def: (constraint name)
- (-> Text Constraint)
- {#type.name name
- #type.super-class (type.class "java.lang.Object" (list))
- #type.super-interfaces (list)})
-
-(def: jvm::class
- (Handler Anchor Inst Definition)
- (/.custom
- [($_ <>.and
- ..declaration
- jvm.class
- (<c>.tuple (<>.some jvm.class))
- ..inheritance
- (<c>.tuple (<>.some ..annotation))
- (<c>.tuple (<>.some ..field))
- (<c>.tuple (<>.some ..method)))
- (function (_ extension phase
- [[name parameters]
- super-class
- super-interfaces
- inheritance
- ## TODO: Handle annotations.
- annotations
- fields
- methods])
- (do phase.monad
- [parameters (directive.lift-analysis
- (typeA.with-env
- (jvm.parameter-types parameters)))
- #let [mapping (list@fold (function (_ [parameterJ parameterT] mapping)
- (dictionary.put (parser.name parameterJ) parameterT mapping))
- luxT.fresh
- parameters)
- field-definitions (|> fields
- (list@map (function (_ field)
- (case field
- ## TODO: Handle annotations.
- (#Constant [name annotations type value])
- (case value
- (^template [<tag> <field>]
- [_ (<tag> value)]
- (<field> #$.Public ($.++F $.staticF $.finalF) name value))
- ([#.Bit _def.boolean-field]
- [#.Int _def.byte-field]
- [#.Int _def.short-field]
- [#.Int _def.int-field]
- [#.Int _def.long-field]
- [#.Frac _def.float-field]
- [#.Frac _def.double-field]
- [#.Nat _def.char-field]
- [#.Text _def.string-field])
-
- _
- (undefined))
-
- ## TODO: Handle annotations.
- (#Variable [name visibility state annotations type])
- (_def.field visibility
- (case state
- ## TODO: Handle transient & static.
- #VolatileS $.volatileF
- #FinalS $.finalF
- #DefaultS $.noneF)
- name
- type))))
- _def.fuse)]
- super-classT (directive.lift-analysis
- (typeA.with-env
- (luxT.check (luxT.class mapping) (..signature super-class))))
- super-interfaceT+ (directive.lift-analysis
- (typeA.with-env
- (monad.map check.monad
- (|>> ..signature (luxT.check (luxT.class mapping)))
- super-interfaces)))
- #let [selfT (jvm.inheritance-relationship-type (#.Primitive name (list@map product.right parameters))
- super-classT
- super-interfaceT+)]
- state (extension.lift phase.get-state)
- #let [analyse (get@ [#directive.analysis #directive.phase] state)
- synthesize (get@ [#directive.synthesis #directive.phase] state)
- generate (get@ [#directive.generation #directive.phase] state)]
- methods (monad.map @ (function (_ methodC)
- (do @
- [methodA (directive.lift-analysis
- (case methodC
- (#Constructor method)
- (jvm.analyse-constructor-method analyse selfT mapping method)
-
- (#Virtual-Method method)
- (jvm.analyse-virtual-method analyse selfT mapping method)
-
- (#Static-Method method)
- (jvm.analyse-static-method analyse mapping method)
-
- (#Overriden-Method method)
- (jvm.analyse-overriden-method analyse selfT mapping method)))]
- (directive.lift-synthesis
- (synthesize methodA))))
- methods)
- _ (directive.lift-generation
- (generation.save! true ["" name]
- [name
- (_def.class #$.V1_6 #$.Public
- (case inheritance
- #FinalI $.finalC
- ## TODO: Handle abstract classes.
- #AbstractI (undefined)
- #DefaultI $.noneC)
- name (list@map (|>> product.left parser.name ..constraint) parameters)
- super-class super-interfaces
- field-definitions)]))
- #let [_ (log! (format "Class " name))]]
- (wrap directive.no-requirements)))]))
-
-(def: #export bundle
- (Bundle Anchor Inst Definition)
- (<| (bundle.prefix "jvm")
- (|> bundle.empty
- (dictionary.put "class" jvm::class)
- )))
diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux
index f975d2a87..2b2278cec 100644
--- a/new-luxc/source/program.lux
+++ b/new-luxc/source/program.lux
@@ -1,5 +1,5 @@
(.module:
- [lux #*
+ [lux (#- Definition)
["@" target]
["." host (#+ import:)]
[abstract
@@ -19,33 +19,28 @@
["." file]]
[target
[jvm
- ["$t" type]]]
+ [bytecode (#+ Bytecode)]]]
[tool
[compiler
[phase
["." macro (#+ Expander)]
[extension (#+ Phase Bundle Operation Handler Extender)
["." analysis #_
- ["#" jvm]]]]
+ ["#" jvm]]
+ ["." directive #_
+ ["#" jvm]]]
+ ["." generation #_
+ ["#" jvm/extension]
+ ["." jvm
+ ["." runtime (#+ Anchor Definition)]
+ ["#/." program]
+ ["." packager]
+ ["#/." host]]]]
[default
["." platform (#+ Platform)]]]]]
[program
["/" compositor
- ["/." cli]]]
- [luxc
- [lang
- ["." packager]
- [host
- ["_" jvm
- ["$d" def]
- ["$i" inst]]]
- ["." directive #_
- ["#" jvm]]
- [translation
- ["." jvm
- ["." runtime]
- ["." expression]
- ["translation" extension]]]]])
+ ["/." cli]]])
(import: #long java/lang/reflect/Method
(invoke [java/lang/Object [java/lang/Object]] #try java/lang/Object))
@@ -90,81 +85,14 @@
apply-method))))
(def: #export platform
- (IO (Platform IO _.Anchor _.Inst _.Definition))
+ (IO (Platform IO Anchor (Bytecode Any) Definition))
(do io.monad
- [host jvm.host]
+ [host jvm/host.host]
(wrap {#platform.&monad io.monad
#platform.&file-system file.system
#platform.host host
- #platform.phase expression.translate
- #platform.runtime runtime.translate})))
-
-(def: program-class "LuxProgram")
-
-(def: #export (program programI)
- (-> _.Inst _.Definition)
- (let [$Object ($t.class "java.lang.Object" (list))
- nilI runtime.noneI
- num-inputsI (|>> ($i.ALOAD 0) $i.ARRAYLENGTH)
- decI (|>> ($i.int +1) $i.ISUB)
- headI (|>> $i.DUP
- ($i.ALOAD 0)
- $i.SWAP
- $i.AALOAD
- $i.SWAP
- $i.DUP_X2
- $i.POP)
- pairI (|>> ($i.int +2)
- ($i.ANEWARRAY $Object)
- $i.DUP_X1
- $i.SWAP
- ($i.int +0)
- $i.SWAP
- $i.AASTORE
- $i.DUP_X1
- $i.SWAP
- ($i.int +1)
- $i.SWAP
- $i.AASTORE)
- consI (|>> ($i.int +1)
- ($i.string "")
- $i.DUP2_X1
- $i.POP2
- runtime.variantI)
- prepare-input-listI (<| $i.with-label (function (_ @loop))
- $i.with-label (function (_ @end))
- (|>> nilI
- num-inputsI
- ($i.label @loop)
- decI
- $i.DUP
- ($i.IFLT @end)
- headI
- pairI
- consI
- $i.SWAP
- ($i.GOTO @loop)
- ($i.label @end)
- $i.POP))
- feed-inputsI ($i.INVOKEVIRTUAL jvm.$Function runtime.apply-method (runtime.apply-signature 1))
- run-ioI (|>> ($i.CHECKCAST jvm.$Function)
- $i.NULL
- ($i.INVOKEVIRTUAL jvm.$Function runtime.apply-method (runtime.apply-signature 1)))
- main-type ($t.method [(list ($t.array ($t.class "java.lang.String" (list))))
- $t.void
- (list)])]
- [..program-class
- ($d.class #_.V1_6
- #_.Public _.finalC
- ..program-class
- (list) $Object
- (list)
- (|>> ($d.method #_.Public _.staticM "main" main-type
- (|>> programI
- prepare-input-listI
- feed-inputsI
- run-ioI
- $i.RETURN))))]))
+ #platform.phase jvm.generate
+ #platform.runtime runtime.generate})))
(def: extender
Extender
@@ -204,9 +132,9 @@
..expander
analysis.bundle
..platform
- translation.bundle
+ generation.bundle
directive.bundle
- ..program
+ jvm/program.program
..extender
service
- [(packager.package ..program-class) jar-path])))
+ [(packager.package jvm/program.class) jar-path])))
diff --git a/stdlib/source/lux/target/jvm/attribute.lux b/stdlib/source/lux/target/jvm/attribute.lux
index 5f8892631..083ebaa15 100644
--- a/stdlib/source/lux/target/jvm/attribute.lux
+++ b/stdlib/source/lux/target/jvm/attribute.lux
@@ -49,7 +49,7 @@
(with-expansions [<Code> (as-is (/code.Code Attribute))]
(type: #export #rec Attribute
- (#Constant (Info Constant))
+ (#Constant (Info (Constant Any)))
(#Code (Info <Code>)))
(type: #export Code
@@ -64,7 +64,7 @@
(info-equivalence /constant.equivalence)
(info-equivalence (/code.equivalence equivalence))))))
-(def: fixed-attribute-length
+(def: common-attribute-length
($_ n.+
## u2 attribute_name_index;
//unsigned.bytes/2
@@ -77,25 +77,23 @@
(case attribute
(^template [<tag>]
(<tag> [name length info])
- (|> length //unsigned.value (n.+ fixed-attribute-length)))
+ (|> length //unsigned.value (n.+ ..common-attribute-length)))
([#Constant] [#Code])))
-(def: constant-name "ConstantValue")
-
+## TODO: Inline ASAP
(def: (constant' @name index)
- (-> (Index UTF8) Constant Attribute)
+ (-> (Index UTF8) (Constant Any) Attribute)
(#Constant {#name @name
#length (|> /constant.length //unsigned.u4 try.assume)
#info index}))
(def: #export (constant index)
- (-> Constant (Resource Attribute))
+ (-> (Constant Any) (Resource Attribute))
(do //constant/pool.monad
- [@name (//constant/pool.utf8 ..constant-name)]
+ [@name (//constant/pool.utf8 "ConstantValue")]
(wrap (constant' @name index))))
-(def: code-name "Code")
-
+## TODO: Inline ASAP
(def: (code' @name specification)
(-> (Index UTF8) Code Attribute)
(#Code {#name @name
@@ -109,7 +107,7 @@
(def: #export (code specification)
(-> Code (Resource Attribute))
(do //constant/pool.monad
- [@name (//constant/pool.utf8 ..code-name)]
+ [@name (//constant/pool.utf8 "Code")]
(wrap (code' @name specification))))
(def: #export (writer value)
diff --git a/stdlib/source/lux/target/jvm/attribute/constant.lux b/stdlib/source/lux/target/jvm/attribute/constant.lux
index 0206ed26e..c5605bcc3 100644
--- a/stdlib/source/lux/target/jvm/attribute/constant.lux
+++ b/stdlib/source/lux/target/jvm/attribute/constant.lux
@@ -11,16 +11,16 @@
[encoding
["#." unsigned (#+ U2 U4)]]])
-(type: #export Constant
- (Index Value))
+(type: #export (Constant a)
+ (Index (Value a)))
(def: #export equivalence
- (Equivalence Constant)
+ (All [a] (Equivalence (Constant a)))
///index.equivalence)
(def: #export length
///index.length)
(def: #export writer
- (Writer Constant)
+ (All [a] (Writer (Constant a)))
///index.writer)
diff --git a/stdlib/source/lux/target/jvm/bytecode.lux b/stdlib/source/lux/target/jvm/bytecode.lux
index 5ad3d2204..a31b90195 100644
--- a/stdlib/source/lux/target/jvm/bytecode.lux
+++ b/stdlib/source/lux/target/jvm/bytecode.lux
@@ -219,17 +219,6 @@
[@4 5]
)
-(def: discontinuity!
- (Bytecode Any)
- (function (_ [pool environment tracker])
- (do try.monad
- [_ (/environment.stack environment)]
- (#try.Success [[pool
- (/environment.discontinue environment)
- tracker]
- [..relative-identity
- []]]))))
-
(template [<name> <consumption> <production> <registry> <instruction>]
[(def: #export <name>
(Bytecode Any)
@@ -414,6 +403,17 @@
[monitorexit $1 $0 @_ _.monitorexit]
)
+(def: discontinuity!
+ (Bytecode Any)
+ (function (_ [pool environment tracker])
+ (do try.monad
+ [_ (/environment.stack environment)]
+ (#try.Success [[pool
+ (/environment.discontinue environment)
+ tracker]
+ [..relative-identity
+ []]]))))
+
(template [<name> <consumption> <instruction>]
[(def: #export <name>
(Bytecode Any)
diff --git a/stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux
new file mode 100644
index 000000000..4db15e8e6
--- /dev/null
+++ b/stdlib/source/lux/tool/compiler/phase/extension/directive/jvm.lux
@@ -0,0 +1,303 @@
+(.module:
+ [lux (#- Type Definition)
+ ["." host]
+ [abstract
+ ["." monad (#+ do)]]
+ [control
+ [pipe (#+ case>)]
+ ["<>" parser ("#@." monad)
+ ["<c>" code (#+ Parser)]
+ ["<t>" text]]]
+ [data
+ ["." product]
+ [number
+ ["." i32]]
+ [text
+ ["%" format (#+ format)]]
+ [collection
+ ["." list ("#@." functor fold)]
+ ["." dictionary]
+ ["." row]]]
+ [type
+ ["." check (#+ Check)]]
+ [macro
+ ["." template]]
+ [target
+ [jvm
+ ["_" bytecode (#+ Bytecode)]
+ ["." modifier (#+ Modifier) ("#@." monoid)]
+ ["." attribute]
+ ["." field]
+ ["." version]
+ ["." class]
+ ["." constant
+ ["." pool (#+ Resource)]]
+ [encoding
+ ["." name]]
+ ["." type (#+ Type Constraint Argument Typed)
+ [category (#+ Void Value Return Method Primitive Object Class Array Var Parameter)]
+ [".T" lux (#+ Mapping)]
+ ["." signature]
+ ["." descriptor (#+ Descriptor)]
+ ["." parser]]]]
+ [tool
+ [compiler
+ ["." analysis]
+ ["." synthesis]
+ ["." directive (#+ Handler Bundle)]
+ ["." phase
+ [analysis
+ [".A" type]]
+ ["." generation
+ [jvm
+ [runtime (#+ Anchor Definition)]]]
+ ["." extension
+ ["." bundle]
+ [analysis
+ ["." jvm]]
+ [directive
+ ["/" lux]]]]]]])
+
+(type: Operation
+ (directive.Operation Anchor (Bytecode Any) Definition))
+
+(def: signature (|>> type.signature signature.signature))
+
+(type: Declaration
+ [Text (List (Type Var))])
+
+(def: declaration
+ (Parser Declaration)
+ (<c>.form (<>.and <c>.text (<>.some jvm.var))))
+
+(def: visibility
+ (Parser (Modifier field.Field))
+ (`` ($_ <>.either
+ (~~ (template [<label> <modifier>]
+ [(<>.after (<c>.text! <label>) (<>@wrap <modifier>))]
+
+ ["public" field.public]
+ ["private" field.private]
+ ["protected" field.protected]
+ ["default" modifier.empty])))))
+
+(def: inheritance
+ (Parser (Modifier class.Class))
+ (`` ($_ <>.either
+ (~~ (template [<label> <modifier>]
+ [(<>.after (<c>.text! <label>) (<>@wrap <modifier>))]
+
+ ["final" class.final]
+ ["abstract" class.abstract]
+ ["default" modifier.empty])))))
+
+(def: state
+ (Parser (Modifier field.Field))
+ (`` ($_ <>.either
+ (~~ (template [<label> <modifier>]
+ [(<>.after (<c>.text! <label>) (<>@wrap <modifier>))]
+
+ ["volatile" field.volatile]
+ ["final" field.final]
+ ["default" modifier.empty])))))
+
+(type: Annotation Any)
+
+(def: annotation
+ (Parser Annotation)
+ <c>.any)
+
+(def: field-type
+ (Parser (Type Value))
+ (<t>.embed parser.value <c>.text))
+
+(type: Constant
+ [Text (List Annotation) (Type Value) Code])
+
+(def: constant
+ (Parser Constant)
+ (<| <c>.form
+ (<>.after (<c>.text! "constant"))
+ ($_ <>.and
+ <c>.text
+ (<c>.tuple (<>.some ..annotation))
+ ..field-type
+ <c>.any
+ )))
+
+(type: Variable
+ [Text (Modifier field.Field) (Modifier field.Field) (List Annotation) (Type Value)])
+
+(def: variable
+ (Parser Variable)
+ (<| <c>.form
+ (<>.after (<c>.text! "variable"))
+ ($_ <>.and
+ <c>.text
+ ..visibility
+ ..state
+ (<c>.tuple (<>.some ..annotation))
+ ..field-type
+ )))
+
+(type: Field
+ (#Constant Constant)
+ (#Variable Variable))
+
+(def: field
+ (Parser Field)
+ ($_ <>.or
+ ..constant
+ ..variable
+ ))
+
+(type: Method-Definition
+ (#Constructor (jvm.Constructor Code))
+ (#Virtual-Method (jvm.Virtual-Method Code))
+ (#Static-Method (jvm.Static-Method Code))
+ (#Overriden-Method (jvm.Overriden-Method Code)))
+
+(def: method
+ (Parser Method-Definition)
+ ($_ <>.or
+ jvm.constructor-definition
+ jvm.virtual-method-definition
+ jvm.static-method-definition
+ jvm.overriden-method-definition
+ ))
+
+(def: (constraint name)
+ (-> Text Constraint)
+ {#type.name name
+ #type.super-class (type.class "java.lang.Object" (list))
+ #type.super-interfaces (list)})
+
+(def: constant::modifier
+ (Modifier field.Field)
+ ($_ modifier@compose
+ field.public
+ field.static
+ field.final))
+
+(def: (field-definition field)
+ (-> Field (Resource field.Field))
+ (case field
+ ## TODO: Handle annotations.
+ (#Constant [name annotations type value])
+ (case value
+ (^template [<tag> <type> <constant>]
+ [_ (<tag> value)]
+ (do pool.monad
+ [constant (`` (|> value (~~ (template.splice <constant>))))
+ attribute (attribute.constant constant)]
+ (field.field ..constant::modifier name <type> (row.row attribute))))
+ ([#.Bit type.boolean [(case> #0 +0 #1 +1) .i64 i32.i32 constant.integer pool.integer]]
+ [#.Int type.byte [.i64 i32.i32 constant.integer pool.integer]]
+ [#.Int type.short [.i64 i32.i32 constant.integer pool.integer]]
+ [#.Int type.int [.i64 i32.i32 constant.integer pool.integer]]
+ [#.Int type.long [constant.long pool.long]]
+ [#.Frac type.float [host.double-to-float constant.float pool.float]]
+ [#.Frac type.double [constant.double pool.double]]
+ [#.Nat type.char [.i64 i32.i32 constant.integer pool.integer]]
+ [#.Text (type.class "java.lang.String" (list)) [pool.string]]
+ )
+
+ ## TODO: Tighten this pattern-matching so this catch-all clause isn't necessary.
+ _
+ (undefined))
+
+ ## TODO: Handle annotations.
+ (#Variable [name visibility state annotations type])
+ (field.field (modifier@compose visibility state)
+ name type (row.row))))
+
+(def: (method-definition [mapping selfT] [analyse synthesize generate])
+ (-> [Mapping .Type]
+ [analysis.Phase
+ synthesis.Phase
+ (generation.Phase Anchor (Bytecode Any) Definition)]
+ (-> Method-Definition (Operation synthesis.Synthesis)))
+ (function (_ methodC)
+ (do phase.monad
+ [methodA (: (Operation analysis.Analysis)
+ (directive.lift-analysis
+ (case methodC
+ (#Constructor method)
+ (jvm.analyse-constructor-method analyse selfT mapping method)
+
+ (#Virtual-Method method)
+ (jvm.analyse-virtual-method analyse selfT mapping method)
+
+ (#Static-Method method)
+ (jvm.analyse-static-method analyse mapping method)
+
+ (#Overriden-Method method)
+ (jvm.analyse-overriden-method analyse selfT mapping method))))]
+ (directive.lift-synthesis
+ (synthesize methodA)))))
+
+(def: jvm::class
+ (Handler Anchor (Bytecode Any) Definition)
+ (/.custom
+ [($_ <>.and
+ ..declaration
+ jvm.class
+ (<c>.tuple (<>.some jvm.class))
+ ..inheritance
+ (<c>.tuple (<>.some ..annotation))
+ (<c>.tuple (<>.some ..field))
+ (<c>.tuple (<>.some ..method)))
+ (function (_ extension phase
+ [[name parameters]
+ super-class
+ super-interfaces
+ inheritance
+ ## TODO: Handle annotations.
+ annotations
+ fields
+ methods])
+ (do phase.monad
+ [parameters (directive.lift-analysis
+ (typeA.with-env
+ (jvm.parameter-types parameters)))
+ #let [mapping (list@fold (function (_ [parameterJ parameterT] mapping)
+ (dictionary.put (parser.name parameterJ) parameterT mapping))
+ luxT.fresh
+ parameters)]
+ super-classT (directive.lift-analysis
+ (typeA.with-env
+ (luxT.check (luxT.class mapping) (..signature super-class))))
+ super-interfaceT+ (directive.lift-analysis
+ (typeA.with-env
+ (monad.map check.monad
+ (|>> ..signature (luxT.check (luxT.class mapping)))
+ super-interfaces)))
+ #let [selfT (jvm.inheritance-relationship-type (#.Primitive name (list@map product.right parameters))
+ super-classT
+ super-interfaceT+)]
+ state (extension.lift phase.get-state)
+ #let [analyse (get@ [#directive.analysis #directive.phase] state)
+ synthesize (get@ [#directive.synthesis #directive.phase] state)
+ generate (get@ [#directive.generation #directive.phase] state)]
+ methods (monad.map @ (..method-definition [mapping selfT] [analyse synthesize generate])
+ methods)
+ ## _ (directive.lift-generation
+ ## (generation.save! true ["" name]
+ ## [name
+ ## (class.class version.v6_0
+ ## (modifier@compose class.public inheritance)
+ ## (name.internal name) (list@map (|>> product.left parser.name ..constraint) parameters)
+ ## super-class super-interfaces
+ ## (list@map ..field-definition fields)
+ ## (list) ## TODO: Add methods
+ ## (row.row))]))
+ #let [_ (log! (format "Class " name))]]
+ (wrap directive.no-requirements)))]))
+
+(def: #export bundle
+ (Bundle Anchor (Bytecode Any) Definition)
+ (<| (bundle.prefix "jvm")
+ (|> bundle.empty
+ ## TODO: Finish handling methods and un-comment.
+ ## (dictionary.put "class" jvm::class)
+ )))
diff --git a/new-luxc/source/luxc/lang/translation/jvm.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/host.lux
index fccbd14bf..2892ac045 100644
--- a/new-luxc/source/luxc/lang/translation/jvm.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/host.lux
@@ -17,39 +17,47 @@
["%" format (#+ format)]]
[collection
["." array]
- ["." dictionary (#+ Dictionary)]]]
+ ["." dictionary (#+ Dictionary)]
+ ["." row]]
+ ["." format #_
+ ["#" binary]]]
[target
[jvm
["." loader (#+ Library)]
+ ["_" bytecode (#+ Bytecode)]
+ ["." modifier (#+ Modifier) ("#@." monoid)]
+ ["." field (#+ Field)]
+ ["." method (#+ Method)]
+ ["." version]
+ ["." class (#+ Class)]
+ ["." encoding #_
+ ["#/." name]]
["." type
["." descriptor]]]]
[tool
[compiler
["." name]]]]
- [///
- [host
- ["." jvm (#+ Inst Definition Host State)
- ["." def]
- ["." inst]]]]
+ ["." // #_
+ ["#." runtime (#+ Definition)]]
)
-(import: org/objectweb/asm/Label)
+(import: #long java/lang/reflect/Field
+ (get [#? java/lang/Object] #try #? java/lang/Object))
-(import: java/lang/reflect/Field
- (get [#? Object] #try #? Object))
+(import: #long (java/lang/Class a)
+ (getField [java/lang/String] #try java/lang/reflect/Field))
-(import: (java/lang/Class a)
- (getField [String] #try Field))
+(import: #long java/lang/Object
+ (getClass [] (java/lang/Class java/lang/Object)))
-(import: java/lang/Object
- (getClass [] (Class Object)))
+(import: #long java/lang/ClassLoader)
-(import: java/lang/ClassLoader)
+(def: value::field "_value")
+(def: value::type (type.class "java.lang.Object" (list)))
+(def: value::modifier ($_ modifier@compose field.public field.final field.static))
-(type: #export ByteCode Binary)
-
-(def: #export value-field Text "_value")
-(def: #export $Value (type.class "java.lang.Object" (list)))
+(def: init::type (type.method [(list) type.void (list)]))
+(def: init::modifier ($_ modifier@compose method.public method.static method.strict))
(exception: #export (cannot-load {class Text} {error Text})
(exception.report
@@ -67,51 +75,53 @@
["Class" class]))
(def: (class-value class-name class)
- (-> Text (Class Object) (Try Any))
- (case (Class::getField ..value-field class)
+ (-> Text (java/lang/Class java/lang/Object) (Try Any))
+ (case (java/lang/Class::getField ..value::field class)
(#try.Success field)
- (case (Field::get #.None field)
+ (case (java/lang/reflect/Field::get #.None field)
(#try.Success ?value)
(case ?value
(#.Some value)
(#try.Success value)
#.None
- (exception.throw invalid-value class-name))
+ (exception.throw ..invalid-value [class-name]))
(#try.Failure error)
- (exception.throw cannot-load [class-name error]))
+ (exception.throw ..cannot-load [class-name error]))
(#try.Failure error)
- (exception.throw invalid-field [class-name ..value-field error])))
+ (exception.throw ..invalid-field [class-name ..value::field error])))
(def: class-path-separator ".")
-(def: (evaluate! library loader eval-class valueI)
- (-> Library ClassLoader Text Inst (Try [Any Definition]))
+(def: (evaluate! library loader eval-class valueG)
+ (-> Library java/lang/ClassLoader Text (Bytecode Any) (Try [Any Definition]))
(let [bytecode-name (text.replace-all class-path-separator .module-separator eval-class)
- bytecode (def.class #jvm.V1_6
- #jvm.Public jvm.noneC
- bytecode-name
- (list) $Value
- (list)
- (|>> (def.field #jvm.Public ($_ jvm.++F jvm.finalF jvm.staticF)
- ..value-field ..$Value)
- (def.method #jvm.Public ($_ jvm.++M jvm.staticM jvm.strictM)
- "<clinit>"
- (type.method [(list) type.void (list)])
- (|>> valueI
- (inst.PUTSTATIC (type.class bytecode-name (list)) ..value-field ..$Value)
- inst.RETURN))))]
+ bytecode (class.class version.v6_0
+ class.public
+ (encoding/name.internal bytecode-name)
+ (encoding/name.internal "java.lang.Object") (list)
+ (list (field.field ..value::modifier ..value::field ..value::type (row.row)))
+ (list (method.method ..init::modifier "<clinit>" ..init::type
+ (list)
+ (#.Some
+ ($_ _.compose
+ valueG
+ (_.putstatic (type.class bytecode-name (list)) ..value::field ..value::type)
+ _.return))))
+ (row.row))]
(io.run (do (try.with io.monad)
- [_ (loader.store eval-class bytecode library)
+ [bytecode (:: @ map (format.run class.writer)
+ (io.io bytecode))
+ _ (loader.store eval-class bytecode library)
class (loader.load eval-class loader)
value (:: io.monad wrap (class-value eval-class class))]
(wrap [value
[eval-class bytecode]])))))
(def: (execute! library loader temp-label [class-name class-bytecode])
- (-> Library ClassLoader Text Definition (Try Any))
+ (-> Library java/lang/ClassLoader Text Definition (Try Any))
(io.run (do (try.with io.monad)
[existing-class? (|> (atom.read library)
(:: io.monad map (dictionary.contains? class-name))
@@ -122,33 +132,28 @@
(loader.store class-name class-bytecode library))]
(loader.load class-name loader))))
-(def: (define! library loader [module name] valueI)
- (-> Library ClassLoader Name Inst (Try [Text Any Definition]))
+(def: (define! library loader [module name] valueG)
+ (-> Library java/lang/ClassLoader Name (Bytecode Any) (Try [Text Any Definition]))
(let [class-name (format (text.replace-all .module-separator class-path-separator module)
class-path-separator (name.normalize name)
"___" (%.nat (text@hash name)))]
(do try.monad
- [[value definition] (evaluate! library loader class-name valueI)]
+ [[value definition] (evaluate! library loader class-name valueG)]
(wrap [class-name value definition]))))
(def: #export host
- (IO Host)
+ (IO //runtime.Host)
(io (let [library (loader.new-library [])
loader (loader.memory library)]
- (: Host
+ (: //runtime.Host
(structure
- (def: (evaluate! temp-label valueI)
+ (def: (evaluate! temp-label valueG)
(let [eval-class (|> temp-label name.normalize (text.replace-all " " "$"))]
(:: try.monad map product.left
- (..evaluate! library loader eval-class valueI))))
+ (..evaluate! library loader eval-class valueG))))
(def: execute!
(..execute! library loader))
(def: define!
(..define! library loader)))))))
-
-(def: #export $Variant (type.array ..$Value))
-(def: #export $Tuple (type.array ..$Value))
-(def: #export $Function (type.class "LuxFunction" (list)))
-(def: #export $Runtime (type.class "LuxRuntime" (list)))
diff --git a/new-luxc/source/luxc/lang/packager.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/packager.lux
index d72506da2..9400adf1a 100644
--- a/new-luxc/source/luxc/lang/packager.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/packager.lux
@@ -1,5 +1,5 @@
(.module:
- [lux #*
+ [lux (#- Module Definition)
["." host (#+ import: do-to)]
[data
["." binary (#+ Binary)]
@@ -16,13 +16,12 @@
[tool
[compiler
[phase
- [generation (#+ Buffer Output)]]
+ [generation (#+ Buffer Output)
+ [jvm
+ [runtime (#+ Definition)]]]]
[meta
[archive
- [descriptor (#+ Module)]]]]]]
- [//
- [host
- [jvm (#+ Definition)]]])
+ [descriptor (#+ Module)]]]]]])
(import: #long java/lang/Object)
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/program.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/program.lux
new file mode 100644
index 000000000..c5f10a9a6
--- /dev/null
+++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/program.lux
@@ -0,0 +1,143 @@
+(.module:
+ [lux (#- Definition)
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["." try]]
+ [data
+ [collection
+ ["." row]]
+ ["." format #_
+ ["#" binary]]]
+ [target
+ [jvm
+ ["_" bytecode (#+ Bytecode)]
+ ["." modifier (#+ Modifier) ("#@." monoid)]
+ ["." method (#+ Method)]
+ ["." version]
+ ["." class (#+ Class)]
+ [encoding
+ ["." name]]
+ ["." type
+ ["." reflection]]]]]
+ ["." //
+ ["#." runtime (#+ Definition)]
+ ["#." function/abstract]])
+
+(def: #export class "LuxProgram")
+
+(def: ^Object (type.class "java.lang.Object" (list)))
+(def: ^String (type.class "java.lang.String" (list)))
+(def: ^Args (type.array ^String))
+
+(def: main::type (type.method [(list ..^Args) type.void (list)]))
+
+(def: main::modifier
+ (Modifier Method)
+ ($_ modifier@compose
+ method.public
+ method.static
+ method.strict
+ ))
+
+(def: program::modifier
+ (Modifier Class)
+ ($_ modifier@compose
+ class.public
+ class.final
+ ))
+
+(def: nil //runtime.none-injection)
+
+(def: amount-of-inputs
+ (Bytecode Any)
+ ($_ _.compose
+ _.aload-0
+ _.arraylength))
+
+(def: decrease
+ (Bytecode Any)
+ ($_ _.compose
+ _.iconst-1
+ _.isub))
+
+(def: head
+ (Bytecode Any)
+ ($_ _.compose
+ _.dup
+ _.aload-0
+ _.swap
+ _.aaload
+ _.swap
+ _.dup-x2
+ _.pop))
+
+(def: pair
+ (Bytecode Any)
+ ($_ _.compose
+ _.iconst-2
+ (_.anewarray ^Object)
+ _.dup-x1
+ _.swap
+ _.iconst-0
+ _.swap
+ _.aastore
+ _.dup-x1
+ _.swap
+ _.iconst-1
+ _.swap
+ _.aastore))
+
+(def: cons //runtime.right-injection)
+
+(def: input-list
+ (Bytecode Any)
+ (do _.monad
+ [@loop _.new-label
+ @end _.new-label]
+ ($_ _.compose
+ ..nil
+ ..amount-of-inputs
+ (_.set-label @loop)
+ ..decrease
+ _.dup
+ (_.iflt @end)
+ ..head
+ ..pair
+ ..cons
+ _.swap
+ (_.goto @loop)
+ (_.set-label @end)
+ _.pop)))
+
+(def: feed-inputs //runtime.apply)
+
+(def: run-io
+ (Bytecode Any)
+ ($_ _.compose
+ (_.checkcast //function/abstract.class)
+ _.aconst-null
+ //runtime.apply))
+
+(def: #export (program program)
+ (-> (Bytecode Any) Definition)
+ (let [super-class (|> ..^Object type.reflection reflection.reflection name.internal)
+ main (method.method ..main::modifier "main" ..main::type
+ (list)
+ (#.Some ($_ _.compose
+ program
+ ..input-list
+ ..feed-inputs
+ ..run-io
+ _.return)))]
+ [..class
+ (<| (format.run class.writer)
+ try.assume
+ (class.class version.v6_0
+ ..program::modifier
+ (name.internal ..class)
+ super-class
+ (list)
+ (list)
+ (list main)
+ (row.row)))]))
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux
index f2349ff41..3ed3ecb52 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm/runtime.lux
@@ -67,6 +67,9 @@
(type: #export (Generator i)
(-> Phase i (Operation (Bytecode Any))))
+(type: #export Host
+ (///.Host (Bytecode Any) Definition))
+
(def: #export class (type.class "LuxRuntime" (list)))
(def: procedure
@@ -180,7 +183,7 @@
(def: #export decode-frac (..procedure ..decode-frac::name ..decode-frac::type))
(def: decode-frac::method
- (method.method ..modifier ..variant::name
+ (method.method ..modifier ..decode-frac::name
..variant::type
(list)
(#.Some
@@ -492,7 +495,7 @@
(def: ^Object (type.class "java.lang.Object" (list)))
-(def: translate-runtime
+(def: generate-runtime
(Operation Any)
(let [class (..reflection ..class)
modifier (: (Modifier Class)
@@ -524,7 +527,7 @@
[_ (///.execute! class [class bytecode])]
(///.save! .false ["" class] [class bytecode]))))
-(def: translate-function
+(def: generate-function
(Operation Any)
(let [apply::method+ (|> (list.n/range (inc //function/arity.minimum)
//function/arity.maximum)
@@ -542,7 +545,7 @@
(_.aload arity)
(_.invokevirtual //function.class ..apply::name (..apply::type //function/arity.minimum))
_.areturn))))))
- (list& (method.method (modifier@compose method.public method.abstract)
+ (list& (method.method method.public
..apply::name (..apply::type //function/arity.minimum)
(list)
## TODO: It shouldn't be necessary to set the code for this method, since it's abstract.
@@ -586,11 +589,11 @@
[_ (///.execute! class [class bytecode])]
(///.save! .false ["" class] [class bytecode]))))
-(def: #export translate
+(def: #export generate
(Operation Any)
(do ////.monad
- [_ ..translate-runtime]
- ..translate-function))
+ [_ ..generate-runtime]
+ ..generate-function))
(def: #export forge-label
(Operation Label)