1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 21:57:38 +03:00
mal/impls/chuck/step1_read_print.ck

82 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

// @import readline.ck
// @import types/MalObject.ck
2016-08-06 01:34:18 +03:00
// @import types/mal/MalAtom.ck
2024-08-29 01:44:37 +03:00
// @import types/mal/MalString.ck
2016-08-06 01:34:18 +03:00
// @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/MalSymbol.ck
// @import types/mal/MalKeyword.ck
// @import types/mal/MalList.ck
// @import types/mal/MalVector.ck
// @import types/mal/MalHashMap.ck
2016-05-12 21:04:22 +03:00
// @import util/*.ck
2016-04-28 10:20:09 +03:00
// @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);
}
2016-08-06 01:34:18 +03:00
fun string errorMessage(MalObject m)
{
2024-08-29 01:44:37 +03:00
return "exception: " + String.repr(m.malObjectValue().stringValue);
2016-08-06 01:34:18 +03:00
}
2016-04-28 10:20:09 +03:00
fun string rep(string input)
{
READ(input) @=> MalObject m;
if( m.type == "error" )
{
2016-08-06 01:34:18 +03:00
return errorMessage(m);
2016-04-28 10:20:09 +03:00
}
else
{
return PRINT(EVAL(m));
}
}
fun void main()
{
int done;
2016-04-28 10:20:09 +03:00
while( !done )
2016-04-28 10:20:09 +03:00
{
Readline.readline("user> ") => string input;
2016-04-28 10:20:09 +03:00
if( input != null )
2016-04-28 10:20:09 +03:00
{
rep(input) => string output;
2024-08-29 01:44:37 +03:00
if( output == "exception: \"empty input\"" )
{
// proceed immediately with prompt
}
else
{
Util.println(output);
}
2016-04-28 10:20:09 +03:00
}
else
{
true => done;
2016-04-28 10:20:09 +03:00
}
}
}
main();