diff --git a/build.py b/build.py index e05da45..785f475 100755 --- a/build.py +++ b/build.py @@ -31,6 +31,5 @@ def compile_package(root_module_name: str) -> None: compile_package("coral") compile_package("oar") compile_package("app") -compile_package("kym") compile_package("runtime") subprocess.run(f"{compile_command} {' '.join(object_file_paths)} -o ./runtime -lSDL2", shell=True, check=True) diff --git a/source/kym.cpp b/source/kym.cpp deleted file mode 100644 index faec578..0000000 --- a/source/kym.cpp +++ /dev/null @@ -1,64 +0,0 @@ -export module kym; - -import coral; -import coral.math; - -export namespace kym { - enum class value_type { - nil, - boolean, - integer, - scalar, - vector2, - vector3, - object, - }; - - struct value { - value_type type{value_type::nil}; - - value() = default; - - value(bool boolean) { - this->data[1] = 0xff * boolean; - this->type = value_type::boolean; - } - - value(coral::i64 integer) { - (*reinterpret_cast(this->data)) = - (*reinterpret_cast(&integer)); - - this->type = value_type::integer; - } - - value(coral::f64 scalar) { - (*reinterpret_cast(this->data)) = - (*reinterpret_cast(&scalar)); - - this->type = value_type::scalar; - } - - value(coral::vector2 vector2) { - (*reinterpret_cast(this->data)) = - (*reinterpret_cast(&vector2)); - - this->type = value_type::vector2; - } - - value(coral::vector3 const & vector3) { - coral::copy(this->data, coral::as_bytes(&vector3)); - - this->type = value_type::vector3; - } - - coral::optional to_integer() const { - if (this->type == value_type::integer) - return (*reinterpret_cast(&this->data)); - - return {}; - } - - private: - coral::u8 data[12]{0}; - }; -}; diff --git a/source/kym/environment.cpp b/source/kym/environment.cpp deleted file mode 100644 index b437ddc..0000000 --- a/source/kym/environment.cpp +++ /dev/null @@ -1,182 +0,0 @@ -export module kym.environment; - -import coral; -import coral.sequence; - -import kym; - -using loggable = coral::callable const &)>; - -export namespace kym { - struct vm; -} - -enum class token_kind { - end, -}; - -struct token { - coral::slice text; - - token_kind kind; -}; - -struct tokenizer { - coral::slice source; - - tokenizer(coral::slice const & source) : source{source} {} - - token next() { - coral::usize cursor = 0; - - while (cursor < source.length) { - - } - - return token{ - .kind = token_kind::end, - }; - } -}; - -struct bytecode { - bytecode(coral::allocator * allocator) : error_message_buffer{allocator} { - - } - - bool compile(tokenizer bytecode_tokenizer, loggable const & log_error) { - for (;;) { - token const initial_token = bytecode_tokenizer.next(); - - switch (initial_token.kind) { - case token_kind::end: return true; - - default: coral::unreachable(); - } - } - } - - kym::value execute(kym::vm & vm, coral::slice const & arguments) { - return {}; - } - - private: - coral::stack error_message_buffer; -}; - -export namespace kym { - value default_call(vm & owning_vm, void * userdata, coral::slice const & arguments) { - return {}; - } - - coral::expected default_stringify(vm & owning_vm, void * userdata, coral::writer & output) { - return output.write(coral::slice{"[object]"}.as_bytes()); - } - - struct bound_object { - void * userdata; - - struct { - void(*cleanup)(vm &, void *); - - value(*call)(vm &, void *, coral::slice const &); - - coral::expected(*stringify)(vm &, void *, coral::writer &); - } behavior; - - bound_object(vm * owning_vm) : userdata{nullptr}, owning_vm{owning_vm}, behavior{ - .cleanup = [](vm & owning_vm, void * userdata) {}, - .call = default_call, - .stringify = default_stringify, - } {} - - void cleanup() { - this->behavior.cleanup(*this->owning_vm, this->userdata); - } - - value call(coral::slice const & arguments) { - return this->behavior.call(*this->owning_vm, this->userdata, arguments); - } - - coral::expected stringify(coral::writer & output) { - return this->behavior.stringify(*this->owning_vm, this->userdata, output); - } - - value get_field(coral::slice const & field_name) { - return {}; - } - - private: - vm * owning_vm; - }; - - struct vm { - struct init_options { - coral::u16 datastack_size; - - coral::u16 callstack_size; - }; - - vm(coral::allocator * allocator, auto log) : allocator{allocator}, log{log}, data_stack{} {} - - ~vm() { - if (this->data_stack.pointer != nullptr) - this->allocator->deallocate(this->data_stack.pointer); - } - - bool init(init_options const & options) { - coral::u8 * const data_stack_buffer = this->allocator->reallocate(reinterpret_cast - (this->data_stack.pointer), options.datastack_size * sizeof(value)); - - if (data_stack_buffer == nullptr) return false; - - this->data_stack = { - reinterpret_cast(data_stack_buffer), options.datastack_size}; - - return true; - } - - value compile(coral::slice const & source) { - bytecode * source_bytecode = new (*this->allocator) bytecode{allocator}; - - if (source_bytecode == nullptr) return {}; - - if (!source_bytecode->compile(tokenizer{source}, [&](coral::slice error_message) { - this->log(error_message); - })) { - this->allocator->deallocate(source_bytecode); - - return {}; - } - - return this->new_object([this, source_bytecode](bound_object & object) { - object.userdata = source_bytecode; - - object.behavior.cleanup = [](vm & owning_vm, void * userdata) { - owning_vm.allocator->deallocate(userdata); - }; - - object.behavior.call = [](vm & owning_vm, void * userdata, coral::slice const & arguments) -> value { - return reinterpret_cast(userdata)->execute(owning_vm, arguments); - }; - - this->allocator->deallocate(source_bytecode); - }); - } - - value new_object(coral::callable const & then) { - return {}; - } - - void with_object(value object_value, coral::callable const & then) { - - } - - private: - coral::slice data_stack; - - loggable log; - - coral::allocator * allocator; - }; -} diff --git a/source/runtime.cpp b/source/runtime.cpp index 095a5c1..3a7a422 100644 --- a/source/runtime.cpp +++ b/source/runtime.cpp @@ -8,9 +8,6 @@ import coral.io; import coral.math; import coral.sequence; -import kym; -import kym.environment; - extern "C" int main(int argc, char const * const * argv) { return app::display("Ona Runtime", [](app::system & system, app::graphics & graphics) -> int { constexpr coral::path config_path{"config.kym"}; @@ -19,16 +16,6 @@ extern "C" int main(int argc, char const * const * argv) { system.res_fs().read_file(config_path, [&](coral::reader & file) { coral::allocator * const allocator{&system.thread_safe_allocator()}; - kym::vm vm{allocator, [&system](coral::slice const & error_message) { - system.log(app::log_level::error, error_message); - }}; - - if (!vm.init({.datastack_size = 64, .callstack_size = 64})) { - system.log(app::log_level::error, "failed to allocate memory for config vm"); - - return; - } - coral::stack script_source{allocator}; { coral::u8 stream_buffer[1024]{0}; @@ -37,36 +24,9 @@ extern "C" int main(int argc, char const * const * argv) { if (!coral::stream(script_writer, file, stream_buffer).is_ok()) return; } - vm.with_object(vm.compile(script_source.as_slice().as_chars()), [&](kym::bound_object & script) { - vm.with_object(script.call({}), [&](kym::bound_object & config) { - constexpr auto to_u16 = [](coral::i64 value) -> coral::optional { - if ((value >= 0) && (value <= coral::u16_max)) - return static_cast(value); + system.log(app::log_level::notice, script_source.as_slice().as_chars()); - return {}; - }; - - coral::u16 const width{config.get_field("width"). - to_integer().map(to_u16).value_or(0)}; - - if (width == 0) return system.log(app::log_level::error, - "failed to decode `width` property of config"); - - coral::u16 const height{config.get_field("height"). - to_integer().map(to_u16).value_or(0)}; - - if (height == 0) return system.log(app::log_level::error, - "failed to decode `height` property of config"); - - if (graphics.show(width, height) != app::graphics::show_result::ok) - return system.log(app::log_level::error, "failed to initialize window"); - - vm.with_object(config.get_field("title"), [&](kym::bound_object & title) { - // TODO: implement. - is_config_loaded = true; - }); - }); - }); + is_config_loaded = true; }); if (!is_config_loaded) {