From 58bfb46ba16fc1db07e501be6fcc0c940ec7a350 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 9 Dec 2014 02:09:11 -0400 Subject: Now compiling tagged values. --- src/lang/compiler.clj | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/lang/compiler.clj') diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index d2b24eb02..dbc088668 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -141,6 +141,13 @@ (doseq [[class field] ?fields] (doto (.visitField =class Opcodes/ACC_PUBLIC field (->type-signature class) nil nil) (.visitEnd))) + (doto (.visitMethod =class Opcodes/ACC_PUBLIC "" "()V" nil nil) + (.visitCode) + (.visitVarInsn Opcodes/ALOAD 0) + (.visitMethodInsn Opcodes/INVOKESPECIAL "java/lang/Object" "" "()V") + (.visitInsn Opcodes/RETURN) + (.visitMaxs 0 0) + (.visitEnd)) (.visitEnd =class) (let [parent-dir (->class *name*)] (.mkdirs (java.io.File. parent-dir)) @@ -161,6 +168,23 @@ (with-open [stream (java.io.BufferedOutputStream. (java.io.FileOutputStream. (str parent-dir "/" ?name ".class")))] (.write stream (.toByteArray =interface)))))) +(let [+tagged+ "test2/Tagged"] + (defcompiler ^:private compile-tagged + [::&parser/tagged ?tag ?value] + (do (prn 'compile-tagged ?tag ?value) + (doto *writer* + (.visitTypeInsn Opcodes/NEW +tagged+) + (.visitInsn Opcodes/DUP) + (.visitMethodInsn Opcodes/INVOKESPECIAL +tagged+ "" "()V") + (.visitInsn Opcodes/DUP) + (.visitLdcInsn ?tag) + (.visitFieldInsn Opcodes/PUTFIELD +tagged+ "tag" "Ljava/lang/String;") + (.visitInsn Opcodes/DUP)) + (compile-form (assoc *state* :form ?value)) + (doto *writer* + (.visitFieldInsn Opcodes/PUTFIELD +tagged+ "value" "Ljava/lang/Object;")) + ))) + (let [+compilers+ [compile-boolean compile-string compile-ident @@ -172,7 +196,8 @@ compile-def compile-module compile-defclass - compile-definterface]] + compile-definterface + compile-tagged]] (defn ^:private compile-form [state] (prn 'compile-form/state state) (some #(% state) +compilers+))) @@ -194,7 +219,10 @@ ;; (.visitInsn Opcodes/RETURN) ;; (.visitMaxs 0 0) ;; (.visitEnd)) - (doall (map #(compile-form (assoc state :form %)) inputs)) + (doseq [input inputs] + (when (not (compile-form (assoc state :form input))) + (assert false input))) + ;; (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] -- cgit v1.2.3