Embedded programming language for Zig
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove `toSlice` from `Value`

IamPyu 005d601f 6690eeb6

+3 -37
+2 -3
src/env.zig
··· 86 86 try list.append(scope, try Value.initFromAny(scope, 4)); 87 87 try list.append(scope, try Value.initFromAny(scope, 5)); 88 88 89 - const slice = try list.toSlice(scope); 90 - 91 - for (slice) |v| { 89 + var iter = Value.Iter.init(list); 90 + while (iter.next()) |v| { 92 91 _ = try zexa.corelib.print(scope, &.{v}); 93 92 } 94 93
+1 -34
src/lang.zig
··· 322 322 }; 323 323 } 324 324 325 - ///Check equality with another value 325 + /// Check equality with another value 326 326 pub fn isEqual(self: *Self, other: *Self) bool { 327 327 if (self.getType() != other.getType()) { 328 328 return false; ··· 345 345 break :blk c1 and c2; 346 346 }, 347 347 }; 348 - } 349 - 350 - /// Convert this value to a slice 351 - pub fn toSlice(self: *Self, scope: *Scope) RuntimeError![]*Value { 352 - var list = try std.ArrayList(*Value).initCapacity(scope.allocator, 10); 353 - try self.toSliceInner(scope, self, &list); 354 - const slice = try list.toOwnedSlice(scope.allocator); 355 - defer scope.allocator.free(slice); 356 - 357 - const nslice = try scope.arena.allocator().alloc(*Value, slice.len); 358 - @memcpy(nslice, slice); 359 - 360 - return nslice; 361 - } 362 - 363 - fn toSliceInner( 364 - self: *Self, 365 - scope: *Scope, 366 - start: *Value, 367 - list: *std.ArrayList(*Value), 368 - ) RuntimeError!void { 369 - if (self == start) { 370 - return; 371 - } 372 - 373 - switch (self.expr) { 374 - .nil => {}, 375 - .cons => |cons| { 376 - try list.append(scope.allocator, cons.car); 377 - try cons.cdr.toSliceInner(scope, start, list); 378 - }, 379 - else => try list.append(scope.allocator, self), 380 - } 381 348 } 382 349 383 350 /// Format the value to a writer