aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2016-06-13 23:15:32 -0400
committerEduardo Julian2016-06-13 23:15:32 -0400
commit7caca63387e14d3a6202120f75ae0056f9ddc17f (patch)
treed758f85f7d28e41d21b4e81cb819ea29eb2471a7 /src
parentc711eb3f90ea3a160b662f8bc5e16306db57c197 (diff)
- Implemented a procedure for loading JVM classes.
Diffstat (limited to '')
-rw-r--r--src/lux/analyser/host.clj14
-rw-r--r--src/lux/compiler/host.clj10
2 files changed, 24 insertions, 0 deletions
diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj
index a677b7973..9cf23b44a 100644
--- a/src/lux/analyser/host.clj
+++ b/src/lux/analyser/host.clj
@@ -858,6 +858,19 @@
(return (&/|list (&&/|meta output-type _cursor
(&&/$proc (&/T ["jvm" "instanceof"]) (&/|list =object) (&/|list class)))))))
+(defn ^:private analyse-jvm-load-class [analyse exo-type ?values]
+ (|do [:let [(&/$Cons [_ (&/$TextS _class-name)] (&/$Nil)) ?values]
+ class-loader &/loader
+ _ (try (do (.loadClass class-loader _class-name)
+ (return nil))
+ (catch Exception e
+ (&/fail-with-loc (str "[Analyser Error] Unknown class: " _class-name))))
+ :let [output-type (&/$HostT "java.lang.Class" (&/|list (&/$HostT _class-name (&/|list))))]
+ _ (&type/check exo-type output-type)
+ _cursor &/cursor]
+ (return (&/|list (&&/|meta output-type _cursor
+ (&&/$proc (&/T ["jvm" "load-class"]) (&/|list) (&/|list _class-name output-type)))))))
+
(let [length-type &type/Int
idx-type &type/Int]
(defn ^:private analyse-array-new [analyse exo-type ?values]
@@ -991,6 +1004,7 @@
"jvm"
(case proc
+ "load-class" (analyse-jvm-load-class analyse exo-type ?values)
"try" (analyse-jvm-try analyse exo-type ?values)
"throw" (analyse-jvm-throw analyse exo-type ?values)
"monitorenter" (analyse-jvm-monitorenter analyse exo-type ?values)
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index 20194d338..d94ca9dbd 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -1287,6 +1287,15 @@
:let [_ (.visitLabel *writer* $end)]]
(return nil)))
+(defn ^:private compile-jvm-load-class [compile ?values special-args]
+ (|do [:let [(&/$Cons _class-name (&/$Cons ?output-type (&/$Nil))) special-args]
+ ^MethodVisitor *writer* &/get-writer
+ :let [_ (doto *writer*
+ (.visitLdcInsn _class-name)
+ (.visitMethodInsn Opcodes/INVOKESTATIC "java/lang/Class" "forName" "(Ljava/lang/String;)Ljava/lang/Class;")
+ (prepare-return! ?output-type))]]
+ (return nil)))
+
(defn ^:private compile-jvm-instanceof [compile ?values special-args]
(|do [:let [(&/$Cons object (&/$Nil)) ?values
(&/$Cons class (&/$Nil)) special-args]
@@ -1339,6 +1348,7 @@
"jvm"
(case proc-name
+ "load-class" (compile-jvm-load-class compile ?values special-args)
"instanceof" (compile-jvm-instanceof compile ?values special-args)
"try" (compile-jvm-try compile ?values special-args)
"new" (compile-jvm-new compile ?values special-args)