diff --git a/TODO.md b/TODO.md index b0995c6..a1d1492 100644 --- a/TODO.md +++ b/TODO.md @@ -5,8 +5,8 @@ Decisions: - How values and heap values will be represented - Transparency and log levels -- [ ] Makefile -- [ ] VALUE +- [x] Makefile +- [x] VALUE - [ ] Stack - [ ] Test application (C++?) - [ ] Heap diff --git a/lib/value.c b/lib/value.c index c308fd7..5b69cc4 100644 --- a/lib/value.c +++ b/lib/value.c @@ -15,6 +15,11 @@ typedef struct { static_assert(sizeof(VALUE) <= 8, "VALUE must be < 8 bytes"); +static TYC_TYPE value_type(VALUE v) +{ + return v.type; +} + static int32_t value_integer(VALUE v) { #ifdef CHECK_TYCHE_BUGS diff --git a/test/tests.c b/test/tests.c new file mode 100644 index 0000000..55ecc68 --- /dev/null +++ b/test/tests.c @@ -0,0 +1,16 @@ +#include "../lib/vm.c" + +#include +#include +#include + +#define EQ(a, b) (memcmp(a, b) == 0) + +int main() +{ + // values + assert(value_type(create_value_integer(42)) == TT_INTEGER); + assert(value_integer(create_value_integer(-42)) == -42); + assert(fabsf(value_real(create_value_real(42.4f)) - 42.4f) < 0.00001f); + assert(value_idx(create_value_idx(TT_FUNCTION, 42)) == 42); +} \ No newline at end of file diff --git a/test/tests.cc b/test/tests.cc deleted file mode 100644 index 17810de..0000000 --- a/test/tests.cc +++ /dev/null @@ -1,7 +0,0 @@ -extern "C" { -#include "../lib/vm.c" -} - -int main() -{ -} \ No newline at end of file