From 5883c0d11c21a74ba493ea369ff01d7baed80a41 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 15 Dec 2014 00:56:48 -0400 Subject: Added tuples. --- src/lang/analyser.clj | 6 ++++++ src/lang/compiler.clj | 14 ++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'src/lang') diff --git a/src/lang/analyser.clj b/src/lang/analyser.clj index 115204570..122d6353d 100644 --- a/src/lang/analyser.clj +++ b/src/lang/analyser.clj @@ -96,6 +96,11 @@ (exec [=value (analyse-form* ?value)] (return (annotated [::variant ?tag =value] [::&type/variant ?tag (:type =value)])))) +(defanalyser analyse-tuple + [::&parser/tuple ?elems] + (exec [=elems (map-m analyse-form* ?elems)] + (return (annotated [::tuple =elems] [::&type/tuple (mapv :type =elems)])))) + (defanalyser analyse-ident [::&parser/ident ?ident] (resolve ?ident)) @@ -211,6 +216,7 @@ (try-all-m [analyse-boolean analyse-string analyse-variant + analyse-tuple analyse-ident analyse-ann-class analyse-static-access diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index fc164d9d1..e8f0207b3 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -79,6 +79,19 @@ :else (assert false (str "[Unknown literal type] " ?literal " : " (class ?literal))))) +(defcompiler ^:private compile-tuple + [::&analyser/tuple ?elems] + (let [num-elems (count ?elems)] + (let [tuple-class (str "test2/Tuple" num-elems)] + (doto *writer* + (.visitTypeInsn Opcodes/NEW tuple-class) + (.visitInsn Opcodes/DUP) + (.visitMethodInsn Opcodes/INVOKESPECIAL tuple-class "" "()V")) + (dotimes [idx num-elems] + (.visitInsn *writer* Opcodes/DUP) + (compile-form (assoc *state* :form (nth ?elems idx))) + (.visitFieldInsn *writer* Opcodes/PUTFIELD tuple-class (str "_" idx) "Ljava/lang/Object;"))))) + (defcompiler ^:private compile-local [::&analyser/local ?idx] (do ;; (prn 'LOCAL ?idx) @@ -329,6 +342,7 @@ (let [+compilers+ [compile-literal compile-variant + compile-tuple compile-local compile-global compile-call -- cgit v1.2.3