diff options
Diffstat (limited to 'src/lang')
-rw-r--r-- | src/lang/analyser.clj | 6 | ||||
-rw-r--r-- | src/lang/compiler.clj | 14 |
2 files changed, 20 insertions, 0 deletions
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 "<init>" "()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 |