diff --git a/src/builtin/range.zig b/src/builtin/range.zig index 0fe30cba..e9cb657d 100644 --- a/src/builtin/range.zig +++ b/src/builtin/range.zig @@ -71,3 +71,17 @@ pub fn invert(ctx: *obj.NativeCtx) c_int { return 1; } + +pub fn subsetOf(ctx: *obj.NativeCtx) c_int { + const rangeA = ctx.vm.peek(1).obj().access(obj.ObjRange, .Range, ctx.vm.gc).?; + const rangeB = ctx.vm.peek(0).obj().access(obj.ObjRange, .Range, ctx.vm.gc).?; + + ctx.vm.push( + Value.fromBoolean( + @min(rangeA.low, rangeA.high) >= @min(rangeB.low, rangeB.high) and + @max(rangeA.low, rangeA.high) <= @max(rangeB.low, rangeB.high), + ), + ); + + return 1; +} diff --git a/src/obj.zig b/src/obj.zig index f3127c99..a40ae762 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -2499,6 +2499,7 @@ pub const ObjRange = struct { .{ "toList", buzz_builtin.range.toList }, .{ "len", buzz_builtin.range.len }, .{ "invert", buzz_builtin.range.invert }, + .{ "subsetOf", buzz_builtin.range.subsetOf }, }, ); @@ -2507,6 +2508,7 @@ pub const ObjRange = struct { .{ "toList", "extern Function toList() > [int]" }, .{ "len", "extern Function len() > int" }, .{ "invert", "extern Function invert() > rg" }, + .{ "subsetOf", "extern Function subsetOf(rg other) > bool" }, }, );