ADD: test script.

main
bog 2023-09-18 19:32:16 +02:00
parent ee1b52cae1
commit 0aa9ebd952
7 changed files with 71 additions and 29 deletions

43
examples/run.sh Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env bash
TOTAL=0
SUCCESS=0
for file in `find -name "*.zn"`
do
NAME=$(basename $file | cut -d'.' -f1)
MSG=$(zarn "$file" 2>&1 > /dev/null)
STATUS=$?
echo -en "\e[34m$NAME ... \e[0m"
if [ $STATUS -eq 0 ]
then
echo -e "\e[32mok\e[0m"
SUCCESS=$(($SUCCESS + 1))
else
echo -e "\e[31mko\e[0m"
echo "$MSG"
fi
TOTAL=$((TOTAL + 1))
done
FAILURE=$(($TOTAL - $SUCCESS))
if [ $SUCCESS -eq $TOTAL ]
then
echo -e "\e[32m======== All tests passed ========\e[0m"
else
echo -e "\e[31m======== $FAILURE tests failed ========\e[0m"
fi
echo -e "\e[0mok:\t$SUCCESS\e[0m"
echo -e "\e[0mko:\t$FAILURE\e[0m"
if [ $SUCCESS -eq $TOTAL ]
then
echo -e "\e[32mTOTAL:\t$TOTAL\e[0m"
else
echo -e "\e[31mTOTAL:\t$TOTAL\e[0m"
fi

View File

@ -1,9 +1,9 @@
#include "macro.hpp" #include "macro.hpp"
std::shared_ptr<Constant> assert_fail(Node const& node, void assert_fail(Node const& node,
Compiler& compiler, Compiler& compiler,
Program& program, Program& program,
SymTable& sym) SymTable&)
{ {
try try
{ {
@ -18,5 +18,7 @@ std::shared_ptr<Constant> assert_fail(Node const& node,
{ {
} }
return std::make_shared<Constant>(TYPE_NIL, node.loc(), 0); size_t addr = program.add_constant(std::make_shared<Constant>
(TYPE_NIL, node.loc(), 0));
program.append(OPCODE_LOAD_CONST, addr);
} }

View File

@ -3,9 +3,9 @@
#include "common.hpp" #include "common.hpp"
std::shared_ptr<Constant> assert_fail(Node const& node, void assert_fail(Node const& node,
Compiler& compiler, Compiler& compiler,
Program& program, Program& program,
SymTable& sym); SymTable& sym);
#endif #endif

View File

@ -57,10 +57,8 @@ namespace zn
{ {
if (macro->name() == ident) if (macro->name() == ident)
{ {
auto res = macro->execute(node, *this, macro->execute(node, *this,
program, m_sym); program, m_sym);
size_t addr = program.add_constant(res);
program.append(OPCODE_LOAD_CONST, addr);
found_macro = true; found_macro = true;
break; break;
} }

View File

@ -13,12 +13,11 @@ namespace zn
{ {
} }
std::shared_ptr<Constant> void NativeMacro::execute(Node const& node,
NativeMacro::execute(Node const& node, Compiler& compiler,
Compiler& compiler, Program& program,
Program& program, SymTable& sym)
SymTable& sym)
{ {
return m_macro(node, compiler, program, sym); m_macro(node, compiler, program, sym);
} }
} }

View File

@ -9,7 +9,7 @@
namespace zn namespace zn
{ {
using native_macro_t = std::function<std::shared_ptr<Constant> using native_macro_t = std::function<void
(Node const&, (Node const&,
Compiler&, Compiler&,
Program&, Program&,
@ -23,11 +23,11 @@ namespace zn
std::string name() const { return m_name; } std::string name() const { return m_name; }
std::shared_ptr<Constant>
execute(Node const& node, void execute(Node const& node,
Compiler& compiler, Compiler& compiler,
Program& program, Program& program,
SymTable& sym); SymTable& sym);
private: private:
std::string m_name; std::string m_name;

View File

@ -13,10 +13,10 @@ namespace zn
/*virtual*/ Zarn::~Zarn() /*virtual*/ Zarn::~Zarn()
{ {
for (void* handler: m_handlers) //for (void* handler: m_handlers)
{ // {
// dlclose(handler); // // dlclose(handler);
} // }
m_handlers.clear(); m_handlers.clear();
} }