mirror of
https://github.com/kanaka/mal.git
synced 2024-09-19 09:38:28 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
63 lines
1.4 KiB
PL/PgSQL
63 lines
1.4 KiB
PL/PgSQL
-- ---------------------------------------------------------
|
|
-- step1_read_print.sql
|
|
|
|
\i init.sql
|
|
\i io.sql
|
|
\i types.sql
|
|
\i reader.sql
|
|
\i printer.sql
|
|
|
|
-- ---------------------------------------------------------
|
|
|
|
CREATE SCHEMA mal;
|
|
|
|
-- read
|
|
CREATE FUNCTION mal.READ(line varchar) RETURNS integer AS $$
|
|
BEGIN
|
|
RETURN reader.read_str(line);
|
|
END; $$ LANGUAGE plpgsql;
|
|
|
|
-- eval
|
|
CREATE FUNCTION mal.EVAL(ast integer, env varchar) RETURNS integer AS $$
|
|
BEGIN
|
|
RETURN ast;
|
|
END; $$ LANGUAGE plpgsql;
|
|
|
|
-- print
|
|
CREATE FUNCTION mal.PRINT(exp integer) RETURNS varchar AS $$
|
|
BEGIN
|
|
RETURN printer.pr_str(exp);
|
|
END; $$ LANGUAGE plpgsql;
|
|
|
|
|
|
-- repl
|
|
|
|
CREATE FUNCTION mal.REP(line varchar) RETURNS varchar AS $$
|
|
BEGIN
|
|
RETURN mal.PRINT(mal.EVAL(mal.READ(line), ''));
|
|
END; $$ LANGUAGE plpgsql;
|
|
|
|
CREATE FUNCTION mal.MAIN(pwd varchar) RETURNS integer AS $$
|
|
DECLARE
|
|
line varchar;
|
|
output varchar;
|
|
BEGIN
|
|
WHILE true
|
|
LOOP
|
|
BEGIN
|
|
line := io.readline('user> ', 0);
|
|
IF line IS NULL THEN
|
|
PERFORM io.close(1);
|
|
RETURN 0;
|
|
END IF;
|
|
IF line NOT IN ('', E'\n') THEN
|
|
output := mal.REP(line);
|
|
PERFORM io.writeline(output);
|
|
END IF;
|
|
|
|
EXCEPTION WHEN OTHERS THEN
|
|
PERFORM io.writeline('Error: ' || SQLERRM);
|
|
END;
|
|
END LOOP;
|
|
END; $$ LANGUAGE plpgsql;
|