diff options
author | Eduardo Julian | 2014-12-21 01:19:59 -0400 |
---|---|---|
committer | Eduardo Julian | 2014-12-21 01:19:59 -0400 |
commit | 4dc96027d8e90734aea3a5e109b8786fc112e88b (patch) | |
tree | 37cbeb650fd283608c59cd421889621b5de7a611 | |
parent | 42940f107ebd3aa944ea06d4d4a577e58a3eeea7 (diff) |
The machinery is in place to allow loading modules at runtime.
-rw-r--r-- | src/lang.clj | 2 | ||||
-rw-r--r-- | src/lang/compiler.clj | 35 |
2 files changed, 23 insertions, 14 deletions
diff --git a/src/lang.clj b/src/lang.clj index f4ef4a9fc..16e76f6e5 100644 --- a/src/lang.clj +++ b/src/lang.clj @@ -11,7 +11,6 @@ (.write stream data))) (comment - ;; TODO: Allow loading classes/modules at runtime. ;; TODO: Add macros. ;; TODO: Re-implement compiler in language. ;; TODO: Add signatures & structures OR type-classes. @@ -25,6 +24,7 @@ ;; TODO: Tuple8 and Tuple8X (for arbitrary-size tuples). ;; TODO: Add extra arities (apply2, apply3, ..., apply16) ;; TODO: When doing partial application, skip "apply" and just call constructor appropiatedly. + ;; TODO: Add "new". Allow setting fields. ;; TODO: (let [source-code (slurp "test2.lang") diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index f1a78ed89..1595fe58e 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -134,9 +134,9 @@ (defcompiler ^:private compile-captured [::&analyser/captured ?scope ?captured-id ?source] (do ;; (prn 'CAPTURED [?scope ?captured-id]) - (doto *writer* - (.visitVarInsn Opcodes/ALOAD 0) - (.visitFieldInsn Opcodes/GETFIELD (apply str (interpose "$" ?scope)) (str "__" ?captured-id) "Ljava/lang/Object;")))) + (doto *writer* + (.visitVarInsn Opcodes/ALOAD 0) + (.visitFieldInsn Opcodes/GETFIELD (apply str (interpose "$" ?scope)) (str "__" ?captured-id) "Ljava/lang/Object;")))) (defcompiler ^:private compile-global [::&analyser/global ?owner-class ?name] @@ -203,8 +203,8 @@ (do ;; (prn 'compile-static-field ?owner ?field) ;; (assert false) (compile-form (assoc *state* :form ?target)) - (doto *writer* - (.visitFieldInsn Opcodes/GETFIELD (->class ?owner) ?field (->java-sig *type*))) + (doto *writer* + (.visitFieldInsn Opcodes/GETFIELD (->class ?owner) ?field (->java-sig *type*))) )) (defcompiler ^:private compile-static-method @@ -221,13 +221,13 @@ (defcompiler ^:private compile-dynamic-method [::&analyser/dynamic-method ?target ?owner ?method-name ?method-type ?args] (do ;; (prn 'compile-dynamic-access ?target ?owner ?method-name ?method-type ?args) - ;; (assert false) - (do (compile-form (assoc *state* :form ?target)) - (doseq [arg ?args] - (compile-form (assoc *state* :form arg))) - (doto *writer* - (.visitMethodInsn Opcodes/INVOKEVIRTUAL (->class ?owner) ?method-name (method->sig ?method-type)) - (.visitInsn Opcodes/ACONST_NULL))) + ;; (assert false) + (do (compile-form (assoc *state* :form ?target)) + (doseq [arg ?args] + (compile-form (assoc *state* :form arg))) + (doto *writer* + (.visitMethodInsn Opcodes/INVOKEVIRTUAL (->class ?owner) ?method-name (method->sig ?method-type)) + (.visitInsn Opcodes/ACONST_NULL))) )) (defcompiler ^:private compile-if @@ -681,4 +681,13 @@ (when (not (compile-form (assoc state :form input))) (assert false input))) (.visitEnd =class) - (.toByteArray =class))) + (.toByteArray =class)) + + (comment + (-> (java.io.File. "./") .toURL vector into-array java.net.URLClassLoader. (.loadClass "test2")) + (-> (java.io.File. "./") .toURL vector into-array java.net.URLClassLoader. (.loadClass "test2.Function")) + (let [test2 (-> (java.io.File. "./") .toURL vector into-array java.net.URLClassLoader. (.loadClass "test2")) + main (first (.getDeclaredMethods test2))] + (.invoke main nil (to-array [nil]))) + ) + ) |