Skip to content

Commit f0a3202

Browse files
committed
yamlscript: Tests step0 and step1 fully passing
To test, run `make -C yamlscript test`. The Makefile will auto-install the ys binary under the impls/yamlscript/.cache/ directory. Passing first 2 steps with no skipped tests.
1 parent 9eb7bea commit f0a3202

12 files changed

Lines changed: 277 additions & 1 deletion

File tree

IMPLS.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ IMPL:
112112
#- {IMPL: wasm, wasm_MODE: wace_libc, NO_SELF_HOST_PERF: 1} # Hangs on GH Actions
113113
- {IMPL: wren}
114114
- {IMPL: xslt, NO_SELF_HOST: 1} # step1 fail: "Too many nested template ..."
115+
- {IMPL: yamlscript}
115116
- {IMPL: yorick}
116117
- {IMPL: zig}
117118

Makefile.impls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ IMPLS = ada ada.2 awk bash basic bbc-basic c c.2 chuck clojure coffee common-lis
3737
guile hare haskell haxe hy io janet java java-truffle js jq julia kotlin latex3 livescript logo lua make mal \
3838
matlab miniMAL nasm nim objc objpascal ocaml perl perl6 php picolisp pike plpgsql \
3939
plsql powershell prolog ps purs python2 python3 r racket rexx rpython ruby ruby.2 rust scala scheme skew sml \
40-
swift swift3 swift4 swift6 tcl ts vala vb vbs vhdl vimscript wasm wren yorick xslt zig
40+
swift swift3 swift4 swift6 tcl ts vala vb vbs vhdl vimscript wasm wren yamlscript yorick xslt zig
4141

