2015-03-26 22:25:50 +11:00
|
|
|
#include "MAL.h"
|
|
|
|
|
|
|
|
|
|
#include "ReadLine.h"
|
|
|
|
|
#include "Types.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
malValuePtr READ(const String& input);
|
|
|
|
|
String PRINT(malValuePtr ast);
|
|
|
|
|
|
|
|
|
|
static ReadLine s_readLine("~/.mal-history");
|
|
|
|
|
|
2015-03-27 09:04:35 +11:00
|
|
|
static String rep(const String& input);
|
|
|
|
|
static malValuePtr EVAL(malValuePtr ast);
|
|
|
|
|
|
2015-03-26 22:25:50 +11:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
String prompt = "user> ";
|
|
|
|
|
String input;
|
|
|
|
|
while (s_readLine.get(prompt, input)) {
|
|
|
|
|
String out;
|
|
|
|
|
try {
|
|
|
|
|
out = rep(input);
|
|
|
|
|
}
|
|
|
|
|
catch (malEmptyInputException&) {
|
|
|
|
|
continue; // no output
|
|
|
|
|
}
|
|
|
|
|
catch (String& s) {
|
|
|
|
|
out = s;
|
|
|
|
|
};
|
|
|
|
|
std::cout << out << "\n";
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-27 09:04:35 +11:00
|
|
|
static String rep(const String& input)
|
2015-03-26 22:25:50 +11:00
|
|
|
{
|
|
|
|
|
return PRINT(EVAL(READ(input)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
malValuePtr READ(const String& input)
|
|
|
|
|
{
|
|
|
|
|
return readStr(input);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-27 09:04:35 +11:00
|
|
|
static malValuePtr EVAL(malValuePtr ast)
|
2015-03-26 22:25:50 +11:00
|
|
|
{
|
|
|
|
|
return ast;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String PRINT(malValuePtr ast)
|
|
|
|
|
{
|
|
|
|
|
return ast->print(true);
|
|
|
|
|
}
|
2015-03-27 09:04:35 +11:00
|
|
|
|
|
|
|
|
// These have been added after step 1 to keep the linker happy.
|
2015-03-27 11:03:28 +11:00
|
|
|
malValuePtr EVAL(malValuePtr ast, malEnvPtr)
|
2015-03-27 09:04:35 +11:00
|
|
|
{
|
|
|
|
|
return ast;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 18:06:50 +11:00
|
|
|
malValuePtr APPLY(malValuePtr ast, malValueIter, malValueIter)
|
2015-03-27 09:04:35 +11:00
|
|
|
{
|
|
|
|
|
return ast;
|
|
|
|
|
}
|