Skip to content

Commit

Permalink
Fix second-order self-hosting.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kanaka committed Jul 29, 2019
1 parent 38daa69 commit ff4e5f1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .travis_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)' && \
Expand Down Expand Up @@ -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; \
Expand All @@ -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);))
Expand Down
7 changes: 1 addition & 6 deletions mal/core.mal
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -45,7 +40,7 @@
['vector vector]
['vector? vector?]
['hash-map hash-map]
['map? _map?]
['map? map?]
['assoc assoc]
['dissoc dissoc]
['get get]
Expand Down
5 changes: 5 additions & 0 deletions mal/run
Original file line number Diff line number Diff line change
@@ -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} "${@}"
11 changes: 6 additions & 5 deletions mal/step8_macros.mal
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

(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)))

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions mal/step9_try.mal
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

(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)))

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions mal/stepA_mal.mal
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

(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)))

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions tests/step9_try.mal
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@
(= [] {})
;=>false

(map? cond)
;=>false

(keyword :abc)
;=>:abc
(keyword? (first (keys {":abc" 123 ":def" 456})))
Expand Down

0 comments on commit ff4e5f1

Please sign in to comment.