Fix second-order self-hosting.
authorJoel Martin <github@martintribe.org>
Mon, 29 Jul 2019 22:55:25 +0000 (17:55 -0500)
committerJoel Martin <github@martintribe.org>
Mon, 29 Jul 2019 22:58:11 +0000 (17:58 -0500)
The `_map?` function was introduced when transitioning the macro
property being stored in metadata to uinsg a regular map with
a special key. The `_map?` function causes issues in a few places but
the biggest issue is that it breaks the `_macro?` function for the
second order self-hosted mal instance. The `_macro?` function contains
a `(map? x)` call that returns false resulting in the `_macro?` call
returning false.  I'll push something later that fixes this and also
that activates second order self-hosted tests so we can catch this
sort of issue in the future.

.travis.yml
.travis_test.sh
Makefile
mal/core.mal
mal/run
mal/step8_macros.mal
mal/step9_try.mal
mal/stepA_mal.mal
tests/step9_try.mal

index d9ab35a..38f0ae9 100644 (file)
@@ -53,7 +53,10 @@ matrix:
     - {env: IMPL=logo NO_SELF_HOST=1,         services: [docker]} # step4 timeout
     - {env: IMPL=lua,                         services: [docker]}
     - {env: IMPL=make NO_SELF_HOST=1,         services: [docker]} # step4 timeout
-    - {env: IMPL=mal BUILD_IMPL=js NO_SELF_HOST=1, services: [docker]}
+    - {env: IMPL=mal MAL_IMPL=js      BUILD_IMPL=js  NO_SELF_HOST=1, services: [docker]}
+    - {env: IMPL=mal MAL_IMPL=js-mal  BUILD_IMPL=js  NO_SELF_HOST=1, services: [docker]}
+    - {env: IMPL=mal MAL_IMPL=nim     BUILD_IMPL=nim NO_SELF_HOST=1, services: [docker]}
+    - {env: IMPL=mal MAL_IMPL=nim-mal BUILD_IMPL=nim NO_SELF_HOST=1, services: [docker]}
     - {env: IMPL=matlab NO_SELF_HOST_PERF=1,  services: [docker]} # Octave, perf timeout
     - {env: IMPL=miniMAL NO_SELF_HOST_PERF=1, services: [docker]} # perf timeout
     - {env: IMPL=nasm NO_SELF_HOST_PERF=1,    services: [docker]} # perf OOM
index c41cf6b..2c063fa 100755 (executable)
@@ -44,7 +44,7 @@ if [ -z "${NO_DOCKER}" ]; then
     img_impl=$(echo "${MAL_IMPL:-${IMPL}}" | tr '[:upper:]' '[:lower:]')
     # We could just use make DOCKERIZE=1 instead but that does add
     # non-trivial startup overhead for each step.
-    MAKE="docker run -it -u $(id -u) -v `pwd`:/mal kanaka/mal-test-${img_impl} ${MAKE}"
+    MAKE="docker run -it -u $(id -u) -v `pwd`:/mal kanaka/mal-test-${img_impl%%-mal} ${MAKE}"
 fi
 
 case "${ACTION}" in
