aboutsummaryrefslogtreecommitdiff
path: root/src/lang
diff options
context:
space:
mode:
authorEduardo Julian2014-12-15 22:54:35 -0400
committerEduardo Julian2014-12-15 22:54:35 -0400
commit08de30a36ff6599e583d22c4305bfee9878f92ea (patch)
treeae7662d6e0d9d750919e83b3eb48aba3e087f1be /src/lang
parentab72e219835d05d7ce76111626a8119a64f5f283 (diff)
Added ints and floats.
Diffstat (limited to 'src/lang')
-rw-r--r--src/lang/analyser.clj16
-rw-r--r--src/lang/compiler.clj16
-rw-r--r--src/lang/parser.clj4
3 files changed, 31 insertions, 5 deletions
diff --git a/src/lang/analyser.clj b/src/lang/analyser.clj
index 8572cfa53..9251b9523 100644
--- a/src/lang/analyser.clj
+++ b/src/lang/analyser.clj
@@ -1,6 +1,7 @@
(ns lang.analyser
(:refer-clojure :exclude [resolve])
- (:require [clojure.string :as string]
+ (:require (clojure [string :as string]
+ [template :refer [do-template]])
[clojure.core.match :refer [match]]
(lang [util :as &util :refer [exec return* return fail fail*
repeat-m try-m try-all-m map-m
@@ -106,6 +107,17 @@
_
=return))))
+(do-template [<name> <tag> <class>]
+ (defanalyser <name>
+ [<tag> ?value]
+ (return (annotated [::literal ?value] [::&type/object <class> []])))
+
+ analyse-boolean ::&parser/boolean "java.lang.Boolean"
+ analyse-int ::&parser/int "java.lang.Integer"
+ analyse-float ::&parser/float "java.lang.Float"
+ analyse-string ::&parser/string "java.lang.String"
+ )
+
(defanalyser analyse-boolean
[::&parser/boolean ?boolean]
(return (annotated [::literal ?boolean] [::&type/object "java.lang.Boolean" []])))
@@ -270,6 +282,8 @@
(def ^:private analyse-form
(try-all-m [analyse-boolean
+ analyse-int
+ analyse-float
analyse-string
analyse-variant
analyse-tuple
diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj
index 83ce18ab1..e7d1ed582 100644
--- a/src/lang/compiler.clj
+++ b/src/lang/compiler.clj
@@ -70,8 +70,17 @@
;; [Utils/Compilers]
(defcompiler ^:private compile-literal
[::&analyser/literal ?literal]
- (cond (string? ?literal)
- (.visitLdcInsn *writer* ?literal)
+ (cond (instance? java.lang.Integer ?literal)
+ (doto *writer*
+ (.visitTypeInsn Opcodes/NEW (->class "java.lang.Integer"))
+ (.visitInsn Opcodes/DUP)(.visitLdcInsn ?literal)
+ (.visitMethodInsn Opcodes/INVOKESPECIAL (->class "java.lang.Integer") "<init>" "(I)V"))
+
+ (instance? java.lang.Float ?literal)
+ (doto *writer*
+ (.visitTypeInsn Opcodes/NEW (->class "java.lang.Float"))
+ (.visitInsn Opcodes/DUP)(.visitLdcInsn ?literal)
+ (.visitMethodInsn Opcodes/INVOKESPECIAL (->class "java.lang.Float") "<init>" "(F)V"))
(instance? java.lang.Boolean ?literal)
(if ?literal
@@ -80,6 +89,9 @@
;; (.visitLdcInsn *writer* (int 0))
(.visitFieldInsn *writer* Opcodes/GETSTATIC (->class "java.lang.Boolean") "FALSE" (->type-signature "java.lang.Boolean")))
+ (string? ?literal)
+ (.visitLdcInsn *writer* ?literal)
+
:else
(assert false (str "[Unknown literal type] " ?literal " : " (class ?literal)))))
diff --git a/src/lang/parser.clj b/src/lang/parser.clj
index 76f32aba1..e82a7ef75 100644
--- a/src/lang/parser.clj
+++ b/src/lang/parser.clj
@@ -25,11 +25,11 @@
(defparser ^:private parse-int
[::&lexer/int ?int]
- (return [::int (Long/parseLong ?int)]))
+ (return [::int (Integer/parseInt ?int)]))
(defparser ^:private parse-float
[::&lexer/float ?float]
- (return [::float (Double/parseDouble ?float)]))
+ (return [::float (Float/parseFloat ?float)]))
(defn ident->string [ident]
(match ident