Skip to content

Commit

Permalink
Merge pull request #423 from asarhaddon/trivial-from-401
Browse files Browse the repository at this point in the history
Trivial commits from 401
  • Loading branch information
kanaka committed Jul 17, 2019
2 parents 12c29f0 + 643ee7d commit 03a2a69
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 22 deletions.
5 changes: 3 additions & 2 deletions ada.2/core.adb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ package body Core is

function Keyword (Args : in Types.T_Array) return Types.T is
begin
Err.Check (Args'Length = 1 and then Args (Args'First).Kind = Kind_String,
"expected a string");
Err.Check (Args'Length = 1
and then Args (Args'First).Kind in Types.Kind_Key,
"expected a keyword or a string");
return (Kind_Keyword, Args (Args'First).Str);
end Keyword;

Expand Down
1 change: 1 addition & 0 deletions elixir/lib/mal/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ defmodule Mal.Core do

defp with_meta([{type, ast, _old_meta}, meta]), do: {type, ast, meta}
defp with_meta([%Function{} = func, meta]), do: %{func | meta: meta}
defp with_meta(_), do: nil

defp deref(args) do
apply(&Mal.Atom.deref/1, args)
Expand Down
2 changes: 1 addition & 1 deletion lib/perf.mal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
`(let* (~start (time-ms)
~ret ~exp)
(do
(prn (str "Elapsed time: " (- (time-ms) ~start) " msecs"))
(println "Elapsed time:" (- (time-ms) ~start) "msecs")
~ret)))))

;; Count evaluations of a function during a given time frame.
Expand Down
10 changes: 9 additions & 1 deletion make/readline.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ __mal_readline_included := true
# have readline history.
READLINE_EOF :=
READLINE_HISTORY_FILE := $${HOME}/.mal-history
READLINE = $(eval __readline_temp := $(shell history -r $(READLINE_HISTORY_FILE); read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && history -s -- "$${line}" && echo "$${line}" || echo "__||EOF||__"; history -a $(READLINE_HISTORY_FILE) 2>/dev/null || true))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))
READLINE = $(eval __readline_temp := $(shell \
history -r $(READLINE_HISTORY_FILE); \
read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && \
history -s -- "$${line}" && \
echo "$${line}" || \
echo "__||EOF||__"; \
history -a $(READLINE_HISTORY_FILE) 2>/dev/null || \
true \
))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))

endif
3 changes: 1 addition & 2 deletions make/step0_repl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ $(call READLINE)
endef

define EVAL
$(if $(READLINE_EOF),,\
$(if $(findstring =,$(1)),$(eval $(1))$($(word 1,$(1))),$(eval __return := $(1))$(__return)))
$(if $(READLINE_EOF),,$(1))
endef

define PRINT
Expand Down
4 changes: 3 additions & 1 deletion scheme/lib/core.sld
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@
(symbol? . ,(lambda (x) (coerce (mal-instance-of? x 'symbol))))
(symbol . ,(lambda (x) (mal-symbol (string->symbol (mal-value x)))))
(keyword? . ,(lambda (x) (coerce (mal-instance-of? x 'keyword))))
(keyword . ,(lambda (x) (mal-keyword (string->symbol (mal-value x)))))
(keyword . ,(lambda (x) (if (mal-instance-of? x 'keyword)
x
(mal-keyword (string->symbol (mal-value x))))))
(vector? . ,(lambda (x) (coerce (mal-instance-of? x 'vector))))
(vector . ,(lambda args (mal-vector (list->vector args))))
(map? . ,(lambda (x) (coerce (mal-instance-of? x 'map))))
Expand Down
49 changes: 49 additions & 0 deletions tests/step0_repl.mal
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,52 @@ hello mal world
hello world abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 (;:() []{}"'* ;:() []{}"'* ;:() []{}"'*)
;=>hello world abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 (;:() []{}"'* ;:() []{}"'* ;:() []{}"'*)

;; Non alphanumeric characters
!
;=>!
&
;=>&
+
;=>+
,
;=>,
-
;=>-
/
;=>/
<
;=><
=
;=>=
>
;=>>
?
;=>?
@
;=>@
;;; Behaviour of backslash is not specified enough to test anything in step0.
^
;=>^
_
;=>_
`
;=>`
~
;=>~

;>>> soft=True
;>>> optional=True
;; ------- Optional Functionality --------------
;; ------- (Not needed for self-hosting) -------

;; Non alphanumeric characters
#
;=>#
$
;=>$
%
;=>%
.
;=>.
|
;=>|
99 changes: 97 additions & 2 deletions tests/step1_read_print.mal
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,54 @@ false
;=>"abc (with parens)"
"abc\"def"
;=>"abc\"def"
;;;"abc\ndef"
;;;;=>"abc\ndef"
""
;=>""
"&"
;=>"&"
"'"
;=>"'"
"("
;=>"("
")"
;=>")"
"*"
;=>"*"
"+"
;=>"+"
","
;=>","
"-"
;=>"-"
":"
;=>":"
";"
;=>";"
"<"
;=>"<"
"="
;=>"="
">"
;=>">"
"?"
;=>"?"
"@"
;=>"@"
"["
;=>"["
"]"
;=>"]"
"^"
;=>"^"
"_"
;=>"_"
"`"
;=>"`"
"{"
;=>"{"
"}"
;=>"}"
"~"
;=>"~"

;; Testing reader errors
(1 2
Expand Down Expand Up @@ -183,3 +227,54 @@ false
;; Testing read of @/deref
@a
;=>(deref a)

;>>> soft=True

;; Non alphanumerice characters in strings
;;; \t is not specified enough to be tested
"\n"
;=>"\n"
"#"
;=>"#"
"$"
;=>"$"
"%"
;=>"%"
"."
;=>"."
"\\"
;=>"\\"
"|"
;=>"|"

;; Non alphanumeric characters in comments
1;!
;=>1
1;"
;=>1
1;#
;=>1
1;$
;=>1
1;%
;=>1
1;'
;=>1
1;\
;=>1
1;\\
;=>1
1;\\\
;=>1
1;`
;=>1
;;; Hopefully less problematic characters
1; &()*+,-./:;<=>?@[]^_{|}~

;; FIXME: These tests have no reasons to be optional, but...
;; fantom fails this one
"!"
;=>"!"
;; io fails this one
"/"
;=>"/"
3 changes: 0 additions & 3 deletions tests/step4_if_fn_do.mal
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ a
;=>2
(fib 4)
;=>5
;;; Too slow for bash, erlang, make and miniMAL
;;;(fib 10)
;;;;=>89


;; Testing recursive function in environment.
Expand Down
27 changes: 27 additions & 0 deletions tests/step6_file.mal
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,30 @@ mymap
;=>true
*ARGV*
;=>()

;>>> soft=True

;; Non alphanumeric characters in comments in read-string
(read-string "1;!")
;=>1
(read-string "1;\"")
;=>1
(read-string "1;#")
;=>1
(read-string "1;$")
;=>1
(read-string "1;%")
;=>1
(read-string "1;'")
;=>1
(read-string "1;\\")
;=>1
(read-string "1;\\\\")
;=>1
(read-string "1;\\\\\\")
;=>1
(read-string "1;`")
;=>1
;;; Hopefully less problematic characters can be checked together
(read-string "1; &()*+,-./:;<=>?@[]^_{|}~")
;=>1
11 changes: 5 additions & 6 deletions tests/step9_try.mal
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@

(symbol "abc")
;=>abc
;;;TODO: all implementations should suppport this too
;;;(keyword :abc)
;;;;=>:abc
(keyword "abc")
;=>:abc

Expand Down Expand Up @@ -258,9 +255,6 @@
;=>{:bcd 234}
(keyword? (nth (keys {:abc 123 :def 456}) 0))
;=>true
;;; TODO: support : in strings in make impl
;;;(keyword? (nth (keys {":abc" 123 ":def" 456}) 0))
;;;;=>false
(keyword? (nth (vals {"a" :abc "b" :def}) 0))
;=>true

Expand Down Expand Up @@ -380,3 +374,8 @@

(map? cond)
;=>false

(keyword :abc)
;=>:abc
(keyword? (first (keys {":abc" 123 ":def" 456})))
;=>false
7 changes: 3 additions & 4 deletions tests/stepA_mal.mal
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@
(with-meta {} {"a" 1})
;=>{}

;;; Not actually supported by Clojure
;;;(meta (with-meta (atom 7) {"a" 1}))
;;;;=>{"a" 1}

(def! l-wm (with-meta [4 5 6] {"b" 2}))
;=>[4 5 6]
(meta l-wm)
Expand Down Expand Up @@ -298,3 +294,6 @@
;=>true
(m (+ 1 1))
;=>false

(meta (with-meta (atom 7) {"a" 1}))
;=>{"a" 1}

0 comments on commit 03a2a69

Please sign in to comment.