4242
step5_EXCLUDES += bash # never completes at 10,000
4343
step5_EXCLUDES += basic # too slow, and limited to ints of 2^16
@@ -199,6 +199,7 @@ vhdl_STEP_TO_PROG = impls/vhdl/$($(1))
199199
vimscript_STEP_TO_PROG = impls/vimscript/$($(1)).vim
200200
wasm_STEP_TO_PROG = impls/wasm/$($(1)).wasm
201201
wren_STEP_TO_PROG = impls/wren/$($(1)).wren
202+
yamlscript_STEP_TO_PROG = impls/yamlscript/$($(1)).ys
202203
yorick_STEP_TO_PROG = impls/yorick/$($(1)).i
203204
xslt_STEP_TO_PROG = impls/xslt/$($(1))
204205
zig_STEP_TO_PROG = impls/zig/$($(1))

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ FAQ](docs/FAQ.md) where I attempt to answer some common questions.
139139
| [WebAssembly](#webassembly-wasm) (wasm) | [Joel Martin](https://github.com/kanaka) |
140140
| [Wren](#wren) | [Dov Murik](https://github.com/dubek) |
141141
| [XSLT](#xslt) | [Ali MohammadPur](https://github.com/alimpfard) |
142+
| [YAMLScript](#yamlscript) | [Ingy döt Net](https://github.com/ingydotnet) |
142143
| [Yorick](#yorick) | [Dov Murik](https://github.com/dubek) |
143144
| [Zig](#zig) | [Josh Tobin](https://github.com/rjtobin) |
144145

@@ -1296,6 +1297,19 @@ cd impls/wren
12961297
wren ./stepX_YYY.wren
12971298
```
12981299

1300+
### YS (YAMLScript)
1301+
1302+
The YS (YAMLScript) implementation of mal was tested on YS 0.2.2.
1303+
1304+
```
1305+
cd impls/yamlscript
1306+
make test
1307+
```
1308+
1309+
The Makefile will install `ys` locally so there are no prerequisites.
1310+
1311+
Note: The YS language owes its origin to the "mal" project!
1312+
12991313
### Yorick
13001314

13011315
The Yorick implementation of mal was tested on Yorick 2.2.04.

impls/yamlscript/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.cache/

impls/yamlscript/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM ubuntu:jammy
2+
LABEL maintainer="Ingy döt Net <ingy@ingy.net>"
3+
4+
##########################################################
5+
# General requirements for testing or common across many
6+
# implementations
7+
##########################################################
8+
9+
RUN apt-get -y update
10+
11+
# Required for running tests
12+
RUN apt-get -y install make python3
13+
14+
# Some typical implementation and test requirements
15+
RUN apt-get -y install curl libreadline-dev libedit-dev
16+
17+
RUN mkdir -p /mal
18+
WORKDIR /mal
19+
20+
##########################################################
21+
# Specific implementation requirements
22+
##########################################################
23+
24+
RUN apt-get -y install xz-utils
25+
26+
RUN ln -s python3 /usr/bin/python
27+
28+
RUN curl -s https://getys.org/ys | VERSION=0.2.2 bash
29+
30+
ENV YSPATH=/mal/impls/yamlscript/lib

impls/yamlscript/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
M := $(or $(MAKES_REPO_DIR),.cache/makes)
2+
$(shell [ -d $M ] || git clone -q https://github.com/makeplus/makes $M)
3+
include $M/init.mk
4+
include $M/clean.mk
5+
include $M/ys.mk
6+
include $M/shell.mk
7+
8+
ROOT := $(shell cd ../.. && pwd)
9+
10+
ifndef BASIC
11+
export DEFERRABLE := 1
12+
export OPTIONAL := 1
13+
endif
14+
15+
IMPL := yamlscript
16+
17+
STEPS := $(shell for f in step*; do echo $${f%%_*}; done)
18+
STEPS := $(STEPS:step%=%)
19+
ALL-TESTS := $(STEPS:%=test-%)
20+
21+
GREP-RESULTS := grep -E '(^TEST RESULTS|: .* tests$$)'
22+
23+
export YSPATH := lib
24+
25+
26+
test:
27+
time $(MAKE) test-all BASIC=$(BASIC) |& $(GREP-RESULTS)
28+
echo
29+
30+
test-all: $(ALL-TESTS)
31+
32+
test-docker: docker-build
33+
$(MAKE) -C $(ROOT) DOCKERIZE=1 test^$(IMPL)
34+
35+
test-self-host: docker-build
36+
time $(MAKE) -C $(ROOT) MAL_IMPL=$(IMPL) test^mal^step{0..1}
37+
# |& \
38+
# $(GREP-RESULTS)
39+
40+
$(ALL-TESTS): $(YS)
41+
time $(MAKE) --no-print-directory -C ../.. \
42+
test^$(IMPL)^step$(@:test-%=%) \
43+
MAL_IMPL=$(IMPL) \
44+
DEFERRABLE=$(DEFERRABLE) \
45+
OPTIONAL=$(OPTIONAL) || \
46+
[[ $@ == test-6 ]]
47+
48+
docker-build:
49+
$(MAKE) -C $(ROOT) docker-build^$(IMPL)
50+
@echo

impls/yamlscript/lib/printer.ys

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
!YS-v0
2+
ns: printer
3+
4+
defn pr-str(ast):
5+
cond:
6+
map?(ast):
7+
cond:
8+
ast.list:
9+
"($(joins(ast.list.map(pr-str))))"
10+
ast.vector:
11+
"[$(joins(ast.vector.map(pr-str)))]"
12+
ast.hash-map:
13+
"{$(joins(ast.hash-map.map(pr-str)))}"
14+
ast.quote:
15+
"(quote $(ast.quote:pr-str))"
16+
ast.quasiquote:
17+
"(quasiquote $(ast.quasiquote:pr-str))"
18+
ast.unquote:
19+
"(unquote $(ast.unquote:pr-str))"
20+
ast.splice-unquote:
21+
"(splice-unquote $(ast.splice-unquote:pr-str))"
22+
ast.deref:
23+
"(deref $(ast.deref:pr-str))"
24+
ast.with-meta:
25+
"(with-meta $(ast.with-meta.0:pr-str)
26+
$(ast.with-meta.1:pr-str))"
27+
else: str(ast)

impls/yamlscript/lib/reader.ys

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
!YS-v0
2+
ns: reader
3+
4+
tokens =: atom(nil)
5+
6+
re-tokenize =:
7+
qr:: |
8+
(?x)
9+
[\s,]*
10+
(
11+
~@ |
12+
[\[\]{}()'`~^@] |
13+
"(?:\\.|[^\\"])*"? |
14+
;.* |
15+
[^\s\[\]{}('"`,;)]*
16+
)
17+
18+
defn read-str(string):
19+
reset tokens: tokenize(string)
20+
read-form:
21+
22+
defn tokenize(string):
23+
remove empty?:
24+
map second:
25+
re-seq re-tokenize: string
26+
27+
defn peek():
28+
=>: tokens.@.first()
29+
30+
defn next():
31+
token =: peek()
32+
reset tokens: rest(tokens.@)
33+
=>: token
34+
35+
defn read-form():
36+
token =: peek()
37+
condp eq token:
38+
'(': read-list('list' ')')
39+
'[': read-list('vector' ']')
40+
'{': read-list('hash-map' '}')
41+
"'": read-quote('quote')
42+
'`': read-quote('quasiquote')
43+
'~': read-quote('unquote')
44+
'~@': read-quote('splice-unquote')
45+
'@': read-quote('deref')
46+
'^': with-meta()
47+
else: read-atom()
48+
49+
defn read-list(type end):
50+
next:
51+
=>::
52+
! type::
53+
loop list []:
54+
token =: peek()
55+
when-not token:
56+
die: "Reached end of input in 'read_list'"
57+
if token != end:
58+
recur: list.conj(read-form())
59+
else:
60+
next:
61+
=>: list
62+
63+
defn read-quote(type):
64+
next:
65+
hash-map: type read-form()
66+
67+
defn with-meta():
68+
next:
69+
meta =: read-form()
70+
form =: read-form()
71+
hash-map: +
72+
'with-meta' [form meta]
73+
74+
re-string =: /"((?:\\.|[^\\"])*)"/
75+
76+
defn read-atom():
77+
atom =: next()
78+
cond:
79+
atom =~ /^"/:
80+
when atom !~ re-string:
81+
die: "Reached end of input looking for '\"'"
82+
=>: atom

impls/yamlscript/lib/readline.ys

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
!YS-v0
2+
ns: readline
3+
4+
defn readline(prompt):
5+
print: prompt
6+
read-line:

impls/yamlscript/run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
exec ys "$(dirname "${BASH_SOURCE[0]}")/${STEP:-stepA_mal}.ys" "$@"

0 commit comments

Comments
 (0)