Closures, Higher-Order Functions, and Everything in Between #44
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: kayomn/ona#44
Loading…
Reference in New Issue
No description provided.
Delete Branch "kym-captures"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements closures into Kym's Chunk-based execution model.
WIP: Closures, Higher-Order Functions, and Everything in Betweento Closures, Higher-Order Functions, and Everything in Between@ -197,2 +197,4 @@
_ = writer;
_ = value;
return null;
TODO functions should be unreachable and have a comment.
@ -573,6 +650,7 @@ pub const RuntimeEnv = struct {
break: convert self.new_string(string[0 .. length.?]);
},
.boxed => unreachable,
Why unreachable?
@ -757,6 +861,8 @@ pub const RuntimeRef = opaque {
else => false,
},
.boxed => unreachable,
Why unreachable?
@ -12,6 +16,11 @@ name: *kym.RuntimeRef,
arity: u8,
opcodes: OpcodeList,
constants: ConstList,
bindings: []?*kym.RuntimeRef,
May be worth replacing with VM managed Buffer object rather than raw Zig array.
Actually this is out of scope and really a non-issue right now.
@ -14,1 +18,4 @@
constants: ConstList,
bindings: []?*kym.RuntimeRef,
const Box = struct {
What is this for?
@ -150,3 +170,2 @@
while (opcode_cursor < chunk.opcodes.values.len) : (opcode_cursor += 1) {
switch (chunk.opcodes.values[opcode_cursor]) {
while (opcode_cursor < self.opcodes.values.len) : (opcode_cursor += 1) {
All these raw illegal state calls may be better as a VM-managed assert function.
@ -514,0 +635,4 @@
coral.debug.assert(string != null);
app.log_info(string.?);
}
Debugging code wants removing or moving somewhere else that is easier to switch on or off.
@ -551,3 +677,3 @@
pub const typeinfo = &kym.Typeinfo{
.size = @sizeOf(Self),
.name = "lambda",
.name = "func",
Why rename?
@ -352,0 +390,4 @@
coral.debug.assert(capture.* == .declaration_index);
if (&target_environment.declarations[capture.declaration_index] == declaration) {
This shouldn't be capable of crashing the process - needs better handling.
@ -129,0 +120,4 @@
.declaration = declare: {
if (is_constant) {
break: declare environment.declare_constant(identifier) catch |declaration_error| {
return switch (declaration_error) {
Shorten to use
root.report_declare_error
.@ -129,0 +132,4 @@
}
break: declare environment.declare_variable(identifier) catch |declaration_error| {
return switch (declaration_error) {
Shorten to use
root.report_declare_error
.@ -24,0 +29,4 @@
capture_index: u8,
};
const DeclareError = coral.io.AllocationError || error {
Should ideally be marked pub as is used on public interface for struct.