ArkScript
A small, fast, functional and scripting language for video games
Closure.cpp
Go to the documentation of this file.
2 
3 #include <Ark/VM/Scope.hpp>
4 #include <Ark/VM/Value.hpp>
5 #include <Ark/VM/VM.hpp>
6 
7 namespace Ark::internal
8 {
9  Closure::Closure() noexcept :
10  m_scope(nullptr),
11  m_page_addr(0)
12  {}
13 
14  Closure::Closure(Scope_t&& scope_ptr, PageAddr_t pa) noexcept :
15  m_scope(scope_ptr),
16  m_page_addr(pa)
17  {}
18 
19  Closure::Closure(const Scope_t& scope_ptr, PageAddr_t pa) noexcept :
20  m_scope(scope_ptr),
21  m_page_addr(pa)
22  {}
23 
24  const Scope_t& Closure::scope() const noexcept
25  {
26  return m_scope;
27  }
28 
30  {
31  return m_scope;
32  }
33 
34  void Closure::toString(std::ostream& os, VM& vm) const noexcept
35  {
36  os << "(";
37  for (std::size_t i = 0, end = m_scope->m_data.size(); i < end; ++i)
38  {
39  if (i != 0)
40  os << ' ';
41 
42  os << '.' << vm.m_state.m_symbols[m_scope->m_data[i].first] << '=';
43  m_scope->m_data[i].second.toString(os, vm);
44  }
45  os << ")";
46  }
47 }
Subtype of the value type, handling closures.
The virtual machine scope system.
The ArkScript virtual machine.
The ArkScript virtual machine, executing ArkScript bytecode.
Definition: VM.hpp:47
const Scope_t & scope() const noexcept
Return the scope held by the object.
Definition: Closure.cpp:24
Scope_t & refScope() noexcept
Return a reference to the scpoe held by the object.
Definition: Closure.cpp:29
void toString(std::ostream &os, VM &vm) const noexcept
Print the closure to a string.
Definition: Closure.cpp:34
Closure() noexcept
Construct a new Closure object.
Definition: Closure.cpp:9
std::shared_ptr< Scope > Scope_t
Scope handling.
Definition: Closure.hpp:37
uint16_t PageAddr_t
Definition: Closure.hpp:38