From ab72e219835d05d7ce76111626a8119a64f5f283 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 15 Dec 2014 22:28:27 -0400 Subject: Added "do" expressions. --- src/lang/compiler.clj | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/lang/compiler.clj') diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index b7079fecf..83ce18ab1 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -99,14 +99,14 @@ (defcompiler ^:private compile-local [::&analyser/local ?idx] (do ;; (prn 'LOCAL ?idx) - (doto *writer* - (.visitVarInsn Opcodes/ALOAD (int ?idx))))) + (doto *writer* + (.visitVarInsn Opcodes/ALOAD (int ?idx))))) (defcompiler ^:private compile-global [::&analyser/global ?owner-class ?name] (do ;; (prn 'GLOBAL ?owner-class ?name *type*) - (doto *writer* - (.visitFieldInsn Opcodes/GETSTATIC (->class ?owner-class) ?name (->java-sig *type*))))) + (doto *writer* + (.visitFieldInsn Opcodes/GETSTATIC (->class ?owner-class) ?name (->java-sig *type*))))) ;; (defcompiler ^:private compile-call ;; [::&analyser/call ?fn ?args] @@ -177,6 +177,7 @@ (doto *writer* (.visitMethodInsn Opcodes/INVOKEVIRTUAL (->class "java.lang.Boolean") "booleanValue" "()Z") (.visitJumpInsn Opcodes/IFEQ else-label)) + (prn 'compile-if/?then (:form ?then)) (assert (compile-form (assoc *state* :form ?then)) "CAN't COMPILE THEN") (doto *writer* (.visitJumpInsn Opcodes/GOTO end-label) @@ -184,6 +185,13 @@ (assert (compile-form (assoc *state* :form ?else)) "CAN't COMPILE ELSE") (.visitLabel *writer* end-label))) +(defcompiler ^:private compile-do + [::&analyser/do ?exprs] + (do (doseq [expr (butlast ?exprs)] + (compile-form (assoc *state* :form expr)) + (.visitInsn *writer* Opcodes/POP)) + (compile-form (assoc *state* :form (last ?exprs))))) + (defcompiler ^:private compile-let [::&analyser/let ?idx ?label ?value ?body] (let [start-label (new Label) @@ -442,6 +450,7 @@ compile-dynamic-access compile-ann-class compile-if + compile-do compile-let compile-lambda compile-def -- cgit v1.2.3