Native "Syscall" Interface for Kym #21

Merged
kayomn merged 6 commits from kym-native-function into main 2023-07-22 15:03:22 +02:00
Owner

Closes #20.

By default, the following syscalls are exposed:

  • log_info Writes an entry to the info log.
  • log_warn Writes an entry to the warning log.
  • log_fail Writes an entry to the failure log.
Closes #20. By default, the following syscalls are exposed: * `log_info` Writes an entry to the info log. * `log_warn` Writes an entry to the warning log. * `log_fail` Writes an entry to the failure log.
kayomn added this to the (deleted) milestone 2023-07-14 21:08:30 +02:00
kayomn self-assigned this 2023-07-14 21:08:30 +02:00
kayomn added 1 commit 2023-07-19 00:53:01 +02:00
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
1828eb3b45
Refactor Kym runtime values to be objects
kayomn added 2 commits 2023-07-22 00:03:32 +02:00
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
1ea115b277
Replace globals with native call interface
kayomn added 2 commits 2023-07-22 13:37:24 +02:00
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
8137f2b474
Fix memory leaks
kayomn changed title from WIP: Native Function Calling and Binding for Kym to Native Function Calling and Binding for Kym 2023-07-22 13:37:47 +02:00
kayomn changed title from Native Function Calling and Binding for Kym to Native "Syscall" Interface for Kym 2023-07-22 13:42:36 +02:00
kayomn reviewed 2023-07-22 13:56:01 +02:00
@ -16,6 +16,16 @@ pub fn Stack(comptime Value: type) type {
self.values = self.values[0 .. 0];
}
pub fn drop(self: *Self, amount: usize) bool {
Author
Owner

Unused function.

Unused function.
kayomn marked this conversation as resolved
@ -77,0 +128,4 @@
}
fn write_stack(stack: *ByteStack, bytes: []const io.Byte) ?usize {
stack.push_all(bytes) catch return null;
Author
Owner

Can be simplified to single expression

Can be simplified to single expression
kayomn marked this conversation as resolved
@ -89,1 +110,4 @@
});
}
pub fn Table(comptime Key: type, comptime Value: type, comptime traits: TableTraits(Key)) type {
Author
Owner

A lot of duplication with @typeInfo(usize).Int and getting min / max limits of int types in general. These could be reduced into a constants declared in function body to reduce repetition.

A lot of duplication with `@typeInfo(usize).Int` and getting min / max limits of int types in general. These could be reduced into a constants declared in function body to reduce repetition.
kayomn marked this conversation as resolved
@ -13,41 +13,55 @@ pub const Manifest = struct {
tick_rate: f32 = 60.0,
pub fn load(self: *Manifest, env: *kym.RuntimeEnv, file_access: file.Access) kym.RuntimeError!void {
Author
Owner

Resolve TODOs in the function body.

Resolve TODOs in the function body.
kayomn marked this conversation as resolved
@ -70,2 +77,2 @@
severity: LogSeverity,
write_buffer: coral.list.ByteStack,
pub fn log_info(message: []const coral.io.Byte) void {
ext.SDL_LogInfo(ext.SDL_LOG_CATEGORY_APPLICATION, "%.*s", @as(c_int, @intCast(message.len)), message.ptr);
Author
Owner

Potentially (but very unlikely to ever trigger) unsafe length cast.

Could do with clamping the length to the max buffer to be safe.

Potentially (but very unlikely to ever trigger) unsafe length cast. Could do with clamping the length to the max buffer to be safe.
kayomn marked this conversation as resolved
@ -75,2 +81,2 @@
fn write(writable_log: *WritableLog, bytes: []const coral.io.Byte) ?usize {
writable_log.write(bytes) catch return null;
pub fn log_warn(message: []const coral.io.Byte) void {
ext.SDL_LogWarn(ext.SDL_LOG_CATEGORY_APPLICATION, "%.*s", @as(c_int, @intCast(message.len)), message.ptr);
Author
Owner

Potentially (but very unlikely to ever trigger) unsafe length cast.

Could do with clamping the length to the max buffer to be safe.

Potentially (but very unlikely to ever trigger) unsafe length cast. Could do with clamping the length to the max buffer to be safe.
kayomn marked this conversation as resolved
@ -127,2 +85,2 @@
}
};
pub fn log_fail(message: []const coral.io.Byte) void {
ext.SDL_LogError(ext.SDL_LOG_CATEGORY_APPLICATION, "%.*s", @as(c_int, @intCast(message.len)), message.ptr);
Author
Owner

Potentially (but very unlikely to ever trigger) unsafe length cast.

Could do with clamping the length to the max buffer to be safe.

Potentially (but very unlikely to ever trigger) unsafe length cast. Could do with clamping the length to the max buffer to be safe.
kayomn marked this conversation as resolved
@ -419,3 +239,3 @@
}
const return_value = try self.state.pop_value();
return self.local_refs.values[local];
Author
Owner

Does this operation "get" like the name suggests (acquiring a reference) or is it an immutable view like the current implementation suggests?

Does this operation "get" like the name suggests (acquiring a reference) or is it an immutable view like the current implementation suggests?
kayomn marked this conversation as resolved
@ -209,6 +221,45 @@ pub fn parse(self: *Self, tokenizer: *tokens.Tokenizer) ParseError!void {
}
},
.global => |identifier| {
Author
Owner

Inaccurate name for syscall.

Inaccurate name for syscall.
kayomn marked this conversation as resolved
@ -264,6 +333,48 @@ fn parse_factor(self: *Self, tokenizer: *tokens.Tokenizer) ParseError!Expression
return Expression{.string_literal = value};
},
.global => |identifier| {
Author
Owner

Inaccurate name for syscall.

Inaccurate name for syscall.
kayomn marked this conversation as resolved
@ -25,2 +24,3 @@
}
const Self = @This();
pub const typeinfo = kym.Typeinfo{
Author
Owner

Does this need to be public?

Does this need to be public?
kayomn marked this conversation as resolved
@ -52,0 +67,4 @@
.caller = kym.Caller.from(kym_log_fail),
},
}) catch {
return app.log_fail("failed to initialize script runtime");
Author
Owner

Inaccurate log message.

Inaccurate log message.
kayomn marked this conversation as resolved
@ -2,3 +2,2 @@
pub fn main() ona.RuntimeError!void {
try ona.run_app(.{.sandboxed_path = &ona.file.Path.cwd});
pub fn main() anyerror!void {
Author
Owner

Error union is unused.

Error union is unused.
kayomn marked this conversation as resolved
kayomn added 1 commit 2023-07-22 14:57:47 +02:00
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
a320a795bc
Amend code review issues
kayomn merged commit 5d06e61564 into main 2023-07-22 15:03:22 +02:00
kayomn deleted branch kym-native-function 2023-07-22 15:03:22 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: kayomn/ona#21
No description provided.