aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/jvm.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-12-24 23:05:30 -0400
committerEduardo Julian2019-12-24 23:05:30 -0400
commitfa37f5d17184db1ed95949352e71542af8fb4ce1 (patch)
treec75422049da941ea1f0e61d72b263cb38ed072e2 /new-luxc/source/luxc/lang/translation/jvm.lux
parent2690a6ba8ff7998f8dbb778b93fa22976eadb4ac (diff)
Ported program generation, host environment and packaging machinery to stdlib.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/jvm/host.lux (renamed from new-luxc/source/luxc/lang/translation/jvm.lux)111
1 files changed, 58 insertions, 53 deletions
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)))