aboutsummaryrefslogtreecommitdiff
path: root/src/lang
diff options
context:
space:
mode:
Diffstat (limited to 'src/lang')
-rw-r--r--src/lang/compiler.clj20
-rw-r--r--src/lang/parser.clj9
2 files changed, 27 insertions, 2 deletions
diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj
index 3e63fc801..26236da93 100644
--- a/src/lang/compiler.clj
+++ b/src/lang/compiler.clj
@@ -128,7 +128,22 @@
(defcompiler ^:private compile-module
[::&parser/module]
(.visit *writer* Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC Opcodes/ACC_SUPER)
- *name* nil "java/lang/Object" nil))
+ (->class *name*) nil "java/lang/Object" nil))
+
+(defcompiler ^:private compile-defclass
+ [::&parser/defclass ?name ?fields]
+ (do (prn 'compile-defclass ?name ?fields)
+ (let [=class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS)
+ (.visit Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC Opcodes/ACC_SUPER)
+ (->class (str *name* "." ?name)) nil "java/lang/Object" nil))]
+ (doseq [[class field] ?fields]
+ (doto (.visitField =class Opcodes/ACC_PUBLIC field (->type-signature class) nil nil)
+ (.visitEnd)))
+ (.visitEnd =class)
+ (let [parent-dir (->class *name*)]
+ (.mkdirs (java.io.File. parent-dir))
+ (with-open [stream (java.io.BufferedOutputStream. (java.io.FileOutputStream. (str parent-dir "/" ?name ".class")))]
+ (.write stream (.toByteArray =class)))))))
(let [+compilers+ [compile-boolean
compile-string
@@ -139,7 +154,8 @@
compile-ann-class
compile-if
compile-def
- compile-module]]
+ compile-module
+ compile-defclass]]
(defn ^:private compile-form [state]
(prn 'compile-form/state state)
(some #(% state) +compilers+)))
diff --git a/src/lang/parser.clj b/src/lang/parser.clj
index 5adf36030..beb14302d 100644
--- a/src/lang/parser.clj
+++ b/src/lang/parser.clj
@@ -107,6 +107,14 @@
[::&lexer/list ([[::&lexer/ident "module"]] :seq)]
(return [::module]))
+(defparser ^:private parse-defclass
+ [::&lexer/list ([[::&lexer/ident "defclass"] [::&lexer/ident ?name] [::&lexer/tuple ?fields]] :seq)]
+ (let [fields (for [field ?fields]
+ (match field
+ [::&lexer/tuple ([[::&lexer/ident ?class] [::&lexer/ident ?field]] :seq)]
+ [?class ?field]))]
+ (return [::defclass ?name fields])))
+
(defparser ^:private parse-tagged
[::&lexer/list ([[::&lexer/tag ?tag] ?data] :seq)]
(exec [=data (apply-m parse-form (list ?data))]
@@ -190,6 +198,7 @@
parse-dynamic-access
parse-ann-class
parse-module
+ parse-defclass
parse-fn-call]))
;; [Interface]