2016-08-06 18:42:56 +03:00
|
|
|
// @import readline.ck
|
2016-04-30 16:16:12 +03:00
|
|
|
// @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()
|
|
|
|
{
|
2016-08-06 18:42:56 +03:00
|
|
|
int done;
|
2016-04-28 10:20:09 +03:00
|
|
|
|
2016-08-06 18:42:56 +03:00
|
|
|
while( !done )
|
2016-04-28 10:20:09 +03:00
|
|
|
{
|
2016-08-06 18:42:56 +03:00
|
|
|
Readline.readline("user> ") => string input;
|
2016-04-28 10:20:09 +03:00
|
|
|
|
2016-08-06 18:42:56 +03:00
|
|
|
if( input != null )
|
2016-04-28 10:20:09 +03:00
|
|
|
{
|
2016-08-06 18:42:56 +03:00
|
|
|
rep(input) => string output;
|
|
|
|
|
2024-08-29 01:44:37 +03:00
|
|
|
if( output == "exception: \"empty input\"" )
|
2016-08-06 18:42:56 +03:00
|
|
|
{
|
|
|
|
// proceed immediately with prompt
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Util.println(output);
|
|
|
|
}
|
2016-04-28 10:20:09 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-06 18:42:56 +03:00
|
|
|
true => done;
|
2016-04-28 10:20:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|