diff --git a/examples/run.sh b/examples/run.sh new file mode 100755 index 0000000..57067cb --- /dev/null +++ b/examples/run.sh @@ -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 diff --git a/libstd/macro.cpp b/libstd/macro.cpp index 41a1188..cafc5e4 100644 --- a/libstd/macro.cpp +++ b/libstd/macro.cpp @@ -1,9 +1,9 @@ #include "macro.hpp" -std::shared_ptr assert_fail(Node const& node, - Compiler& compiler, - Program& program, - SymTable& sym) +void assert_fail(Node const& node, + Compiler& compiler, + Program& program, + SymTable&) { try { @@ -18,5 +18,7 @@ std::shared_ptr assert_fail(Node const& node, { } - return std::make_shared(TYPE_NIL, node.loc(), 0); + size_t addr = program.add_constant(std::make_shared + (TYPE_NIL, node.loc(), 0)); + program.append(OPCODE_LOAD_CONST, addr); } diff --git a/libstd/macro.hpp b/libstd/macro.hpp index c342446..e630c0c 100644 --- a/libstd/macro.hpp +++ b/libstd/macro.hpp @@ -3,9 +3,9 @@ #include "common.hpp" -std::shared_ptr assert_fail(Node const& node, - Compiler& compiler, - Program& program, - SymTable& sym); +void assert_fail(Node const& node, + Compiler& compiler, + Program& program, + SymTable& sym); #endif diff --git a/src/Compiler.cpp b/src/Compiler.cpp index 1458e2b..c8dd27e 100644 --- a/src/Compiler.cpp +++ b/src/Compiler.cpp @@ -57,10 +57,8 @@ namespace zn { if (macro->name() == ident) { - auto res = macro->execute(node, *this, - program, m_sym); - size_t addr = program.add_constant(res); - program.append(OPCODE_LOAD_CONST, addr); + macro->execute(node, *this, + program, m_sym); found_macro = true; break; } diff --git a/src/NativeMacro.cpp b/src/NativeMacro.cpp index 41d012c..6b68eee 100644 --- a/src/NativeMacro.cpp +++ b/src/NativeMacro.cpp @@ -13,12 +13,11 @@ namespace zn { } - std::shared_ptr - NativeMacro::execute(Node const& node, - Compiler& compiler, - Program& program, - SymTable& sym) + void NativeMacro::execute(Node const& node, + Compiler& compiler, + Program& program, + SymTable& sym) { - return m_macro(node, compiler, program, sym); + m_macro(node, compiler, program, sym); } } diff --git a/src/NativeMacro.hpp b/src/NativeMacro.hpp index 2f7c0f1..1f721ce 100644 --- a/src/NativeMacro.hpp +++ b/src/NativeMacro.hpp @@ -9,7 +9,7 @@ namespace zn { - using native_macro_t = std::function + using native_macro_t = std::function - execute(Node const& node, - Compiler& compiler, - Program& program, - SymTable& sym); + + void execute(Node const& node, + Compiler& compiler, + Program& program, + SymTable& sym); private: std::string m_name; diff --git a/src/Zarn.cpp b/src/Zarn.cpp index 592b8dd..e6d3ddd 100644 --- a/src/Zarn.cpp +++ b/src/Zarn.cpp @@ -13,10 +13,10 @@ namespace zn /*virtual*/ Zarn::~Zarn() { - for (void* handler: m_handlers) - { - // dlclose(handler); - } + //for (void* handler: m_handlers) + // { + // // dlclose(handler); + // } m_handlers.clear(); }