aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-02-28 10:35:04 -0600
committerJoel Martin <github@martintribe.org>2015-02-28 10:35:04 -0600
commit2ab1e5845c213a9951bee46a0c991202e6c46d5c (patch)
treeac1e5d898523bb892181804aa64f22ec4f4b9032
parent1218ce98a40ef243824fed0efce7160a10fe5f36 (diff)
downloadmal-2ab1e5845c213a9951bee46a0c991202e6c46d5c.tar.gz
mal-2ab1e5845c213a9951bee46a0c991202e6c46d5c.zip
Multiple: interop enhancements.
-rw-r--r--cs/stepA_interop.cs4
-rw-r--r--docs/TODO8
-rw-r--r--js/stepA_interop.js8
-rw-r--r--js/types.js4
-rw-r--r--php/stepA_interop.php14
-rw-r--r--ps/interop.ps4
-rw-r--r--ruby/stepA_interop.rb6
-rw-r--r--rust/Makefile7
8 files changed, 45 insertions, 10 deletions
diff --git a/cs/stepA_interop.cs b/cs/stepA_interop.cs
index 2e8fc12..6531d50 100644
--- a/cs/stepA_interop.cs
+++ b/cs/stepA_interop.cs
@@ -231,10 +231,10 @@ namespace Mal {
}
repl_env.set(new MalSymbol("eval"), new MalFunc(
a => EVAL(a[0], repl_env)));
- int fileIdx = 1;
+ int fileIdx = 0;
if (args.Length > 0 && args[0] == "--raw") {
Mal.readline.mode = Mal.readline.Mode.Raw;
- fileIdx = 2;
+ fileIdx = 1;
}
MalList _argv = new MalList();
for (int i=fileIdx; i < args.Length; i++) {
diff --git a/docs/TODO b/docs/TODO
index 741d024..e5b135b 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -1,4 +1,6 @@
All:
+ - Finish guide.md
+
- rename stepA_interop to stepA_mal
- test to check args set properly
- test to make sure slurp captures final newline
@@ -57,6 +59,8 @@ C:
C#:
- fix command line arg processing (doesn't run file specified)
- accumulates line breaks with mal/clojurewest2014.mal
+ - step9_interop:
+ http://www.ckode.dk/programming/eval-in-c-yes-its-possible/
Clojure:
- make indent consistent across steps (e.g. step5, step8)
@@ -167,6 +171,10 @@ Future Implementations:
- http://api.haxe.org/
- http://haxe.us/haxe_tutorial.html
+ - Julia
+
+ - Nim
+
- Objective-C:
- Pascal:
diff --git a/js/stepA_interop.js b/js/stepA_interop.js
index 456c006..d879cd3 100644
--- a/js/stepA_interop.js
+++ b/js/stepA_interop.js
@@ -5,6 +5,7 @@ if (typeof module !== 'undefined') {
var printer = require('./printer');
var Env = require('./env').Env;
var core = require('./core');
+ var interop = require('./interop');
}
// read
@@ -108,8 +109,11 @@ function _EVAL(ast, env) {
return eval(a1.toString());
case ".":
var el = eval_ast(ast.slice(2), env),
- f = eval(a1.toString());
- return f.apply(f, el);
+ r = interop.resolve_js(a1.toString()),
+ obj = r[0], f = r[1];
+ var res = f.apply(obj, el);
+ console.log("DEBUG3:", res);
+ return interop.js_to_mal(res);
case "try*":
try {
return EVAL(a1, env);
diff --git a/js/types.js b/js/types.js
index 848a484..e3901b7 100644
--- a/js/types.js
+++ b/js/types.js
@@ -79,6 +79,10 @@ function _clone (obj) {
default:
throw new Error("clone of non-collection: " + _obj_type(obj));
}
+ Object.defineProperty(new_obj, "__meta__", {
+ enumerable: false,
+ writable: true
+ });
return new_obj;
}
diff --git a/php/stepA_interop.php b/php/stepA_interop.php
index 8c67c66..1dc3b04 100644
--- a/php/stepA_interop.php
+++ b/php/stepA_interop.php
@@ -109,7 +109,19 @@ function MAL_EVAL($ast, $env) {
case "macroexpand":
return macroexpand($ast[1], $env);
case "php*":
- return eval($ast[1]);
+ $res = eval($ast[1]);
+ switch (gettype($res)) {
+ case "array":
+ if ($res !== array_values($res)) {
+ $new_res = _hash_map();
+ $new_res->exchangeArray($res);
+ return $new_res;
+ } else {
+ return call_user_func_array('_list', $res);
+ }
+ default:
+ return $res;
+ }
case "try*":
$a1 = $ast[1];
$a2 = $ast[2];
diff --git a/ps/interop.ps b/ps/interop.ps
index fb3b88d..8020ab0 100644
--- a/ps/interop.ps
+++ b/ps/interop.ps
@@ -1,6 +1,6 @@
-% ps_val -> ps2mal -> mal_val
+% [ ps_val1...] -> ps2mal -> [ mal_val1...]
/ps2mal {
- % convert a PS value to a Mal value (recursively)
+ % convert returned values to Mal types
[ exch
{ %forall returned values
dup ==
diff --git a/ruby/stepA_interop.rb b/ruby/stepA_interop.rb
index 6123293..1eff1f1 100644
--- a/ruby/stepA_interop.rb
+++ b/ruby/stepA_interop.rb
@@ -96,7 +96,11 @@ def EVAL(ast, env)
when :macroexpand
return macroexpand(a1, env)
when :"rb*"
- return eval(a1)
+ res = eval(a1)
+ return case res
+ when Array; List.new res
+ else; res
+ end
when :"try*"
begin
return EVAL(a1, env)
diff --git a/rust/Makefile b/rust/Makefile
index 537dac5..6910356 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -8,19 +8,22 @@ SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
#####################
-SRCS = step0_repl.rs step1_read_print.rs step2_eval.rs step3_env.rs \
+SRCS = step1_read_print.rs step2_eval.rs step3_env.rs \
step4_if_fn_do.rs step5_tco.rs step6_file.rs step7_quote.rs \
step8_macros.rs step9_try.rs stepA_interop.rs
BINS = $(SRCS:%.rs=target/%)
#####################
-all: $(BINS) mal
+all: mal
mal: ${SOURCES_BASE} $(word $(words ${SOURCES_LISP}),${SOURCES_LISP})
cargo build
cp $(word $(words ${BINS}),${BINS}) $@
+#$(BINS): target/%: src/%.rs
+# cargo build $*
+
clean:
cargo clean
rm -f mal