aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/example/test1.lux (renamed from src/example/test1.lang)0
-rw-r--r--src/lux.clj (renamed from src/lang.clj)23
-rw-r--r--src/lux/analyser.clj (renamed from src/lang/analyser.clj)28
-rw-r--r--src/lux/compiler.clj (renamed from src/lang/compiler.clj)100
-rw-r--r--src/lux/lexer.clj (renamed from src/lang/lexer.clj)6
-rw-r--r--src/lux/parser.clj (renamed from src/lang/parser.clj)16
-rw-r--r--src/lux/type.clj (renamed from src/lang/type.clj)8
-rw-r--r--src/lux/util.clj (renamed from src/lang/util.clj)2
8 files changed, 90 insertions, 93 deletions
diff --git a/src/example/test1.lang b/src/example/test1.lux
index 8e740eabd..8e740eabd 100644
--- a/src/example/test1.lang
+++ b/src/example/test1.lux
diff --git a/src/lang.clj b/src/lux.clj
index 0777812b7..82fcb3a57 100644
--- a/src/lang.clj
+++ b/src/lux.clj
@@ -1,13 +1,14 @@
-(ns lang
- (:require (lang [lexer :as &lexer]
- [parser :as &parser]
- [type :as &type]
- [analyser :as &analyser]
- [compiler :as &compiler])
+(ns lux
+ (:require (lux [lexer :as &lexer]
+ [parser :as &parser]
+ [type :as &type]
+ [analyser :as &analyser]
+ [compiler :as &compiler])
:reload))
(comment
- ;; TODO: Add macros.
+ ;; TODO: Make macros monadic.
+ ;; TODO: Finish type system.
;; TODO: Re-implement compiler in language.
;; TODO: Add signatures & structures OR type-classes.
;; TODO: Add type-level computations.
@@ -21,12 +22,12 @@
;; TODO: When doing partial application, skip "apply" and just call constructor appropiatedly.
;; TODO: Add "new". Allow setting fields.
;; TODO: Don't take into account newlines in strings unless they come from \n to allow better coding.
- ;; TODO:
+ ;; TODO: monitor enter & monitor exit.
;; TODO:
;; TODO:
;; TODO:
- (let [source-code (slurp "test2.lang")
+ (let [source-code (slurp "test2.lux")
tokens (&lexer/lex source-code)
;; _ (prn 'tokens tokens)
syntax (&parser/parse tokens)
@@ -37,12 +38,8 @@
class-data (&compiler/compile "test2" syntax)
;; _ (prn 'class-data class-data)
]
- ;; (with-open [stream (java.io.BufferedOutputStream. (java.io.FileOutputStream. "test2.class"))]
- ;; (.write stream class-data))
)
- (Class/forName "test2.Variant")
-
;; jar cvf test2.jar *.class test2 && java -cp "test2.jar" test2
)
diff --git a/src/lang/analyser.clj b/src/lux/analyser.clj
index 30592c817..115a943c9 100644
--- a/src/lang/analyser.clj
+++ b/src/lux/analyser.clj
@@ -1,15 +1,15 @@
-(ns lang.analyser
+(ns lux.analyser
(:refer-clojure :exclude [resolve])
(: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 reduce-m
- apply-m within
- normalize-ident
- loader]]
- [parser :as &parser]
- [type :as &type])))
+ (lux [util :as &util :refer [exec return* return fail fail*
+ repeat-m try-m try-all-m map-m reduce-m
+ apply-m within
+ normalize-ident
+ loader]]
+ [parser :as &parser]
+ [type :as &type])))
(declare analyse-form
->tokens
@@ -64,7 +64,7 @@
;; ?macro-name
;; (get-in state [:lambda-scope 0])
;; (some (partial = ?macro-name) (get-in state [:lambda-scope 0])))
- [::&util/ok [state (some (partial = ?macro-name) (get-in state [:lambda-scope 0]))]])
+ [::&util/ok [state (some (partial = ?macro-name) (get-in state [:lambda-scope 0]))]])
_
[::&util/ok [state false]])
@@ -105,10 +105,10 @@
(match =return
[::&util/ok [?state ?value]]
[::&util/ok [(do ;; (prn [:lambda-scope 0] (get-in ?state [:lambda-scope 0]))
- ;; (prn [:lambda-scope 1] (get-in ?state [:lambda-scope 1]))
- (-> ?state
- (update-in [:lambda-scope 0] pop)
- (assoc-in [:lambda-scope 1] (inc (get-in state [:lambda-scope 1])))))
+ ;; (prn [:lambda-scope 1] (get-in ?state [:lambda-scope 1]))
+ (-> ?state
+ (update-in [:lambda-scope 0] pop)
+ (assoc-in [:lambda-scope 1] (inc (get-in state [:lambda-scope 1])))))
?value]]
_
@@ -223,7 +223,7 @@
(if-let [global|import (or (get-in state [:defs-env ident])
(get-in state [:imports ident]))]
(do ;; (prn 'resolve/_3 'global|import global|import)
- [::&util/ok [state global|import]])
+ [::&util/ok [state global|import]])
[::&util/failure (str "Unresolved identifier: " ident)])
:else
diff --git a/src/lang/compiler.clj b/src/lux/compiler.clj
index 27652c1ad..d4d7431a2 100644
--- a/src/lang/compiler.clj
+++ b/src/lux/compiler.clj
@@ -1,17 +1,17 @@
-(ns lang.compiler
+(ns lux.compiler
(:refer-clojure :exclude [compile])
(:require [clojure.string :as string]
[clojure.set :as set]
[clojure.core.match :refer [match]]
- (lang [util :as &util :refer [exec return* return fail fail*
- repeat-m try-m try-all-m map-m reduce-m
- apply-m within
- normalize-ident
- loader]]
- [type :as &type]
- [lexer :as &lexer]
- [parser :as &parser]
- [analyser :as &analyser])
+ (lux [util :as &util :refer [exec return* return fail fail*
+ repeat-m try-m try-all-m map-m reduce-m
+ apply-m within
+ normalize-ident
+ loader]]
+ [type :as &type]
+ [lexer :as &lexer]
+ [parser :as &parser]
+ [analyser :as &analyser])
:reload)
(:import (org.objectweb.asm Opcodes
Label
@@ -423,45 +423,45 @@
;; [::&analyser/case ?variant ?branches]
[::&analyser/case ?base-idx ?variant ?max-registers ?branch-mappings ?decision-tree]
(do ;; (prn 'compile-case ?base-idx ?variant ?max-registers ?branch-mappings ?decision-tree)
- ;; (assert false)
- (let [start-label (new Label)
- end-label (new Label)
- ;; default-label (new Label)
- entries (for [[?branch ?body] ?branch-mappings
- :let [label (new Label)]]
- [[?branch label]
- [label ?body]])
- mappings* (into {} (map first entries))]
- (dotimes [idx ?max-registers]
- (.visitLocalVariable *writer* (str "__" (swap! !case-vars inc) "__") (->java-sig ::&type/any) nil start-label end-label (+ ?base-idx (inc idx))))
- (compile-form (assoc *state* :form ?variant))
- (.visitLabel *writer* start-label)
- (let [default-label (new Label)
- default-code (:default ?decision-tree)]
- ;; (prn 'sequence-parts
- ;; (sequence-parts (:branches ?decision-tree) (list ?decision-tree)))
- (doseq [decision-tree (map first (sequence-parts (:branches ?decision-tree) (list ?decision-tree)))]
- (compile-decision-tree *writer* mappings* 0 nil default-label decision-tree))
- (.visitLabel *writer* default-label)
- (when (not default-code)
- ;; (do (prn 'default-code default-code)
- ;; (assert false)
- ;; ;; (.visitInsn Opcodes/POP) ;; ...
- ;; (compile-form (assoc *state* :form default-code))
- ;; (.visitJumpInsn *writer* Opcodes/GOTO end-label))
- (doto *writer*
- ;; (.visitInsn Opcodes/POP)
- (.visitTypeInsn Opcodes/NEW ex-class)
- (.visitInsn Opcodes/DUP)
- (.visitMethodInsn Opcodes/INVOKESPECIAL ex-class "<init>" "()V")
- (.visitInsn Opcodes/ATHROW))))
- ;; (compile-decision-tree *state* *writer* mappings* 1 nil (:branches ?decision-tree) ?decision-tree)
- (doseq [[?label ?body] (map second entries)]
- (.visitLabel *writer* ?label)
- (compile-form (assoc *state* :form ?body))
- (.visitJumpInsn *writer* Opcodes/GOTO end-label))
- (.visitLabel *writer* end-label)
- ))
+ ;; (assert false)
+ (let [start-label (new Label)
+ end-label (new Label)
+ ;; default-label (new Label)
+ entries (for [[?branch ?body] ?branch-mappings
+ :let [label (new Label)]]
+ [[?branch label]
+ [label ?body]])
+ mappings* (into {} (map first entries))]
+ (dotimes [idx ?max-registers]
+ (.visitLocalVariable *writer* (str "__" (swap! !case-vars inc) "__") (->java-sig ::&type/any) nil start-label end-label (+ ?base-idx (inc idx))))
+ (compile-form (assoc *state* :form ?variant))
+ (.visitLabel *writer* start-label)
+ (let [default-label (new Label)
+ default-code (:default ?decision-tree)]
+ ;; (prn 'sequence-parts
+ ;; (sequence-parts (:branches ?decision-tree) (list ?decision-tree)))
+ (doseq [decision-tree (map first (sequence-parts (:branches ?decision-tree) (list ?decision-tree)))]
+ (compile-decision-tree *writer* mappings* 0 nil default-label decision-tree))
+ (.visitLabel *writer* default-label)
+ (when (not default-code)
+ ;; (do (prn 'default-code default-code)
+ ;; (assert false)
+ ;; ;; (.visitInsn Opcodes/POP) ;; ...
+ ;; (compile-form (assoc *state* :form default-code))
+ ;; (.visitJumpInsn *writer* Opcodes/GOTO end-label))
+ (doto *writer*
+ ;; (.visitInsn Opcodes/POP)
+ (.visitTypeInsn Opcodes/NEW ex-class)
+ (.visitInsn Opcodes/DUP)
+ (.visitMethodInsn Opcodes/INVOKESPECIAL ex-class "<init>" "()V")
+ (.visitInsn Opcodes/ATHROW))))
+ ;; (compile-decision-tree *state* *writer* mappings* 1 nil (:branches ?decision-tree) ?decision-tree)
+ (doseq [[?label ?body] (map second entries)]
+ (.visitLabel *writer* ?label)
+ (compile-form (assoc *state* :form ?body))
+ (.visitJumpInsn *writer* Opcodes/GOTO end-label))
+ (.visitLabel *writer* end-label)
+ ))
))
(defcompiler ^:private compile-let
@@ -821,7 +821,7 @@
[::&analyser/require ?file ?alias]
(let [module-name (re-find #"[^/]+$" ?file)
;; _ (prn 'module-name module-name)
- source-code (slurp (str module-name ".lang"))
+ source-code (slurp (str module-name ".lux"))
;; _ (prn 'source-code source-code)
tokens (&lexer/lex source-code)
;; _ (prn 'tokens tokens)
diff --git a/src/lang/lexer.clj b/src/lux/lexer.clj
index 7b23c5947..a302e89ba 100644
--- a/src/lang/lexer.clj
+++ b/src/lux/lexer.clj
@@ -1,8 +1,8 @@
-(ns lang.lexer
+(ns lux.lexer
(:require [clojure.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]]))
+ [lux.util :as &util :refer [exec return* return fail fail*
+ repeat-m try-m try-all-m]]))
(declare lex-forms lex-list lex-tuple lex-record lex-tag)
diff --git a/src/lang/parser.clj b/src/lux/parser.clj
index 34f3e70b4..8d3cfb0dd 100644
--- a/src/lang/parser.clj
+++ b/src/lux/parser.clj
@@ -1,11 +1,11 @@
-(ns lang.parser
+(ns lux.parser
(:require [clojure.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
- apply-m]]
- [lexer :as &lexer]
- [type :as &type])))
+ (lux [util :as &util :refer [exec return* return fail fail*
+ repeat-m try-m try-all-m map-m
+ apply-m]]
+ [lexer :as &lexer]
+ [type :as &type])))
(declare parse-form)
@@ -32,8 +32,8 @@
)
(defparser ^:private parse-char
- [::&lexer/char ?value]
- (return [::char (.charAt ?value 0)]))
+ [::&lexer/char ?value]
+ (return [::char (.charAt ?value 0)]))
(defn ident->string [ident]
(match ident
diff --git a/src/lang/type.clj b/src/lux/type.clj
index cfb404a21..b29fcd5d1 100644
--- a/src/lang/type.clj
+++ b/src/lux/type.clj
@@ -1,9 +1,9 @@
-(ns lang.type
+(ns lux.type
(:refer-clojure :exclude [resolve])
(:require [clojure.core.match :refer [match]]
- [lang.util :as &util :refer [exec return* return fail fail*
- repeat-m try-m try-all-m map-m
- apply-m assert!]]))
+ [lux.util :as &util :refer [exec return* return fail fail*
+ repeat-m try-m try-all-m map-m
+ apply-m assert!]]))
;; [Util]
(def ^:private success (return nil))
diff --git a/src/lang/util.clj b/src/lux/util.clj
index 063dfa061..5c792c2f3 100644
--- a/src/lang/util.clj
+++ b/src/lux/util.clj
@@ -1,4 +1,4 @@
-(ns lang.util
+(ns lux.util
(:require [clojure.string :as string]
[clojure.core.match :refer [match]]))