diff --git a/.gitignore b/.gitignore index e257658..e820098 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ *.out *.app +cmake-build-*/ +build/ diff --git a/.idea/tyche.iml b/.idea/tyche.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/tyche.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/vm/vm.cc b/src/vm/vm.cc index 1a602f4..b8854b2 100644 --- a/src/vm/vm.cc +++ b/src/vm/vm.cc @@ -36,12 +36,25 @@ int32_t VM::to_integer(int index) const return i.as_integer(); } +float VM::to_float(int index) const +{ + Value i = stack_.at(index); + assert_type(i, Type::Float); + return i.as_float(); +} + VM& VM::push_integer(int32_t value) { stack_.push(Value::CreateInteger(value)); return *this; } +VM& VM::push_float(float value) +{ + stack_.push(Value::CreateFloat(value)); + return *this; +} + void VM::run_until_return() { size_t level = stack_.fp_level(); diff --git a/src/vm/vm.hh b/src/vm/vm.hh index 6ecd22a..e555bb6 100644 --- a/src/vm/vm.hh +++ b/src/vm/vm.hh @@ -14,8 +14,10 @@ public: VM& call(size_t n_params); [[nodiscard]] int32_t to_integer(int index) const; + [[nodiscard]] float to_float(int index) const; VM& push_integer(int32_t value); + VM& push_float(float value); [[nodiscard]] std::string debug_stack() const { return stack_.debug(); }