aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2014-12-07 20:13:58 -0400
committerEduardo Julian2014-12-07 20:13:58 -0400
commit8f8467773fa2c5fb6556355a826b03050f75824e (patch)
tree18b61120f162a893ab89b93eae7a6a57391be942
parent0dbcec8e727511d71101a705972eb252eec79b9f (diff)
Fixed the bug that was causing &lexer/lex-form to be used unbound.
Diffstat (limited to '')
-rw-r--r--src/lang/compiler.clj34
-rw-r--r--src/lang/lexer.clj66
2 files changed, 40 insertions, 60 deletions
diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj
index 66e50a462..52195d2f2 100644
--- a/src/lang/compiler.clj
+++ b/src/lang/compiler.clj
@@ -103,28 +103,18 @@
(match ?form
[::&parser/fn-call [::&parser/ident ?name] ?args]
(if (= "main" ?name)
- (let [=method (doto (.visitMethod *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) ?name "([Ljava/lang/String;)V" nil nil)
- (.visitCode))]
- (compile-form =method ?body)
- (doto =method
- (.visitInsn Opcodes/RETURN)
- (.visitMaxs 0 0)
- (.visitEnd)))
- (let [=method (doto (.visitMethod *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) ?name "(Ljava/lang/Object;)Ljava/lang/Object;" nil nil)
- (.visitCode))]
- ;; (doto =method
- ;; (.visitFieldInsn Opcodes/GETSTATIC (->class "java.lang.System") "out" (->type-signature "java.io.PrintStream"))
- ;; (.visitLdcInsn "IN")
- ;; (.visitMethodInsn Opcodes/INVOKEVIRTUAL (->class "java.io.PrintStream") "println" "(Ljava/lang/String;)V"))
- (compile-form =method ?body)
- ;; (doto =method
- ;; (.visitFieldInsn Opcodes/GETSTATIC (->class "java.lang.System") "out" (->type-signature "java.io.PrintStream"))
- ;; (.visitLdcInsn "OUT")
- ;; (.visitMethodInsn Opcodes/INVOKEVIRTUAL (->class "java.io.PrintStream") "println" "(Ljava/lang/String;)V"))
- (doto =method
- (.visitInsn Opcodes/ARETURN)
- (.visitMaxs 0 0)
- (.visitEnd))))
+ (doto (.visitMethod *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) ?name "([Ljava/lang/String;)V" nil nil)
+ (.visitCode)
+ (compile-form ?body)
+ (.visitInsn Opcodes/RETURN)
+ (.visitMaxs 0 0)
+ (.visitEnd))
+ (doto (.visitMethod *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) ?name "(Ljava/lang/Object;)Ljava/lang/Object;" nil nil)
+ (.visitCode)
+ (compile-form ?body)
+ (.visitInsn Opcodes/ARETURN)
+ (.visitMaxs 0 0)
+ (.visitEnd)))
))
(let [+compilers+ [compile-boolean
diff --git a/src/lang/lexer.clj b/src/lang/lexer.clj
index 65e57114b..caaa15604 100644
--- a/src/lang/lexer.clj
+++ b/src/lang/lexer.clj
@@ -4,7 +4,7 @@
[lang.util :as &util :refer [exec return* return fail fail*
repeat-m try-m try-all-m]]))
-(declare lex-form)
+(declare lex-forms lex-list lex-tuple lex-record lex-tag)
;; [Utils]
(defn ^:private lex-regex [regex]
@@ -22,33 +22,6 @@
;; [Lexers]
(def ^:private lex-white-space (lex-regex #"^(\s+)"))
-(def lex-forms
- (exec [forms (repeat-m lex-form)]
- (return (filter #(match %
- [::comment _]
- false
- _
- true)
- forms))))
-
-(def ^:private lex-list
- (exec [_ (lex-str "(")
- members lex-forms
- _ (lex-str ")")]
- (return [::list members])))
-
-(def ^:private lex-tuple
- (exec [_ (lex-str "[")
- members lex-forms
- _ (lex-str "]")]
- (return [::tuple members])))
-
-(def ^:private lex-record
- (exec [_ (lex-str "{")
- members lex-forms
- _ (lex-str "}")]
- (return [::record members])))
-
(def +ident-re+ #"^([a-zA-Z\-\+\_\=!@$%^&*<>\.,/\\\|':][0-9a-zA-Z\-\+\_\=!@$%^&*<>\.,/\\\|':]*)")
(do-template [<name> <tag> <regex>]
@@ -68,8 +41,6 @@
]
(return [::string token])))
-;; (lex "(_. (_.. java.lang.System out) (println \"YOLO\"))")
-
(def ^:private lex-single-line-comment
(exec [_ (lex-str "##")
comment (lex-regex #"^([^\n]*)")
@@ -98,14 +69,6 @@
]
(return [::comment comment])))
-;; #"^(.*?!(#\()).*#\)"
-
-;; ;; UP TO #(
-;; #"^.+?(?=#\()"
-
-;; ;; UP TO )#
-;; #"^.+?(?=\)#)"
-
(def ^:private lex-tag
(exec [_ (lex-str "#")
token (lex-regex +ident-re+)]
@@ -127,6 +90,33 @@
_ (try-m lex-white-space)]
(return form)))
+(def lex-forms
+ (exec [forms (repeat-m lex-form)]
+ (return (filter #(match %
+ [::comment _]
+ false
+ _
+ true)
+ forms))))
+
+(def ^:private lex-list
+ (exec [_ (lex-str "(")
+ members lex-forms
+ _ (lex-str ")")]
+ (return [::list members])))
+
+(def ^:private lex-tuple
+ (exec [_ (lex-str "[")
+ members lex-forms
+ _ (lex-str "]")]
+ (return [::tuple members])))
+
+(def ^:private lex-record
+ (exec [_ (lex-str "{")
+ members lex-forms
+ _ (lex-str "}")]
+ (return [::record members])))
+
;; [Interface]
(defn lex [text]
(match (lex-forms text)