File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -111,3 +111,29 @@ pub fn intersect(ctx: *obj.NativeCtx) c_int {
111
111
112
112
return 1 ;
113
113
}
114
+
115
+ pub fn @"union" (ctx : * obj.NativeCtx ) c_int {
116
+ const rangeA = ctx .vm .peek (1 ).obj ().access (obj .ObjRange , .Range , ctx .vm .gc ).? ;
117
+ const rangeB = ctx .vm .peek (0 ).obj ().access (obj .ObjRange , .Range , ctx .vm .gc ).? ;
118
+
119
+ ctx .vm .push (
120
+ Value .fromObj ((ctx .vm .gc .allocateObject (
121
+ obj .ObjRange ,
122
+ obj.ObjRange {
123
+ .high = @min (
124
+ @min (rangeB .low , rangeB .high ),
125
+ @min (rangeA .low , rangeA .high ),
126
+ ),
127
+ .low = @max (
128
+ @max (rangeB .low , rangeB .high ),
129
+ @max (rangeA .low , rangeA .high ),
130
+ ),
131
+ },
132
+ ) catch {
133
+ ctx .vm .panic ("Out of memory" );
134
+ unreachable ;
135
+ }).toObj ()),
136
+ );
137
+
138
+ return 1 ;
139
+ }
Original file line number Diff line number Diff line change @@ -2501,6 +2501,7 @@ pub const ObjRange = struct {
2501
2501
.{ "invert" , buzz_builtin .range .invert },
2502
2502
.{ "subsetOf" , buzz_builtin .range .subsetOf },
2503
2503
.{ "intersect" , buzz_builtin .range .intersect },
2504
+ .{ "union" , buzz_builtin .range .@"union" },
2504
2505
},
2505
2506
);
2506
2507
@@ -2511,6 +2512,7 @@ pub const ObjRange = struct {
2511
2512
.{ "invert" , "extern Function invert() > rg" },
2512
2513
.{ "subsetOf" , "extern Function subsetOf(rg other) > bool" },
2513
2514
.{ "intersect" , "extern Function intersect(rg other) > rg" },
2515
+ .{ "union" , "extern Function union(rg other) > rg" },
2514
2516
},
2515
2517
);
2516
2518
You can’t perform that action at this time.
0 commit comments