File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,15 @@ const TestValue = union(Tag) {
52
52
}
53
53
}
54
54
55
- pub const call = scripty .defaultCall (TestValue );
55
+ pub const call = scripty .defaultCall (TestValue , TestContext );
56
56
57
57
pub fn builtinsFor (comptime tag : Tag ) type {
58
58
const StringBuiltins = struct {
59
59
pub const len = struct {
60
60
pub fn call (
61
61
str : []const u8 ,
62
62
gpa : std.mem.Allocator ,
63
+ _ : * const TestContext ,
63
64
args : []const TestValue ,
64
65
) ! TestValue {
65
66
if (args .len != 0 ) return .{ .err = "'len' wants no arguments" };
Original file line number Diff line number Diff line change @@ -29,16 +29,18 @@ pub fn defaultDot(
29
29
}.dot ;
30
30
}
31
31
32
- pub fn defaultCall (comptime Value : type ) fn (
32
+ pub fn defaultCall (Value : type , Context : type ) fn (
33
33
Value ,
34
34
std .mem .Allocator ,
35
+ * const Context ,
35
36
[]const u8 ,
36
37
[]const Value ,
37
38
) error { OutOfMemory , Interrupt }! Value {
38
39
return struct {
39
40
pub fn call (
40
41
value : Value ,
41
42
gpa : std.mem.Allocator ,
43
+ ctx : * const Context ,
42
44
fn_name : []const u8 ,
43
45
args : []const Value ,
44
46
) error { OutOfMemory , Interrupt }! Value {
@@ -55,6 +57,7 @@ pub fn defaultCall(comptime Value: type) fn (
55
57
return @field (Builtin , decl .name ).call (
56
58
v ,
57
59
gpa ,
60
+ ctx ,
58
61
args ,
59
62
);
60
63
}
@@ -63,6 +66,7 @@ pub fn defaultCall(comptime Value: type) fn (
63
66
if (hasDecl (@TypeOf (v ), "fallbackCall" )) {
64
67
return v .fallbackCall (
65
68
gpa ,
69
+ ctx ,
66
70
fn_name ,
67
71
args ,
68
72
);
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ pub fn VM(
257
257
stack_locs [call_idx ].start = call_loc .start ;
258
258
stack_locs [call_idx ].end = call_loc .end + 1 ;
259
259
260
- const new_value = old_value .call (gpa , fn_name , args ) catch | err | switch (err ) {
260
+ const new_value = old_value .call (gpa , ctx , fn_name , args ) catch | err | switch (err ) {
261
261
error .OutOfMemory = > return error .OutOfMemory ,
262
262
error .Interrupt = > {
263
263
vm .state = .waiting ;
@@ -340,14 +340,15 @@ pub const TestValue = union(Tag) {
340
340
}
341
341
}
342
342
343
- pub const call = types .defaultCall (TestValue );
343
+ pub const call = types .defaultCall (TestValue , TestContext );
344
344
345
345
pub fn builtinsFor (comptime tag : Tag ) type {
346
346
const StringBuiltins = struct {
347
347
pub const len = struct {
348
348
pub fn call (
349
349
str : []const u8 ,
350
350
gpa : std.mem.Allocator ,
351
+ _ : * const TestContext ,
351
352
args : []const TestValue ,
352
353
) ! TestValue {
353
354
if (args .len != 0 ) return .{
@@ -360,6 +361,7 @@ pub const TestValue = union(Tag) {
360
361
pub fn call (
361
362
str : []const u8 ,
362
363
gpa : std.mem.Allocator ,
364
+ _ : * const TestContext ,
363
365
args : []const TestValue ,
364
366
) ! TestValue {
365
367
if (args .len != 0 ) return .{
You can’t perform that action at this time.
0 commit comments