ADD: test bash script.
parent
0795eb5d9f
commit
690122ea4a
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
OK=0
|
||||
TOTAL=0
|
||||
|
||||
for file in `find . -name "*.gri" -exec basename {} \;`
|
||||
do
|
||||
echo -en "\e[34m$file ... \e[0m"
|
||||
|
||||
MSG="$(grino $file 2>&1 > /dev/null)"
|
||||
RES=$?
|
||||
|
||||
if [ "$RES" == "0" ]
|
||||
then
|
||||
echo -e "ok"
|
||||
OK=$(($OK + 1))
|
||||
else
|
||||
echo "ko"
|
||||
echo -e "\t\e[31m$MSG\e[0m"
|
||||
fi
|
||||
|
||||
TOTAL=$(($TOTAL + 1))
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
if [ $OK -eq $TOTAL ]
|
||||
then
|
||||
echo -e "\e[32m=== $OK/$TOTAL tests passed ! ===\e[0m"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
FAILURE=$(($TOTAL - $OK))
|
||||
|
||||
echo -e "\e[31m=== $FAILURE/$TOTAL tests failed ===\e[0m"
|
||||
exit -1
|
100
src/main.cpp
100
src/main.cpp
|
@ -11,6 +11,55 @@
|
|||
#include "src/SymTable.hpp"
|
||||
#include "Loader.hpp"
|
||||
|
||||
void run(char** argv, bool debug_mode)
|
||||
{
|
||||
std::string source;
|
||||
{
|
||||
std::ifstream file { argv[optind] };
|
||||
assert(file);
|
||||
std::string line;
|
||||
|
||||
while (std::getline(file, line))
|
||||
{ source += line + (file.eof() ? "" : "\n"); }
|
||||
}
|
||||
|
||||
grino::Logger logger;
|
||||
grino::Lexer lexer {logger, argv[optind]};
|
||||
grino::Parser parser {logger, lexer};
|
||||
|
||||
auto ast = parser.parse(source);
|
||||
|
||||
if (debug_mode)
|
||||
{
|
||||
std::cout << "--- ast ---" << std::endl;
|
||||
std::cout << ast->string() << std::endl;
|
||||
}
|
||||
|
||||
grino::SymTable sym_table {logger};
|
||||
grino::VM vm {logger};
|
||||
|
||||
grino::Loader loader {vm, sym_table};
|
||||
loader.load_libraries();
|
||||
|
||||
grino::Compiler compiler {logger, sym_table};
|
||||
grino::Program program;
|
||||
compiler.compile(ast, program);
|
||||
|
||||
if (debug_mode)
|
||||
{
|
||||
std::cout << "--- program ---" << std::endl;
|
||||
std::cout << program.string() << std::endl;
|
||||
}
|
||||
|
||||
vm.run(program);
|
||||
|
||||
if (debug_mode)
|
||||
{
|
||||
std::cout << "--- stack ---" << std::endl;
|
||||
std::cout << vm.string() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
bool debug_mode = false;
|
||||
|
@ -54,50 +103,21 @@ int main(int argc, char** argv)
|
|||
|
||||
if (optind < argc)
|
||||
{
|
||||
std::string source;
|
||||
{
|
||||
std::ifstream file { argv[optind] };
|
||||
assert(file);
|
||||
std::string line;
|
||||
|
||||
while (std::getline(file, line))
|
||||
{ source += line + (file.eof() ? "" : "\n"); }
|
||||
}
|
||||
|
||||
grino::Logger logger;
|
||||
grino::Lexer lexer {logger, argv[optind]};
|
||||
grino::Parser parser {logger, lexer};
|
||||
|
||||
auto ast = parser.parse(source);
|
||||
|
||||
if (debug_mode)
|
||||
{
|
||||
std::cout << "--- ast ---" << std::endl;
|
||||
std::cout << ast->string() << std::endl;
|
||||
run(argv, debug_mode);
|
||||
}
|
||||
|
||||
grino::SymTable sym_table {logger};
|
||||
grino::VM vm {logger};
|
||||
|
||||
grino::Loader loader {vm, sym_table};
|
||||
loader.load_libraries();
|
||||
|
||||
grino::Compiler compiler {logger, sym_table};
|
||||
grino::Program program;
|
||||
compiler.compile(ast, program);
|
||||
|
||||
if (debug_mode)
|
||||
else
|
||||
{
|
||||
std::cout << "--- program ---" << std::endl;
|
||||
std::cout << program.string() << std::endl;
|
||||
}
|
||||
|
||||
vm.run(program);
|
||||
|
||||
if (debug_mode)
|
||||
{
|
||||
std::cout << "--- stack ---" << std::endl;
|
||||
std::cout << vm.string() << std::endl;
|
||||
try
|
||||
{
|
||||
run(argv, debug_mode);
|
||||
}
|
||||
catch(std::exception const& err)
|
||||
{
|
||||
std::cerr << err.what() << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue