mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 10:37:58 +03:00
0fc0391825
Ran into the same problem with macroexpand that prevented TCO in step5. Apparently objects as parameters cannot be re-assigning (or copied and re-assigned even) in a loop. When trying to do so, the server process crashes with a memory error. Move away from try to allocate and pass full structures around. Instead pass integer references into a memory pool of the objects (nested table of mal objects) and then pass this memory pool around by reference. Passing the memory pool around all over the place is ugly, but it allows TCO and macroexpand to work at all and seems to have better performance anyways.
69 lines
1.3 KiB
SQL
69 lines
1.3 KiB
SQL
@io.sql
|
|
@types.sql
|
|
@reader.sql
|
|
@printer.sql
|
|
|
|
CREATE OR REPLACE PACKAGE mal IS
|
|
|
|
FUNCTION MAIN(pwd varchar) RETURN integer;
|
|
|
|
END mal;
|
|
/
|
|
|
|
CREATE OR REPLACE PACKAGE BODY mal IS
|
|
|
|
FUNCTION MAIN(pwd varchar) RETURN integer IS
|
|
M mem_type;
|
|
line varchar2(4000);
|
|
|
|
-- read
|
|
FUNCTION READ(line varchar) RETURN integer IS
|
|
BEGIN
|
|
RETURN reader.read_str(M, line);
|
|
END;
|
|
|
|
-- eval
|
|
FUNCTION EVAL(ast integer, env varchar) RETURN integer IS
|
|
BEGIN
|
|
RETURN ast;
|
|
END;
|
|
|
|
-- print
|
|
FUNCTION PRINT(exp integer) RETURN varchar IS
|
|
BEGIN
|
|
RETURN printer.pr_str(M, exp);
|
|
END;
|
|
|
|
-- repl
|
|
FUNCTION REP(line varchar) RETURN varchar IS
|
|
BEGIN
|
|
RETURN PRINT(EVAL(READ(line), ''));
|
|
END;
|
|
|
|
BEGIN
|
|
M := types.mem_new();
|
|
|
|
WHILE true LOOP
|
|
BEGIN
|
|
line := stream_readline('user> ', 0);
|
|
IF line IS NULL THEN CONTINUE; END IF;
|
|
IF line IS NOT NULL THEN
|
|
stream_writeline(REP(line));
|
|
END IF;
|
|
|
|
EXCEPTION WHEN OTHERS THEN
|
|
IF SQLCODE = -20000 THEN
|
|
RETURN 0;
|
|
END IF;
|
|
stream_writeline('Error: ' || SQLERRM);
|
|
stream_writeline(dbms_utility.format_error_backtrace);
|
|
END;
|
|
END LOOP;
|
|
END;
|
|
|
|
END mal;
|
|
/
|
|
show errors;
|
|
|
|
quit;
|