index cdbaa7c..44e1ad8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -291,7 +291,7 @@ STEP_TEST_FILES = $(strip $(wildcard \
 lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
 impl_to_image = kanaka/mal-test-$(call lc,$(1))
 
-actual_impl = $(if $(filter mal,$(1)),$(MAL_IMPL),$(1))
+actual_impl = $(if $(filter mal,$(1)),$(patsubst %-mal,%,$(MAL_IMPL)),$(1))
 
 # Takes impl
 # Returns nothing if DOCKERIZE is not set, otherwise returns the
@@ -400,7 +400,7 @@ $(foreach i,$(DO_IMPLS),$(foreach s,$(STEPS),build^$(i)^$(s))): $$(call $$(word
 $(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
        @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
          $(foreach step,$(word 3,$(subst ^, ,$(@))),\
-           cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)) && \
+           cd $(call actual_impl,$(impl)) && \
            $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
              echo '----------------------------------------------' && \
              echo 'Testing $@; step file: $+, test file: $(test)' && \
@@ -455,7 +455,7 @@ perf: $(IMPL_PERF)
 $(IMPL_PERF):
        @echo "----------------------------------------------"; \
        $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
-         cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
+         cd $(call actual_impl,$(impl)); \
          echo "Performance test for $(impl):"; \
          echo 'Running: $(call get_run_prefix,$(impl),stepA) ../$(impl)/run ../tests/perf1.mal'; \
          $(call get_run_prefix,$(impl),stepA) ../$(impl)/run ../tests/perf1.mal; \
@@ -472,7 +472,7 @@ $(IMPL_PERF):
 $(ALL_REPL): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
        @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
          $(foreach step,$(word 3,$(subst ^, ,$(@))),\
-           cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
+           cd $(call actual_impl,$(impl)); \
            echo 'REPL implementation $(impl), step file: $+'; \
            echo 'Running: $(call get_run_prefix,$(impl),$(step)) ../$(impl)/run $(RUN_ARGS)'; \
            $(call get_run_prefix,$(impl),$(step)) ../$(impl)/run $(RUN_ARGS);))
index 5137f50..b7200bf 100644 (file)
@@ -1,8 +1,3 @@
-(def! _map? (fn* [x]
-  (if (map? x)
-    (not (contains? x :__MAL_MACRO__))
-    false)))
-
 (def! _macro? (fn* [x]
   (if (map? x)
     (contains? x :__MAL_MACRO__)
@@ -45,7 +40,7 @@
    ['vector vector]
    ['vector? vector?]
    ['hash-map hash-map]
-   ['map? _map?]
+   ['map? map?]
    ['assoc assoc]
    ['dissoc dissoc]
    ['get get]
diff --git a/mal/run b/mal/run
index 32be705..119ef19 100755 (executable)
--- a/mal/run
+++ b/mal/run
@@ -1,4 +1,9 @@
 #!/bin/bash
 MAL_FILE=../mal/${STEP:-stepA_mal}.mal
 export STEP=stepA_mal # force MAL_IMPL to use stepA
+case ${MAL_IMPL} in
+*-mal)
+    MAL_IMPL=${MAL_IMPL%%-mal}
+    MAL_FILE="../mal/stepA_mal.mal ${MAL_FILE}" ;;
+esac
 exec ./../${MAL_IMPL:-js}/run ${MAL_FILE} "${@}"
index d109f06..36871c1 100644 (file)
 
     (vector? ast) (apply vector (map (fn* [exp] (EVAL exp env)) ast))
 
-    (_map? ast)   (apply hash-map
-                      (apply concat
-                        (map (fn* [k] [k (EVAL (get ast k) env)])
-                             (keys ast))))
+    (map? ast)    (apply hash-map
+                    (apply concat
+                      (map (fn* [k] [k (EVAL (get ast k) env)])
+                           (keys ast))))
 
     "else"        ast)))
 
@@ -87,7 +87,8 @@
           (EVAL (QUASIQUOTE (nth ast 1)) env)
 
           (= 'defmacro! a0)
-          (env-set env (nth ast 1) {:__MAL_MACRO__ (EVAL (nth ast 2) env)})
+          (env-set env (nth ast 1) (hash-map :__MAL_MACRO__
+                                             (EVAL (nth ast 2) env)))
 
           (= 'macroexpand a0)
           (MACROEXPAND (nth ast 1) env)
index 89d697a..76abf84 100644 (file)
 
     (vector? ast) (apply vector (map (fn* [exp] (EVAL exp env)) ast))
 
-    (_map? ast)   (apply hash-map
-                      (apply concat
-                        (map (fn* [k] [k (EVAL (get ast k) env)])
-                             (keys ast))))
+    (map? ast)    (apply hash-map
+                    (apply concat
+                      (map (fn* [k] [k (EVAL (get ast k) env)])
+                           (keys ast))))
 
     "else"        ast)))
 
@@ -87,7 +87,8 @@
           (EVAL (QUASIQUOTE (nth ast 1)) env)
 
           (= 'defmacro! a0)
-          (env-set env (nth ast 1) {:__MAL_MACRO__ (EVAL (nth ast 2) env)})
+          (env-set env (nth ast 1) (hash-map :__MAL_MACRO__
+                                             (EVAL (nth ast 2) env)))
 
           (= 'macroexpand a0)
           (MACROEXPAND (nth ast 1) env)
index 35db404..294046e 100644 (file)
 
     (vector? ast) (apply vector (map (fn* [exp] (EVAL exp env)) ast))
 
-    (_map? ast)   (apply hash-map
-                      (apply concat
-                        (map (fn* [k] [k (EVAL (get ast k) env)])
-                             (keys ast))))
+    (map? ast)    (apply hash-map
+                    (apply concat
+                      (map (fn* [k] [k (EVAL (get ast k) env)])
+                           (keys ast))))
 
     "else"        ast)))
 
@@ -87,7 +87,8 @@
           (EVAL (QUASIQUOTE (nth ast 1)) env)
 
           (= 'defmacro! a0)
-          (env-set env (nth ast 1) {:__MAL_MACRO__ (EVAL (nth ast 2) env)})
+          (env-set env (nth ast 1) (hash-map :__MAL_MACRO__
+                                             (EVAL (nth ast 2) env)))
 
           (= 'macroexpand a0)
           (MACROEXPAND (nth ast 1) env)
index ce6c9e1..d231b7f 100644 (file)
 (= [] {})
 ;=>false
 
-(map? cond)
-;=>false
-
 (keyword :abc)
 ;=>:abc
 (keyword? (first (keys {":abc" 123 ":def" 456})))