26
src/vm/vm.hh
26
src/vm/vm.hh
@@ -9,15 +9,31 @@ namespace tyche::vm {
|
||||
|
||||
class VM {
|
||||
public:
|
||||
void load_bytecode(ByteArray const& ba);
|
||||
VM& load_bytecode(ByteArray const& ba);
|
||||
|
||||
void call(size_t n_params);
|
||||
VM& call(size_t n_params);
|
||||
|
||||
[[nodiscard]] int32_t to_integer(int index) const;
|
||||
[[nodiscard]] bool is_nil(int index) const { return stack_.at(index).type() == Type::Nil; }
|
||||
[[nodiscard]] bool is_integer(int index) const { return stack_.at(index).type() == Type::Integer; }
|
||||
[[nodiscard]] bool is_float(int index) const { return stack_.at(index).type() == Type::Float; }
|
||||
[[nodiscard]] bool is_string(int index) const { return stack_.at(index).type() == Type::String; }
|
||||
[[nodiscard]] bool is_array(int index) const { return stack_.at(index).type() == Type::Array; }
|
||||
[[nodiscard]] bool is_table(int index) const { return stack_.at(index).type() == Type::Table; }
|
||||
[[nodiscard]] bool is_function(int index) const { return stack_.at(index).type() == Type::Function; }
|
||||
[[nodiscard]] bool is_native_pointer(int index) const { return stack_.at(index).type() == Type::NativePointer; }
|
||||
|
||||
void push_integer(int32_t value);
|
||||
[[nodiscard]] size_t stack_sz() const { return stack_.size(); }
|
||||
|
||||
[[nodiscard]] std::string debug_stack() const { return stack_.debug(); }
|
||||
VM& push_nil();
|
||||
VM& push_integer(int32_t value);
|
||||
VM& push_float(float value);
|
||||
VM& push_string(std::string const& string);
|
||||
|
||||
[[nodiscard]] int32_t to_integer(int index) const;
|
||||
[[nodiscard]] float to_float(int index) const;
|
||||
[[nodiscard]] std::string to_string(int index) const;
|
||||
|
||||
[[nodiscard]] std::string debug_stack() const { return stack_.debug(); }
|
||||
|
||||
private:
|
||||
void run_until_return();
|
||||
|
||||
Reference in New Issue
Block a user