mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 13:55:55 +03:00
Haxe: update README, fix macro eval, add conj.
Also: - add ability to build all or one Haxe target. - enable travis build for Haxe
This commit is contained in:
parent
56be4ef0ee
commit
33dec7afc2
@ -24,6 +24,7 @@ matrix:
|
||||
- {env: IMPL=groovy, services: [docker]}
|
||||
- {env: IMPL=guile, services: [docker]}
|
||||
- {env: IMPL=haskell, services: [docker]}
|
||||
- {env: IMPL=haxe, services: [docker]}
|
||||
- {env: IMPL=java, services: [docker]}
|
||||
- {env: IMPL=js, services: [docker]}
|
||||
- {env: IMPL=julia, services: [docker]}
|
||||
|
25
README.md
25
README.md
@ -6,7 +6,7 @@
|
||||
|
||||
Mal is a Clojure inspired Lisp interpreter.
|
||||
|
||||
Mal is implemented in 44 different languages:
|
||||
Mal is implemented in 45 different languages:
|
||||
|
||||
* GNU awk
|
||||
* Bash shell
|
||||
@ -27,6 +27,7 @@ Mal is implemented in 44 different languages:
|
||||
* Groovy
|
||||
* GNU Guile
|
||||
* Haskell
|
||||
* Haxe
|
||||
* Java
|
||||
* JavaScript ([Online Demo](http://kanaka.github.io/mal))
|
||||
* Julia
|
||||
@ -314,6 +315,28 @@ make
|
||||
./stepX_YYY
|
||||
```
|
||||
|
||||
### Haxe
|
||||
|
||||
The Haxe implementation of mal requires Haxe version 3.2 to compile.
|
||||
Four different Haxe targets are supported: Neko, Python, C++, and
|
||||
JavaScript.
|
||||
|
||||
```
|
||||
cd haxe
|
||||
# Neko
|
||||
make all-neko
|
||||
neko ./stepX_YYY.n
|
||||
# Python
|
||||
make all-python
|
||||
python3 ./stepX_YYY.py
|
||||
# C++
|
||||
make all-cpp
|
||||
./cpp/stepX_YYY
|
||||
# JavaScript
|
||||
make all-js
|
||||
node ./stepX_YYY.js
|
||||
```
|
||||
|
||||
|
||||
### Java 1.7
|
||||
|
||||
|
@ -2,6 +2,20 @@ STEP1_DEPS = Compat.hx types/Types.hx reader/Reader.hx printer/Printer.hx
|
||||
STEP3_DEPS = $(STEP1_DEPS) env/Env.hx
|
||||
STEP4_DEPS = $(STEP3_DEPS) core/Core.hx
|
||||
|
||||
STEPS = step0_repl step1_read_print step2_eval step3_env \
|
||||
step4_if_fn_do step5_tco step6_file step7_quote \
|
||||
step8_macros step9_try stepA_mal
|
||||
|
||||
all: all-neko all-python all-cpp all-js
|
||||
|
||||
all-neko: $(foreach x,$(STEPS),$(x).n)
|
||||
|
||||
all-python: $(foreach x,$(STEPS),$(x).py)
|
||||
|
||||
all-cpp: $(foreach x,$(STEPS),cpp/$(x))
|
||||
|
||||
all-js: $(foreach x,$(STEPS),$(x).js)
|
||||
|
||||
|
||||
# Neko target (neko)
|
||||
|
||||
|
@ -87,7 +87,7 @@ class Step8_macros {
|
||||
|
||||
// apply
|
||||
ast = macroexpand(ast, env);
|
||||
if (!list_Q(ast)) { return ast; }
|
||||
if (!list_Q(ast)) { return eval_ast(ast, env); }
|
||||
|
||||
var alst = _list(ast);
|
||||
switch (alst[0]) {
|
||||
|
@ -89,7 +89,7 @@ class Step9_try {
|
||||
|
||||
// apply
|
||||
ast = macroexpand(ast, env);
|
||||
if (!list_Q(ast)) { return ast; }
|
||||
if (!list_Q(ast)) { return eval_ast(ast, env); }
|
||||
|
||||
var alst = _list(ast);
|
||||
switch (alst[0]) {
|
||||
|
@ -89,7 +89,7 @@ class StepA_mal {
|
||||
|
||||
// apply
|
||||
ast = macroexpand(ast, env);
|
||||
if (!list_Q(ast)) { return ast; }
|
||||
if (!list_Q(ast)) { return eval_ast(ast, env); }
|
||||
|
||||
var alst = _list(ast);
|
||||
switch (alst[0]) {
|
||||
@ -213,7 +213,9 @@ class StepA_mal {
|
||||
rep("(def! not (fn* (a) (if a false true)))");
|
||||
rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
|
||||
rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))");
|
||||
rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))");
|
||||
rep("(def! *gensym-counter* (atom 0))");
|
||||
rep("(def! gensym (fn* [] (symbol (str \"G__\" (swap! *gensym-counter* (fn* [x] (+ 1 x)))))))");
|
||||
rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))");
|
||||
|
||||
|
||||
if (cmdargs.length > 0) {
|
||||
|
@ -179,6 +179,19 @@ class Core {
|
||||
}
|
||||
}
|
||||
|
||||
static function conj(args) {
|
||||
return switch (args[0]) {
|
||||
case MalList(l):
|
||||
var elems = args.slice(1);
|
||||
elems.reverse();
|
||||
MalList(elems.concat(l));
|
||||
case MalVector(l):
|
||||
MalVector(l.concat(args.slice(1)));
|
||||
case _: throw "Invalid conj call";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// hash-map functions
|
||||
|
||||
public static function get(hm:MalType, key:MalType) {
|
||||
@ -335,7 +348,7 @@ class Core {
|
||||
"apply" => apply,
|
||||
"map" => do_map,
|
||||
|
||||
"conj" => function(a) { return nil; },
|
||||
"conj" => conj,
|
||||
|
||||
"meta" => meta,
|
||||
"with-meta" => with_meta,
|
||||
|
Loading…
Reference in New Issue
Block a user