aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm.lux53
1 files changed, 33 insertions, 20 deletions
diff --git a/new-luxc/source/luxc/lang/translation/jvm.lux b/new-luxc/source/luxc/lang/translation/jvm.lux
index f98438902..12bf96631 100644
--- a/new-luxc/source/luxc/lang/translation/jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm.lux
@@ -40,18 +40,16 @@
["." inst]]]]
)
-(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: java/lang/ClassLoader)
+(import: #long java/lang/ClassLoader)
(type: #export ByteCode Binary)
@@ -74,23 +72,23 @@
["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 ".")
@@ -103,7 +101,7 @@
(format lux-context "." (%.nat module-id) ..class-path-separator (%.nat artifact-id)))
(def: (evaluate! library loader eval-class valueI)
- (-> Library ClassLoader Text Inst (Try [Any Definition]))
+ (-> Library java/lang/ClassLoader Text Inst (Try [Any Definition]))
(let [bytecode-name (..bytecode-name eval-class)
bytecode (def.class #jvm.V1_6
#jvm.Public jvm.noneC
@@ -121,12 +119,12 @@
(io.run (do (try.with io.monad)
[_ (loader.store eval-class bytecode library)
class (loader.load eval-class loader)
- value (:: io.monad wrap (class-value eval-class class))]
+ 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))
@@ -138,7 +136,7 @@
(loader.load class-name loader))))
(def: (define! library loader context valueI)
- (-> Library ClassLoader generation.Context Inst (Try [Text Any Definition]))
+ (-> Library java/lang/ClassLoader generation.Context Inst (Try [Text Any Definition]))
(let [class-name (..class-name context)]
(do try.monad
[[value definition] (evaluate! library loader class-name valueI)]
@@ -158,7 +156,22 @@
(..execute! library loader))
(def: define!
- (..define! library loader)))))))
+ (..define! library loader))
+
+ (def: (ingest context bytecode)
+ [(..class-name context) bytecode])
+
+ (def: (re-learn context [_ bytecode])
+ (io.run
+ (loader.store (..class-name context) bytecode library)))
+
+ (def: (re-load context [_ bytecode])
+ (io.run
+ (do (try.with io.monad)
+ [#let [class-name (..class-name context)]
+ _ (loader.store class-name bytecode library)
+ class (loader.load class-name loader)]
+ (:: io.monad wrap (..class-value class-name class))))))))))
(def: #export $Variant (type.array ..$Value))
(def: #export $Tuple (type.array ..$Value))