Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
549af109b9
|
|||
|
6dce7016ce
|
@@ -9,15 +9,13 @@ main:
|
||||
store %0
|
||||
|
||||
lenof
|
||||
push $s32 1
|
||||
sub
|
||||
store %1
|
||||
|
||||
push $s32 0
|
||||
loop:
|
||||
dup
|
||||
load %1
|
||||
eq
|
||||
ge
|
||||
jnz #end
|
||||
body:
|
||||
dup
|
||||
|
||||
@@ -7,14 +7,14 @@ main:
|
||||
array $arr
|
||||
store %0
|
||||
|
||||
push $s32 1
|
||||
push $s32 2
|
||||
store %1
|
||||
|
||||
push $s32 0
|
||||
loop:
|
||||
dup
|
||||
load %1
|
||||
eq
|
||||
ge
|
||||
jnz #end
|
||||
body:
|
||||
dup
|
||||
|
||||
@@ -111,7 +111,7 @@ using function_id = std::uint16_t;
|
||||
/**
|
||||
* @brief A handle to a furvm function.
|
||||
*/
|
||||
using function_h = handle<function, generic_header<function_id>>;
|
||||
using function_h = handle<function, refcount_header<function_id>>;
|
||||
|
||||
// module.hpp
|
||||
|
||||
|
||||
@@ -69,8 +69,9 @@ public:
|
||||
[[nodiscard]] T* allocate(std::size_t count = 1) {
|
||||
for (auto it = m_deadThings->begin(); it != m_deadThings->end(); ++it) {
|
||||
if (it->second != count) continue;
|
||||
T* data = it->first;
|
||||
m_deadThings->erase(it);
|
||||
return it->first;
|
||||
return data;
|
||||
}
|
||||
return m_arena->allocate<T>(count);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ thing_h executor::pop_thing() {
|
||||
if (m_frames.top().stackBase >= m_stack.size()) throw stack_underflow();
|
||||
thing_h top = std::move(m_stack.top());
|
||||
m_stack.pop();
|
||||
return top;
|
||||
return std::move(top);
|
||||
}
|
||||
|
||||
thing_h executor::thing() const {
|
||||
|
||||
+26
-1
@@ -1,3 +1,28 @@
|
||||
#include "furlang/arena.hpp"
|
||||
#include "furvm/furvm.hpp"
|
||||
#include "furvm/thing.hpp"
|
||||
#include "furvm/thing_allocator.hpp"
|
||||
|
||||
#include "gtest/gtest.h" // IWYU pragma: keep
|
||||
|
||||
namespace {}
|
||||
namespace {
|
||||
|
||||
// TODO: Basic program tests (e.g. for loops)
|
||||
|
||||
TEST(Things, Ops) {
|
||||
furlang::arena arena;
|
||||
furvm::thing_allocator<std::byte> alloc{ arena };
|
||||
|
||||
furvm::thing lhs{ furvm::thing_type{ furvm::thing_type::U32 }, alloc };
|
||||
lhs.get<furvm::thing_type::u32>() = 6;
|
||||
furvm::thing rhs{ furvm::thing_type{ furvm::thing_type::U32 }, alloc };
|
||||
rhs.get<furvm::thing_type::u32>() = 7;
|
||||
|
||||
auto res = lhs.add(rhs);
|
||||
ASSERT_EQ(res.type().type, furvm::thing_type::U32);
|
||||
EXPECT_EQ(lhs.get<furvm::thing_type::u32>(), 6);
|
||||
EXPECT_EQ(rhs.get<furvm::thing_type::u32>(), 7);
|
||||
EXPECT_EQ(res.get<furvm::thing_type::u32>(), 6 + 7);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user