-
Notifications
You must be signed in to change notification settings - Fork 5
/
function.cpp
45 lines (36 loc) · 910 Bytes
/
function.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <compiler.hpp>
#include <function.hpp>
#include <gc.hpp>
#include <list.hpp>
#include <upvalue.hpp>
namespace vy {
u32 CodeBlock::add_param() {
++m_num_params;
VYSE_ASSERT(m_num_params < Compiler::MaxFuncParams, "Too many function parameters.");
return m_num_params;
}
void CodeBlock::trace(GC& gc) {
gc.mark_object(m_name);
for (Value val : m_block.constant_pool) {
gc.mark_value(val);
}
}
/// Function ///
Closure::Closure(CodeBlock* code, u32 upval_count) noexcept
: Obj(ObjType::closure), m_codeblock{code} {
m_upvals.resize(upval_count);
}
void Closure::set_upval(u32 idx, Upvalue* uv) {
VYSE_ASSERT(idx < m_upvals.size(), "Invalid upvalue index.");
m_upvals[idx] = uv;
}
void Closure::trace(GC& gc) {
for (Upvalue* upval : m_upvals) {
gc.mark_object(upval);
}
gc.mark_object(m_codeblock);
}
void CClosure::trace(GC& gc) {
gc.mark_object(m_values);
}
} // namespace vy