diff options
author | Eduardo Julian | 2014-12-09 00:58:48 -0400 |
---|---|---|
committer | Eduardo Julian | 2014-12-09 00:58:48 -0400 |
commit | bad2695169969e6ee7551d2a2c23d9c4e1b656fb (patch) | |
tree | 60786df17a1d5d955657c752a1ebc9732b053a83 /src/lang | |
parent | 36de85ef43d60e29f4aeb622fb449cabb506e2d8 (diff) |
Now can define constants in modules.
Diffstat (limited to 'src/lang')
-rw-r--r-- | src/lang/compiler.clj | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index f305d8556..d2b24eb02 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -69,7 +69,7 @@ (do (doseq [arg ?args] (compile-form (assoc *state* :form arg))) (doto *writer* - (.visitMethodInsn Opcodes/INVOKESTATIC *name* ?fn "(Ljava/lang/Object;)Ljava/lang/Object;")))) + (.visitMethodInsn Opcodes/INVOKESTATIC (->class *name*) ?fn "(Ljava/lang/Object;)Ljava/lang/Object;")))) (defcompiler ^:private compile-static-access [::&parser/static-access ?class ?member] @@ -123,6 +123,9 @@ (.visitInsn Opcodes/ARETURN) (.visitMaxs 0 0) (.visitEnd)))) + [::&parser/ident ?name] + (doto (.visitField *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) ?name "Ljava/lang/Object;" nil nil) + (.visitEnd)) )) (defcompiler ^:private compile-module @@ -192,5 +195,22 @@ ;; (.visitMaxs 0 0) ;; (.visitEnd)) (doall (map #(compile-form (assoc state :form %)) inputs)) + (when-let [constants (seq (for [input inputs + :let [payload (match input + [::&parser/def [::&parser/ident ?name] ?body] + [?name ?body] + _ + nil)] + :when payload] + payload))] + (let [=init (doto (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil) + (.visitCode))] + (doseq [[?name ?body] constants] + (do (compile-form (assoc state :writer =init :form ?body)) + (.visitFieldInsn =init Opcodes/PUTSTATIC (->class class-name) ?name "Ljava/lang/Object;"))) + (doto =init + (.visitInsn Opcodes/RETURN) + (.visitMaxs 0 0) + (.visitEnd)))) (.visitEnd =class) (.toByteArray =class))) |