forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jq: merge eval_ast/macroexpand into EVAL. Add DEBUG-EVAL
Original issue describing the change and converting the first set of implementations: kanaka#592 Tracking issue for other implementations: kanaka#657 All normal tests pass, but REGRESS and self-hosting fail. Steps: display the results from jq without python simplify/improve quasiquote simplify replenv construction Cosmetic: Update the interpreter from latest Debian/Ubuntu. move first core functions from steps4-A to core.jq simplify interprocess communication between run and utils.jq merge run and rts.py, simplify it
- Loading branch information
1 parent
cc1ebff
commit 0262704
Showing
20 changed files
with
1,017 additions
and
2,077 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM ubuntu:bionic | ||
FROM ubuntu:24.04 | ||
MAINTAINER Joel Martin <[email protected]> | ||
|
||
########################################################## | ||
|
@@ -9,10 +9,8 @@ MAINTAINER Joel Martin <[email protected]> | |
RUN apt-get -y update | ||
|
||
# Required for running tests | ||
RUN apt-get -y install make python | ||
|
||
# Some typical implementation and test requirements | ||
RUN apt-get -y install curl libreadline-dev libedit-dev libpcre3-dev | ||
RUN apt-get -y install make python3 | ||
RUN ln -fs /usr/bin/python3 /usr/local/bin/python | ||
|
||
RUN mkdir -p /mal | ||
WORKDIR /mal | ||
|
@@ -21,12 +19,4 @@ WORKDIR /mal | |
# Specific implementation requirements | ||
######################################################### | ||
|
||
RUN apt-get -y install python3.8 wget | ||
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10 | ||
|
||
# grab jq 1.6 from github releases | ||
RUN wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 | ||
|
||
RUN chmod +x jq-linux64 | ||
# a bit ugly, but it'll do? | ||
RUN mv jq-linux64 /usr/bin/jq | ||
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install jq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
all: | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -fr .mypy_cache/ | ||
|
||
check: | ||
flake8 run | ||
pylint run | ||
mypy run | ||
|
||
.PHONY: all clean check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
#!/bin/sh | ||
#!/usr/bin/python3 | ||
"""Spawn a jq subprocess and wrap some IO interactions for it. | ||
exec python rts.py "${@}" | ||
jq seems unable to | ||
- open an arbitrary file (slurp) | ||
- emit a string on stdout without new line (readline) | ||
""" | ||
from json import JSONDecodeError, dumps, loads | ||
from os import environ | ||
from os.path import dirname, join, realpath | ||
from subprocess import PIPE, Popen | ||
from sys import argv | ||
|
||
rundir = dirname(realpath(__file__)) | ||
with Popen(args=['/usr/bin/jq', | ||
'--argjson', 'DEBUG', 'false', | ||
'-nrM', # --null-input --raw-output --monochrome-output | ||
'-L', rundir, | ||
'-f', join(rundir, environ.get('STEP', 'stepA_mal') + '.jq'), | ||
'--args'] + argv[1:], | ||
stdin=PIPE, stderr=PIPE, encoding='utf-8', | ||
) as proc: | ||
assert proc.stderr is not None # for mypy | ||
for received in proc.stderr: | ||
try: | ||
as_json = loads(received) | ||
except JSONDecodeError: | ||
print(f'JQ STDERR: {received}', end=None) | ||
else: | ||
match as_json: | ||
case ['DEBUG:', ['display', str(message)]]: | ||
# While at it, provide a way to immediately print to | ||
# stdin for DEBUG-EVAL, println and prn (jq is able to | ||
# output to stderr, but *we* are already piping it). | ||
print(message) | ||
# Jq waits for this signal to go on, so that its own | ||
# output is not mixed with our one. | ||
print('null', file=proc.stdin, flush=True) | ||
case ['DEBUG:', ['readline', str(prompt)]]: | ||
try: | ||
data = input(prompt) | ||
except EOFError: | ||
break # Expected end of this script | ||
print(dumps(data), file=proc.stdin, flush=True) | ||
case ['DEBUG:', ['slurp', str(fname)]]: | ||
with open(fname, 'r', encoding='utf-8') as file_handler: | ||
data = file_handler.read() | ||
print(dumps(data), file=proc.stdin, flush=True) | ||
case _: | ||
# Allow normal debugging information for other purposes. | ||
print(f'JQ STDERR: {received}', end=None) | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.