From 8f5cd3917fd3a94ae99710a614dce9028f9afad8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 12 Dec 2014 19:07:58 -0400 Subject: Added let (local vars). --- src/lang/compiler.clj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/lang/compiler.clj') diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index a71a66b8b..8b73720c4 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -127,6 +127,19 @@ (assert (compile-form (assoc *state* :form ?else)) "CAN't COMPILE ELSE") (.visitLabel *writer* end-label))) +(defcompiler ^:private compile-let + [::&analyser/let ?idx ?label ?value ?body] + (let [start-label (new Label) + end-label (new Label) + ?idx (int ?idx)] + (.visitLocalVariable *writer* ?label (->java-sig (:type ?value)) nil start-label end-label ?idx) + (assert (compile-form (assoc *state* :form ?value)) "CAN't COMPILE LET-VALUE") + (doto *writer* + (.visitVarInsn Opcodes/ASTORE ?idx) + (.visitLabel start-label)) + (assert (compile-form (assoc *state* :form ?body)) "CAN't COMPILE LET-BODY") + (.visitLabel *writer* end-label))) + (defcompiler ^:private compile-def [::&analyser/def ?form ?body] (match ?form @@ -221,6 +234,7 @@ compile-dynamic-access compile-ann-class compile-if + compile-let compile-def compile-module compile-defclass -- cgit v1.2.3