diff options
Diffstat (limited to '')
-rw-r--r-- | src/lux/analyser/host.clj | 14 | ||||
-rw-r--r-- | src/lux/compiler/host.clj | 10 |
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) |