Temporarily drop testing of Kym library
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kayomn 2023-02-22 23:19:42 +00:00
parent f9ac5831cf
commit 2dd7946b88
4 changed files with 2 additions and 289 deletions

View File

@ -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)

View File

@ -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<coral::u64 *>(this->data)) =
(*reinterpret_cast<coral::u64 *>(&integer));
this->type = value_type::integer;
}
value(coral::f64 scalar) {
(*reinterpret_cast<coral::u64 *>(this->data)) =
(*reinterpret_cast<coral::u64 *>(&scalar));
this->type = value_type::scalar;
}
value(coral::vector2 vector2) {
(*reinterpret_cast<coral::u64 *>(this->data)) =
(*reinterpret_cast<coral::u64 *>(&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<coral::i64> to_integer() const {
if (this->type == value_type::integer)
return (*reinterpret_cast<coral::i64 const *>(&this->data));
return {};
}
private:
coral::u8 data[12]{0};
};
};

View File

@ -1,182 +0,0 @@
export module kym.environment;
import coral;
import coral.sequence;
import kym;
using loggable = coral::callable<void(coral::slice<char const> const &)>;
export namespace kym {
struct vm;
}
enum class token_kind {
end,
};
struct token {
coral::slice<char const> text;
token_kind kind;
};
struct tokenizer {
coral::slice<char const> source;
tokenizer(coral::slice<char const> 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<kym::value const> const & arguments) {
return {};
}
private:
coral::stack<char> error_message_buffer;
};
export namespace kym {
value default_call(vm & owning_vm, void * userdata, coral::slice<value const> const & arguments) {
return {};
}
coral::expected<coral::usize, coral::io_error> 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<value const> const &);
coral::expected<coral::usize, coral::io_error>(*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<value const> const & arguments) {
return this->behavior.call(*this->owning_vm, this->userdata, arguments);
}
coral::expected<coral::usize, coral::io_error> stringify(coral::writer & output) {
return this->behavior.stringify(*this->owning_vm, this->userdata, output);
}
value get_field(coral::slice<char const> 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
<coral::u8 *>(this->data_stack.pointer), options.datastack_size * sizeof(value));
if (data_stack_buffer == nullptr) return false;
this->data_stack = {
reinterpret_cast<value * >(data_stack_buffer), options.datastack_size};
return true;
}
value compile(coral::slice<char const> const & source) {
bytecode * source_bytecode = new (*this->allocator) bytecode{allocator};
if (source_bytecode == nullptr) return {};
if (!source_bytecode->compile(tokenizer{source}, [&](coral::slice<char const> 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<value const> const & arguments) -> value {
return reinterpret_cast<bytecode *>(userdata)->execute(owning_vm, arguments);
};
this->allocator->deallocate(source_bytecode);
});
}
value new_object(coral::callable<void(bound_object &)> const & then) {
return {};
}
void with_object(value object_value, coral::callable<void(bound_object &)> const & then) {
}
private:
coral::slice<value> data_stack;
loggable log;
coral::allocator * allocator;
};
}

View File

@ -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<char const> 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<coral::u8> 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<coral::i16> {
if ((value >= 0) && (value <= coral::u16_max))
return static_cast<coral::u16>(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) {