mirror of
https://github.com/kanaka/mal.git
synced 2024-08-18 02:00:40 +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.
84 lines
1.5 KiB
Plaintext
84 lines
1.5 KiB
Plaintext
// @import readline.ck
|
|
// @import types/boxed/*.ck
|
|
// @import types/MalObject.ck
|
|
// @import types/mal/MalAtom.ck
|
|
// @import types/mal/MalError.ck
|
|
// @import types/mal/MalNil.ck
|
|
// @import types/mal/MalFalse.ck
|
|
// @import types/mal/MalTrue.ck
|
|
// @import types/mal/MalInt.ck
|
|
// @import types/mal/MalString.ck
|
|
// @import types/mal/MalSymbol.ck
|
|
// @import types/mal/MalKeyword.ck
|
|
// @import types/mal/MalList.ck
|
|
// @import types/mal/MalVector.ck
|
|
// @import types/mal/MalHashMap.ck
|
|
// @import util/*.ck
|
|
// @import reader.ck
|
|
// @import printer.ck
|
|
|
|
fun MalObject READ(string input)
|
|
{
|
|
return Reader.read_str(input);
|
|
}
|
|
|
|
fun MalObject EVAL(MalObject m)
|
|
{
|
|
return m;
|
|
}
|
|
|
|
fun string PRINT(MalObject m)
|
|
{
|
|
return Printer.pr_str(m, true);
|
|
}
|
|
|
|
fun string errorMessage(MalObject m)
|
|
{
|
|
(m$MalError).value() @=> MalObject value;
|
|
return "exception: " + Printer.pr_str(value, true);
|
|
}
|
|
|
|
fun string rep(string input)
|
|
{
|
|
READ(input) @=> MalObject m;
|
|
|
|
if( m.type == "error" )
|
|
{
|
|
return errorMessage(m);
|
|
}
|
|
else
|
|
{
|
|
return PRINT(EVAL(m));
|
|
}
|
|
}
|
|
|
|
fun void main()
|
|
{
|
|
int done;
|
|
|
|
while( !done )
|
|
{
|
|
Readline.readline("user> ") => string input;
|
|
|
|
if( input != null )
|
|
{
|
|
rep(input) => string output;
|
|
|
|
if( output == "empty input" )
|
|
{
|
|
// proceed immediately with prompt
|
|
}
|
|
else
|
|
{
|
|
Util.println(output);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
true => done;
|
|
}
|
|
}
|
|
}
|
|
|
|
main();
|