aboutsummaryrefslogtreecommitdiff
path: root/src/lang
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lang.clj3
-rw-r--r--src/lang/analyser.clj16
-rw-r--r--src/lang/compiler.clj16
-rw-r--r--src/lang/parser.clj4
4 files changed, 32 insertions, 7 deletions
diff --git a/src/lang.clj b/src/lang.clj
index e09c06f33..2c0ca47e6 100644
--- a/src/lang.clj
+++ b/src/lang.clj
@@ -12,7 +12,6 @@
(comment
;; TODO: Add pattern-matching.
- ;; TODO: Add all the missing literal types.
;; TODO: Allow strings to have escape characters.
;; TODO: Fold all closure classes into one.
;; TODO: When doing partial application, skip "apply" and just call constructor appropiatedly.
@@ -20,7 +19,7 @@
;; TODO: Tuple8 and Tuple8X (for arbitrary-size tuples).
;; TODO: Allow "lambdas" to be closures.
;; TODO: Add Java-interop.
- ;; TODO: Add interpreter.
+ ;; TODO: Allow loading classes at runtime.
;; TODO: Add macros.
;; TODO: Re-implement compiler in language.
;; TODO: Add signatures & structures OR type-classes.
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