mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
remove more cycles
This commit is contained in:
parent
6aaab3276c
commit
a41cbc3941
7 changed files with 29 additions and 34 deletions
18
src/base/DataSpan.zig
Normal file
18
src/base/DataSpan.zig
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
//! Just a small struct to take a span of data in an array
|
||||
|
||||
const DataSpan = @This();
|
||||
|
||||
start: u32,
|
||||
len: u32,
|
||||
|
||||
pub fn empty() DataSpan {
|
||||
return DataSpan{ .start = 0, .len = 0 };
|
||||
}
|
||||
|
||||
pub fn init(start: u32, len: u32) DataSpan {
|
||||
return DataSpan{ .start = start, .len = len };
|
||||
}
|
||||
|
||||
pub fn as(self: DataSpan, comptime T: type) T {
|
||||
return @as(T, .{ .span = self });
|
||||
}
|
||||
|
|
@ -6,20 +6,16 @@
|
|||
//! in constant time. Storing IDs in each IR instead of strings also uses less memory in the IRs.
|
||||
|
||||
const std = @import("std");
|
||||
const mod = @import("mod.zig");
|
||||
const Region = @import("Region.zig");
|
||||
const serialization = @import("serialization");
|
||||
const CompactWriter = serialization.CompactWriter;
|
||||
const collections = @import("collections");
|
||||
|
||||
const SmallStringInterner = mod.SmallStringInterner;
|
||||
const Region = @import("Region.zig");
|
||||
const SmallStringInterner = @import("SmallStringInterner.zig");
|
||||
|
||||
const CompactWriter = serialization.CompactWriter;
|
||||
|
||||
const Ident = @This();
|
||||
|
||||
test {
|
||||
std.testing.refAllDecls(@This());
|
||||
}
|
||||
|
||||
/// The original text of the identifier.
|
||||
raw_text: []const u8,
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const mod = @import("mod.zig");
|
||||
const DataSpan = mod.DataSpan;
|
||||
const DataSpan = @import("DataSpan.zig");
|
||||
|
||||
/// Configurable packed DataSpan with customizable bit allocation
|
||||
pub fn PackedDataSpan(comptime start_bits: u6, comptime length_bits: u6) type {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//! when working with recursive operations
|
||||
|
||||
const std = @import("std");
|
||||
const base = @import("../base.zig");
|
||||
const DataSpan = @import("DataSpan.zig");
|
||||
|
||||
/// A stack for easily adding and removing index types when doing recursive operations
|
||||
pub fn Scratch(comptime T: type) type {
|
||||
|
|
@ -45,7 +45,7 @@ pub fn Scratch(comptime T: type) type {
|
|||
|
||||
/// Creates a new span starting at start. Moves the items from scratch
|
||||
/// to extra_data as appropriate.
|
||||
pub fn spanFromStart(self: *Self, start: u32, gpa: std.mem.Allocator, data: *std.ArrayListUnmanaged(u32)) std.mem.Allocator.Error!base.DataSpan {
|
||||
pub fn spanFromStart(self: *Self, start: u32, gpa: std.mem.Allocator, data: *std.ArrayListUnmanaged(u32)) std.mem.Allocator.Error!DataSpan {
|
||||
const end = self.items.len;
|
||||
defer self.items.shrinkRetainingCapacity(start);
|
||||
var i = @as(usize, @intCast(start));
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@
|
|||
//! arrays with values corresponding 1-to-1 to interned values, e.g. regions.
|
||||
|
||||
const std = @import("std");
|
||||
const mod = @import("mod.zig");
|
||||
const collections = @import("collections");
|
||||
const serialization = @import("serialization");
|
||||
|
||||
const Region = mod.Region;
|
||||
const Region = @import("Region.zig");
|
||||
const CompactWriter = serialization.CompactWriter;
|
||||
|
||||
const Self = @This();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub const SmallStringInterner = @import("SmallStringInterner.zig");
|
|||
pub const safe_memory = @import("safe_memory.zig");
|
||||
|
||||
pub const target = @import("target.zig");
|
||||
|
||||
pub const DataSpan = @import("DataSpan.zig");
|
||||
pub const PackedDataSpan = @import("PackedDataSpan.zig").PackedDataSpan;
|
||||
pub const FunctionArgs = @import("PackedDataSpan.zig").FunctionArgs;
|
||||
pub const SmallCollections = @import("PackedDataSpan.zig").SmallCollections;
|
||||
|
|
@ -94,21 +94,3 @@ pub const NumLiteral = union(enum) {
|
|||
Int: IntLiteral,
|
||||
Frac: FracLiteral,
|
||||
};
|
||||
|
||||
/// Just a small struct to take a span of data in an array
|
||||
pub const DataSpan = struct {
|
||||
start: u32,
|
||||
len: u32,
|
||||
|
||||
pub fn empty() DataSpan {
|
||||
return DataSpan{ .start = 0, .len = 0 };
|
||||
}
|
||||
|
||||
pub fn init(start: u32, len: u32) DataSpan {
|
||||
return DataSpan{ .start = start, .len = len };
|
||||
}
|
||||
|
||||
pub fn as(self: DataSpan, comptime T: type) T {
|
||||
return @as(T, .{ .span = self });
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const collections = @import("collections");
|
|||
const tracy = @import("tracy");
|
||||
const compile = @import("compile");
|
||||
|
||||
const DataSpan = base.DataSpan;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
|
||||
/// representation of a token in the source code, like '+', 'foo', '=', '{'
|
||||
|
|
@ -37,7 +38,7 @@ pub const Token = struct {
|
|||
pub const List = std.MultiArrayList(@This());
|
||||
|
||||
pub const Idx = u32;
|
||||
pub const Span = struct { span: base.DataSpan };
|
||||
pub const Span = struct { span: DataSpan };
|
||||
|
||||
pub const Tag = enum(u8) {
|
||||
EndOfFile,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue