| author | |
| committer | |
| log | 84a6254c0de7dd1bcd097da3898d2b4cb8c4b64e |
| tree | 06836771054a46299091cc2111735cc17a25728a |
| parent | 2205bf12c2792b8eef92453a207a8521c32055c4 |
| signature | Signed by PGP key B5690EEEBB952194 |
12 files changed, 49 insertions(+), 49 deletions(-)
doc/language-manual.md+6-6| ... | @@ -11,8 +11,8 @@ Key goals of this project are: | ... | @@ -11,8 +11,8 @@ Key goals of this project are: |
| 11 | It primarily focuses on merging some great points of Rust, Zig, and JavaScript's language designs: | 11 | It primarily focuses on merging some great points of Rust, Zig, and JavaScript's language designs: |
| 12 | 12 | ||
| 13 | - **Rust** - Expressive control flow that is easy to write. | 13 | - **Rust** - Expressive control flow that is easy to write. |
| 14 | - **Zig** - Execute any code at compile time, everything is an expression. | 14 | - **Zig** - Execute any code at compile time; everything is an expression. |
| 15 | - **JavaScript** - Garbage collected values with a versitile type system. | 15 | - **JavaScript** - Garbage collected values with a versatile type system. |
| 16 | 16 | ||
| 17 | ## Standard Library | 17 | ## Standard Library |
| 18 | 18 | ||
| ... | @@ -25,9 +25,9 @@ let print = @js("console").log; | ... | @@ -25,9 +25,9 @@ let print = @js("console").log; |
| 25 | print("Hello, world!"); | 25 | print("Hello, world!"); |
| 26 | ``` | 26 | ``` |
| 27 | 27 | ||
| 28 | The `print` function is implemented by getting an external reference to the `console` JavaScript global, and then retriving the `log` property from it. | 28 | The `print` function is implemented by getting an external reference to the `console` JavaScript global and then retrieving the `log` property from it. |
| 29 | 29 | ||
| 30 | ## Primative Data Types | 30 | ## Primitive Data Types |
| 31 | 31 | ||
| 32 | | name | ts equivilent | description | | 32 | | name | ts equivilent | description | |
| 33 | | ---------- | --------------------- | ---------------------------------------------- | | 33 | | ---------- | --------------------- | ---------------------------------------------- | |
| ... | @@ -36,7 +36,7 @@ The `print` function is implemented by getting an external reference to the `con | ... | @@ -36,7 +36,7 @@ The `print` function is implemented by getting an external reference to the `con |
| 36 | | `bool` | `boolean` | either `true` or `false` | | 36 | | `bool` | `boolean` | either `true` or `false` | |
| 37 | | `string` | `string` | a sequence of text characters | | 37 | | `string` | `string` | a sequence of text characters | |
| 38 | | `void` | `undefined` or `null` | detectable lack of a value | | 38 | | `void` | `undefined` or `null` | detectable lack of a value | |
| 39 | | `opaque` | `unknown` or `any` | could be any value | | 39 | | `opaque` | `unknown` or `any` | could be any value | |
| 40 | | `noreturn` | `never` | control flow prevents this value from existing | | 40 | | `noreturn` | `never` | control flow prevents this value from existing | |
| 41 | 41 | ||
| 42 | > **note**: `bigint` is planned but not added | 42 | > **note**: `bigint` is planned but not added |
| ... | @@ -61,7 +61,7 @@ let true = 1 == 0; | ... | @@ -61,7 +61,7 @@ let true = 1 == 0; |
| 61 | 61 | ||
| 62 | There are two types of variables, `let` and `var`. | 62 | There are two types of variables, `let` and `var`. |
| 63 | 63 | ||
| 64 | `let` bindings cannot be overridden, and should be thought of as aliases of the expression within. Referring to these identifiers is equivilent to inlining it's where it was used, aside from side effect duplication. | 64 | `let` bindings cannot be overridden, and should be thought of as aliases of the expression within. Referring to these identifiers is equivalent to inlining it where it was used, aside from side effect duplication. |
| 65 | 65 | ||
| 66 | ```lang:run | 66 | ```lang:run |
| 67 | let hello: int = 1; | 67 | let hello: int = 1; |
src/core/Ast.zig+6-6| ... | @@ -1,11 +1,11 @@ | ... | @@ -1,11 +1,11 @@ |
| 1 | //! The Abstract Syntax Tree preserves most details of the source code, | 1 | //! The Abstract Syntax Tree preserves most details of the source code, |
| 2 | //! as it is used for formatting. Before semantic analysis, this | 2 | //! as it is used for formatting. Before semantic analysis, this |
| 3 | //! structure is normalized into `Teg`, which removes constructs like | 3 | //! structure is normalized into `Teg`, which removes constructs like |
| 4 | //! grouping, unneded let bindings, and other transforms. | 4 | //! grouping, unneeded let bindings, and other transforms. |
| 5 | //! | 5 | //! |
| 6 | //! `ast.nodes` contains nodes stored as three parts: | 6 | //! `ast.nodes` contains nodes stored as three parts: |
| 7 | //! - tag: the type of the node | 7 | //! - tag: the type of the node |
| 8 | //! - main_token: index to it's primary token, depends on the tag | 8 | //! - main_token: index to its primary token, depends on the tag |
| 9 | //! - data: two u32 values, depends on the tag | 9 | //! - data: two u32 values, depends on the tag |
| 10 | //! | 10 | //! |
| 11 | //! Many nodes encode all their metadata with just `node.data`, using | 11 | //! Many nodes encode all their metadata with just `node.data`, using |
| ... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
| 20 | //! - If the keyword before `main_token` is `kw_pub` it is a public variable. | 20 | //! - If the keyword before `main_token` is `kw_pub` it is a public variable. |
| 21 | //! | 21 | //! |
| 22 | //! To make decoding these easier, many nodes contain a "full" variant, | 22 | //! To make decoding these easier, many nodes contain a "full" variant, |
| 23 | //! such as `full.VarDecl`, which can be aquired with `ast.fullVarDecl(id)`. | 23 | //! such as `full.VarDecl`, which can be acquired with `ast.fullVarDecl(id)`. |
| 24 | //! | 24 | //! |
| 25 | //! For nodes that must store more than 64 bits of payload data, an "extra" | 25 | //! For nodes that must store more than 64 bits of payload data, an "extra" |
| 26 | //! struct is stored out-of-line in the `extra` field. These can be read | 26 | //! struct is stored out-of-line in the `extra` field. These can be read |
| ... | @@ -56,7 +56,7 @@ pub const Node = struct { | ... | @@ -56,7 +56,7 @@ pub const Node = struct { |
| 56 | /// main_token is the { | 56 | /// main_token is the { |
| 57 | /// data is .list (containing stmt slice) | 57 | /// data is .list (containing stmt slice) |
| 58 | /// | 58 | /// |
| 59 | /// This guarantees that the block either empty, or the last statement | 59 | /// This guarantees that either the block is empty or the last statement |
| 60 | /// ends with a semicolon. | 60 | /// ends with a semicolon. |
| 61 | block_void, | 61 | block_void, |
| 62 | /// main_token is the { | 62 | /// main_token is the { |
| ... | @@ -332,7 +332,7 @@ pub const Node = struct { | ... | @@ -332,7 +332,7 @@ pub const Node = struct { |
| 332 | extra: ExtraIndex, | 332 | extra: ExtraIndex, |
| 333 | body: NodeIndex, | 333 | body: NodeIndex, |
| 334 | }, | 334 | }, |
| 335 | /// either is a node list or a token list, depending on the node's tag | 335 | /// is either a node list or a token list, depending on the node's tag |
| 336 | list: SubList, | 336 | list: SubList, |
| 337 | var_decl: struct { | 337 | var_decl: struct { |
| 338 | type: OptionalNodeIndex, | 338 | type: OptionalNodeIndex, |
| ... | @@ -398,7 +398,7 @@ pub const Span = struct { | ... | @@ -398,7 +398,7 @@ pub const Span = struct { |
| 398 | main: u32, | 398 | main: u32, |
| 399 | }; | 399 | }; |
| 400 | 400 | ||
| 401 | // This can be removed when the following issue is implemented: | 401 | // This can be removed when the following issues are implemented: |
| 402 | // See: https://github.com/ziglang/zig/issues/104 | 402 | // See: https://github.com/ziglang/zig/issues/104 |
| 403 | // See: https://github.com/ziglang/zig/issues/3806 | 403 | // See: https://github.com/ziglang/zig/issues/3806 |
| 404 | pub const OptionalNodeIndex = enum(u32) { | 404 | pub const OptionalNodeIndex = enum(u32) { |
src/core/Cache.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | /// This is 128 bits - Even with 2^54 cache entries, the probably of a collision would be under 10^-6 | 3 | /// This is 128 bits - Even with 2^54 cache entries, the probability of a collision would be under 10^-6 |
| 4 | pub const bin_digest_len = 16; | 4 | pub const bin_digest_len = 16; |
| 5 | pub const hex_digest_len = bin_digest_len * 2; | 5 | pub const hex_digest_len = bin_digest_len * 2; |
| 6 | pub const BinDigest = [bin_digest_len]u8; | 6 | pub const BinDigest = [bin_digest_len]u8; |
src/core/Comp.zig+6-6| ... | @@ -12,7 +12,7 @@ analyzed_instructions: usize = 0, | ... | @@ -12,7 +12,7 @@ analyzed_instructions: usize = 0, |
| 12 | 12 | ||
| 13 | options: Options = .{}, | 13 | options: Options = .{}, |
| 14 | 14 | ||
| 15 | // TODO: consider computing this dynamicly per-link | 15 | // TODO: consider computing this dynamically per-link |
| 16 | current_compile_decls: std.ArrayListUnmanaged(Decl.Index) = .{}, | 16 | current_compile_decls: std.ArrayListUnmanaged(Decl.Index) = .{}, |
| 17 | 17 | ||
| 18 | pub fn init(comp: *Comp) !void { | 18 | pub fn init(comp: *Comp) !void { |
| ... | @@ -60,7 +60,7 @@ pub const File = struct { | ... | @@ -60,7 +60,7 @@ pub const File = struct { |
| 60 | root_module: Decl.Index.Optional, | 60 | root_module: Decl.Index.Optional, |
| 61 | status: enum { | 61 | status: enum { |
| 62 | never_loader, | 62 | never_loader, |
| 63 | /// A failure occurred during loading the file. Retrying might succeed. | 63 | /// A failure occurred while loading the file. Retrying might succeed. |
| 64 | retryable_failure, | 64 | retryable_failure, |
| 65 | /// Errors during parse | 65 | /// Errors during parse |
| 66 | parse_failure, | 66 | parse_failure, |
| ... | @@ -232,7 +232,7 @@ pub const Decl = struct { | ... | @@ -232,7 +232,7 @@ pub const Decl = struct { |
| 232 | teg_decl_index: InternPool.TrackedInst.Index.Optional, | 232 | teg_decl_index: InternPool.TrackedInst.Index.Optional, |
| 233 | 233 | ||
| 234 | /// Represents the "shallow" analysis status. For example, for decls that are functions, | 234 | /// Represents the "shallow" analysis status. For example, for decls that are functions, |
| 235 | /// the function type is analyzed with this set to `in_progress`, however, the semantic | 235 | /// the function type is analyzed with this set to `in_progress`; however, the semantic |
| 236 | /// analysis of the function body is performed with this value set to `success`. Functions | 236 | /// analysis of the function body is performed with this value set to `success`. Functions |
| 237 | /// have their own analysis status field. | 237 | /// have their own analysis status field. |
| 238 | analysis: enum { | 238 | analysis: enum { |
| ... | @@ -256,10 +256,10 @@ pub const Decl = struct { | ... | @@ -256,10 +256,10 @@ pub const Decl = struct { |
| 256 | sema_failure, | 256 | sema_failure, |
| 257 | /// There will be a corresponding ErrorMsg in Zcu.failed_decls. | 257 | /// There will be a corresponding ErrorMsg in Zcu.failed_decls. |
| 258 | codegen_failure, | 258 | codegen_failure, |
| 259 | /// Sematic analysis and constant value codegen of this Decl has | 259 | /// Semantic analysis and constant value codegen of this Decl has |
| 260 | /// succeeded. However, the Decl may be outdated due to an in-progress | 260 | /// succeeded. However, the Decl may be outdated due to an in-progress |
| 261 | /// update. Note that for a function, this does not mean codegen of the | 261 | /// update. Note that for a function, this does not mean codegen of the |
| 262 | /// function body succeded: that state is indicated by the function's | 262 | /// function body succeeded: that state is indicated by the function's |
| 263 | /// `analysis` field. | 263 | /// `analysis` field. |
| 264 | complete, | 264 | complete, |
| 265 | }, | 265 | }, |
| ... | @@ -268,7 +268,7 @@ pub const Decl = struct { | ... | @@ -268,7 +268,7 @@ pub const Decl = struct { |
| 268 | 268 | ||
| 269 | is_pub: bool, | 269 | is_pub: bool, |
| 270 | 270 | ||
| 271 | /// What kind of a declaration is this. | 271 | /// What kind of a declaration this is. |
| 272 | kind: Kind, | 272 | kind: Kind, |
| 273 | 273 | ||
| 274 | pub fn deinit(decl: *Decl, gpa: Allocator) void { | 274 | pub fn deinit(decl: *Decl, gpa: Allocator) void { |
src/core/InternPool.zig+4-4| ... | @@ -8,7 +8,7 @@ items: std.MultiArrayList(Item) = .{}, | ... | @@ -8,7 +8,7 @@ items: std.MultiArrayList(Item) = .{}, |
| 8 | extra: ExtraStore = .{}, | 8 | extra: ExtraStore = .{}, |
| 9 | 9 | ||
| 10 | /// In order to store references to strings in fewer bytes, we copy all | 10 | /// In order to store references to strings in fewer bytes, we copy all |
| 11 | /// string bytes into here. String bytes can be null. It is up to whomever | 11 | /// string bytes into here. String bytes can be null. It is up to whoever |
| 12 | /// is referencing the data here whether they want to store both index and length, | 12 | /// is referencing the data here whether they want to store both index and length, |
| 13 | /// thus allowing null bytes, or store only index, and use null-termination. The | 13 | /// thus allowing null bytes, or store only index, and use null-termination. The |
| 14 | /// `string_bytes` array is agnostic to either usage. | 14 | /// `string_bytes` array is agnostic to either usage. |
| ... | @@ -69,7 +69,7 @@ pub const EncodedData = dod.EncodedData(Tag, u32); | ... | @@ -69,7 +69,7 @@ pub const EncodedData = dod.EncodedData(Tag, u32); |
| 69 | pub const ExtraIndex = ExtraStore.Index; | 69 | pub const ExtraIndex = ExtraStore.Index; |
| 70 | 70 | ||
| 71 | pub const Tag = enum(u8) { | 71 | pub const Tag = enum(u8) { |
| 72 | /// This special tag represents a value which was removed from this pool via | 72 | /// This special tag represents a value that was removed from this pool via |
| 73 | /// `InternPool.remove`. The item remains allocated to preserve indices, but | 73 | /// `InternPool.remove`. The item remains allocated to preserve indices, but |
| 74 | /// lookups will consider it not equal to any other item, and all queries | 74 | /// lookups will consider it not equal to any other item, and all queries |
| 75 | /// assert not this tag. `data` is unused. | 75 | /// assert not this tag. `data` is unused. |
| ... | @@ -581,7 +581,7 @@ pub const TrackedInst = extern struct { | ... | @@ -581,7 +581,7 @@ pub const TrackedInst = extern struct { |
| 581 | inst: Teg.Inst.Index, | 581 | inst: Teg.Inst.Index, |
| 582 | 582 | ||
| 583 | comptime { | 583 | comptime { |
| 584 | // The fields should be tightly packed. See also serialiation logic in `Compilation.saveState`. | 584 | // The fields should be tightly packed. See also serialization logic in `Compilation.saveState`. |
| 585 | assert(@sizeOf(@This()) == Cache.bin_digest_len + @sizeOf(Teg.Inst.Index)); | 585 | assert(@sizeOf(@This()) == Cache.bin_digest_len + @sizeOf(Teg.Inst.Index)); |
| 586 | } | 586 | } |
| 587 | 587 | ||
| ... | @@ -882,7 +882,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void { | ... | @@ -882,7 +882,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void { |
| 882 | try ip.map.ensureUnusedCapacity(gpa, static_keys.len); | 882 | try ip.map.ensureUnusedCapacity(gpa, static_keys.len); |
| 883 | try ip.extra.list.ensureUnusedCapacity(gpa, static_keys.len); | 883 | try ip.extra.list.ensureUnusedCapacity(gpa, static_keys.len); |
| 884 | 884 | ||
| 885 | // This inserts all the statically-known values into the intern pool in the | 885 | // This inserts all the statically known values into the intern pool in the |
| 886 | // order expected. | 886 | // order expected. |
| 887 | for (static_keys) |key| { | 887 | for (static_keys) |key| { |
| 888 | _ = ip.get(gpa, key) catch unreachable; | 888 | _ = ip.get(gpa, key) catch unreachable; |
src/core/JsLink.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | /// This is the JavaScript backend's linker. | 1 | /// This is the JavaScript backend's linker. |
| 2 | /// It takes in a compilation, a list of `JsTree`s and creates a JavaScript | 2 | /// It takes in a compilation and a list of `JsTree`s and creates a JavaScript |
| 3 | /// bundle out of them. | 3 | /// bundle out of them. |
| 4 | comp: *Comp, | 4 | comp: *Comp, |
| 5 | 5 | ||
| ... | @@ -453,7 +453,7 @@ pub fn indexOfNeedsEscape(slice: []const u8) ?usize { | ... | @@ -453,7 +453,7 @@ pub fn indexOfNeedsEscape(slice: []const u8) ?usize { |
| 453 | return null; | 453 | return null; |
| 454 | } | 454 | } |
| 455 | 455 | ||
| 456 | // This function is loosely based off of Bun's `writeJSONString`, which | 456 | // This function is loosely based on Bun's `writeJSONString`, which |
| 457 | // is a Zig port of esbuild's `printUnquotedUTF16` function. | 457 | // is a Zig port of esbuild's `printUnquotedUTF16` function. |
| 458 | // Both projects are licensed under MIT | 458 | // Both projects are licensed under MIT |
| 459 | fn writeString(decoded: []const u8, writer: anytype) !void { | 459 | fn writeString(decoded: []const u8, writer: anytype) !void { |
src/core/Parse.zig+5-5| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | //! Parser takes a Token list and creates a Node list. It does not own the source code or | 1 | //! Parser takes a Token list and creates a Node list. It does not own the source code or |
| 2 | //! token data, however transferring into an `Ast` does move token list ownership. | 2 | //! token data, but transferring into an `Ast` does move token list ownership. |
| 3 | gpa: Allocator, | 3 | gpa: Allocator, |
| 4 | source: [:0]const u8, | 4 | source: [:0]const u8, |
| 5 | token_tags: []const Token.Tag, | 5 | token_tags: []const Token.Tag, |
| ... | @@ -250,7 +250,7 @@ fn parseModuleMembers(p: *Parse) Error!SubList { | ... | @@ -250,7 +250,7 @@ fn parseModuleMembers(p: *Parse) Error!SubList { |
| 250 | try p.scratch.append(p.gpa, try p.parseExpression(true)); | 250 | try p.scratch.append(p.gpa, try p.parseExpression(true)); |
| 251 | 251 | ||
| 252 | switch (first_tag) { | 252 | switch (first_tag) { |
| 253 | // some control flow and blocks are allowed to not have a | 253 | // some control flow and blocks are allowed to not have |
| 254 | // trailing semicolons. this is a stylistic choice. | 254 | // trailing semicolons. this is a stylistic choice. |
| 255 | .kw_if, | 255 | .kw_if, |
| 256 | .start_brace, | 256 | .start_brace, |
| ... | @@ -425,7 +425,7 @@ fn parseBlockContents(p: *Parse) Error!struct { Node.Tag, SubList } { | ... | @@ -425,7 +425,7 @@ fn parseBlockContents(p: *Parse) Error!struct { Node.Tag, SubList } { |
| 425 | try p.scratch.append(p.gpa, try p.parseExpression(true)); | 425 | try p.scratch.append(p.gpa, try p.parseExpression(true)); |
| 426 | 426 | ||
| 427 | switch (first_tag) { | 427 | switch (first_tag) { |
| 428 | // some control flow and blocks are allowed to not have a | 428 | // some control flow and blocks are allowed to not have |
| 429 | // trailing semicolons. this is a stylistic choice. | 429 | // trailing semicolons. this is a stylistic choice. |
| 430 | .kw_if, | 430 | .kw_if, |
| 431 | .start_brace, | 431 | .start_brace, |
| ... | @@ -1027,13 +1027,13 @@ fn parseGroup(p: *Parse) Error!NodeIndex { | ... | @@ -1027,13 +1027,13 @@ fn parseGroup(p: *Parse) Error!NodeIndex { |
| 1027 | 1027 | ||
| 1028 | // helpers | 1028 | // helpers |
| 1029 | 1029 | ||
| 1030 | /// Append a node and return it's index. | 1030 | /// Append a node and return its index. |
| 1031 | fn addNode(p: *Parse, node: Node) !NodeIndex { | 1031 | fn addNode(p: *Parse, node: Node) !NodeIndex { |
| 1032 | const trace = t.trace(@src()); | 1032 | const trace = t.trace(@src()); |
| 1033 | defer trace.end(); | 1033 | defer trace.end(); |
| 1034 | 1034 | ||
| 1035 | try p.nodes.append(p.gpa, node); | 1035 | try p.nodes.append(p.gpa, node); |
| 1036 | // @intCast is always safe because 2^32 tokens alwayss produce less than | 1036 | // @intCast is always safe because 2^32 tokens always produce less than |
| 1037 | // 2^32 nodes, and there is a 2^32 limit on source file bytes. | 1037 | // 2^32 nodes, and there is a 2^32 limit on source file bytes. |
| 1038 | return @intCast(p.nodes.len - 1); | 1038 | return @intCast(p.nodes.len - 1); |
| 1039 | } | 1039 | } |
src/core/Report.zig+3-3| ... | @@ -358,7 +358,7 @@ pub const Warn = union(enum) { | ... | @@ -358,7 +358,7 @@ pub const Warn = union(enum) { |
| 358 | }, | 358 | }, |
| 359 | }; | 359 | }; |
| 360 | 360 | ||
| 361 | /// A variant of std.builtin.StackTrace that stores it's data within itself | 361 | /// A variant of std.builtin.StackTrace that stores its data within itself |
| 362 | /// instead of being a pointer. This allows capturing the stack trace and | 362 | /// instead of being a pointer. This allows capturing the stack trace and |
| 363 | /// saving it for later printing. | 363 | /// saving it for later printing. |
| 364 | pub const StoredTrace = struct { | 364 | pub const StoredTrace = struct { |
| ... | @@ -603,7 +603,7 @@ pub fn dumpToStdErr(report: Report, comp: *Comp) !void { | ... | @@ -603,7 +603,7 @@ pub fn dumpToStdErr(report: Report, comp: *Comp) !void { |
| 603 | const tty = std.io.tty.detectConfig(stderr); | 603 | const tty = std.io.tty.detectConfig(stderr); |
| 604 | 604 | ||
| 605 | if (false or | 605 | if (false or |
| 606 | // Windows API uses it's own API calls, so a buffered writer | 606 | // Windows API uses its own API calls, so a buffered writer |
| 607 | // cannot be used :/ | 607 | // cannot be used :/ |
| 608 | (builtin.os.tag == .windows and tty == .windows_api) or | 608 | (builtin.os.tag == .windows and tty == .windows_api) or |
| 609 | // Debug stack trace printer writes directly to standard err, | 609 | // Debug stack trace printer writes directly to standard err, |
| ... | @@ -776,7 +776,7 @@ pub const MsgContext = struct { | ... | @@ -776,7 +776,7 @@ pub const MsgContext = struct { |
| 776 | report: *const Report, | 776 | report: *const Report, |
| 777 | utf8_source: [:0]const u8, | 777 | utf8_source: [:0]const u8, |
| 778 | 778 | ||
| 779 | /// This arena is is a stack fallback with 16kb, then | 779 | /// This arena is a stack fallback with 16kb, then |
| 780 | /// falling back to an arena allocator. This should | 780 | /// falling back to an arena allocator. This should |
| 781 | /// make the cost of arbitrarily creating `Component` | 781 | /// make the cost of arbitrarily creating `Component` |
| 782 | /// nodes extremely lightweight. | 782 | /// nodes extremely lightweight. |
src/core/Sema.zig+1-1| ... | @@ -42,7 +42,7 @@ pub const Error = error{ | ... | @@ -42,7 +42,7 @@ pub const Error = error{ |
| 42 | } || Comp.File.GetTegError; | 42 | } || Comp.File.GetTegError; |
| 43 | 43 | ||
| 44 | /// Instead of using a hash map for this, just pre-allocate a list long enough to hold everything. | 44 | /// Instead of using a hash map for this, just pre-allocate a list long enough to hold everything. |
| 45 | /// This is fine because all instructions are going to be adacent in a single declaration. | 45 | /// This is fine because all instructions are going to be adjacent in a single declaration. |
| 46 | const InstMap = struct { | 46 | const InstMap = struct { |
| 47 | items: []Air.Inst.Ref.Optional, | 47 | items: []Air.Inst.Ref.Optional, |
| 48 | start: Teg.Inst.Index, | 48 | start: Teg.Inst.Index, |
src/core/Teg.zig+2-2| ... | @@ -207,7 +207,7 @@ pub const Inst = struct { | ... | @@ -207,7 +207,7 @@ pub const Inst = struct { |
| 207 | } | 207 | } |
| 208 | }; | 208 | }; |
| 209 | 209 | ||
| 210 | /// A reference to instruction, or to an InternPool index, or neither. | 210 | /// A reference to an instruction, or to an InternPool index, or to neither. |
| 211 | /// | 211 | /// |
| 212 | /// If the integer tag value is < InternPool.static_len, then it | 212 | /// If the integer tag value is < InternPool.static_len, then it |
| 213 | /// corresponds to an InternPool index. Otherwise, this refers to a ZIR | 213 | /// corresponds to an InternPool index. Otherwise, this refers to a ZIR |
| ... | @@ -328,7 +328,7 @@ pub const Inst = struct { | ... | @@ -328,7 +328,7 @@ pub const Inst = struct { |
| 328 | }; | 328 | }; |
| 329 | }; | 329 | }; |
| 330 | 330 | ||
| 331 | /// Trailng data for function declarations | 331 | /// Trailing data for function declarations |
| 332 | pub const DeclFn = struct { | 332 | pub const DeclFn = struct { |
| 333 | params: RefList, | 333 | params: RefList, |
| 334 | return_type: Ref, | 334 | return_type: Ref, |
src/core/Tokenizer.zig+10-10| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | //! The tokenizer is extremely simple structure that, given a view of source | 1 | //! The tokenizer is an extremely simple structure that, given a view of source |
| 2 | //! code, can stream tokens one at a time. A token is an 8-bit tag and a 32-bit | 2 | //! code, can stream tokens one at a time. A token is an 8-bit tag and a 32-bit |
| 3 | //! offset to where that token is located. | 3 | //! offset to where that token is located. |
| 4 | //! | 4 | //! |
| 5 | //! Retriving payloads like string/numeric values, identifier names, etc is | 5 | //! Retrieving payloads like string/numeric values, identifier names, etc is |
| 6 | //! done separately, either in Parse or Transform, when the respective data | 6 | //! done separately, either in Parse or Transform, when the respective data |
| 7 | //! is actually needed. Tokenization does guarante that such data is valid. | 7 | //! is actually needed. Tokenization does guarantee that such data is valid. |
| 8 | code: [:0]const u8, | 8 | code: [:0]const u8, |
| 9 | pos: ByteOffset = 0, | 9 | pos: ByteOffset = 0, |
| 10 | 10 | ||
| ... | @@ -146,7 +146,7 @@ pub const Token = struct { | ... | @@ -146,7 +146,7 @@ pub const Token = struct { |
| 146 | /// Used so that parser does not need to do out of bounds checks | 146 | /// Used so that parser does not need to do out of bounds checks |
| 147 | eof, | 147 | eof, |
| 148 | 148 | ||
| 149 | /// Most tokens have statically known lexeme, such as "struct" or "+=" | 149 | /// Most tokens have statically known lexemes, such as "struct" or "+=" |
| 150 | pub fn lexeme(tag: Tag) ?[]const u8 { | 150 | pub fn lexeme(tag: Tag) ?[]const u8 { |
| 151 | return switch (tag) { | 151 | return switch (tag) { |
| 152 | .invalid => unreachable, | 152 | .invalid => unreachable, |
| ... | @@ -290,7 +290,7 @@ pub const Token = struct { | ... | @@ -290,7 +290,7 @@ pub const Token = struct { |
| 290 | }); | 290 | }); |
| 291 | }; | 291 | }; |
| 292 | 292 | ||
| 293 | /// When any of these error occurs, the tokenizer's position is set to | 293 | /// When any of these errors occurs, the tokenizer's position is set to |
| 294 | /// the start of the offending token. | 294 | /// the start of the offending token. |
| 295 | pub const NextTokenError = error{ | 295 | pub const NextTokenError = error{ |
| 296 | /// Generic token syntax error | 296 | /// Generic token syntax error |
| ... | @@ -525,7 +525,7 @@ fn nextByte(t: Tokenizer) u8 { | ... | @@ -525,7 +525,7 @@ fn nextByte(t: Tokenizer) u8 { |
| 525 | return t.code[t.pos + 1]; | 525 | return t.code[t.pos + 1]; |
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | /// Remember that using this only makes sense if you know for certain that all | 528 | /// Remember that using this makes sense only if you know for certain that all |
| 529 | /// previous bytes are ASCII, otherwise you may hit UB | 529 | /// previous bytes are ASCII, otherwise you may hit UB |
| 530 | fn byteAt(t: Tokenizer, comptime offset: u32) ?u8 { | 530 | fn byteAt(t: Tokenizer, comptime offset: u32) ?u8 { |
| 531 | if (offset == 1) @compileError("use nextByte()"); | 531 | if (offset == 1) @compileError("use nextByte()"); |
| ... | @@ -940,7 +940,7 @@ fn simpleToken(t: *Tokenizer, comptime tag: Token.Tag) Token { | ... | @@ -940,7 +940,7 @@ fn simpleToken(t: *Tokenizer, comptime tag: Token.Tag) Token { |
| 940 | 940 | ||
| 941 | /// We are about to return an error, such as error.TrailingNumericSeparator. | 941 | /// We are about to return an error, such as error.TrailingNumericSeparator. |
| 942 | /// However, the character we ran into might actually be invalid UTF-8. | 942 | /// However, the character we ran into might actually be invalid UTF-8. |
| 943 | /// This utility just checks for that to make sure we dont mask error.InvalidUtf8 | 943 | /// This utility just checks for that to make sure we don't mask error.InvalidUtf8 |
| 944 | fn maybeUTF8Error(t: *Tokenizer, comptime real_err: anytype) @Type(.{ | 944 | fn maybeUTF8Error(t: *Tokenizer, comptime real_err: anytype) @Type(.{ |
| 945 | .ErrorSet = &[_]std.builtin.Type.Error{ | 945 | .ErrorSet = &[_]std.builtin.Type.Error{ |
| 946 | .{ .name = "InvalidUtf8" }, | 946 | .{ .name = "InvalidUtf8" }, |
| ... | @@ -1003,7 +1003,7 @@ pub fn tokenLocation( | ... | @@ -1003,7 +1003,7 @@ pub fn tokenLocation( |
| 1003 | .line_end = @intCast(utf8_source.len), | 1003 | .line_end = @intCast(utf8_source.len), |
| 1004 | }; | 1004 | }; |
| 1005 | 1005 | ||
| 1006 | // Scan to by line until we go past the token start | 1006 | // Scan by line until we go past the token start |
| 1007 | while (std.mem.indexOfScalarPos(u8, utf8_source, loc.line_start, '\n')) |i| { | 1007 | while (std.mem.indexOfScalarPos(u8, utf8_source, loc.line_start, '\n')) |i| { |
| 1008 | if (i >= token_start) { | 1008 | if (i >= token_start) { |
| 1009 | break; // Went past | 1009 | break; // Went past |
| ... | @@ -1058,7 +1058,7 @@ pub fn decodeStringCount(esc: []const u8) usize { | ... | @@ -1058,7 +1058,7 @@ pub fn decodeStringCount(esc: []const u8) usize { |
| 1058 | // - 0x00 thru 0x7F -> one byte | 1058 | // - 0x00 thru 0x7F -> one byte |
| 1059 | // - 0x80 thru 0xFF -> two bytes | 1059 | // - 0x80 thru 0xFF -> two bytes |
| 1060 | // | 1060 | // |
| 1061 | // we check the second byte anyways to ensure safe modes | 1061 | // we check the second byte anyway to ensure safe modes |
| 1062 | // catch potential invalid string literals. | 1062 | // catch potential invalid string literals. |
| 1063 | 'x' => switch (esc[backslash + 3]) { | 1063 | 'x' => switch (esc[backslash + 3]) { |
| 1064 | '0'...'9', 'a'...'f', 'A'...'F' => { | 1064 | '0'...'9', 'a'...'f', 'A'...'F' => { |
| ... | @@ -1105,7 +1105,7 @@ pub fn decodeStringCount(esc: []const u8) usize { | ... | @@ -1105,7 +1105,7 @@ pub fn decodeStringCount(esc: []const u8) usize { |
| 1105 | } | 1105 | } |
| 1106 | 1106 | ||
| 1107 | /// Given a valid string literal contents (excluding the quotes), write | 1107 | /// Given a valid string literal contents (excluding the quotes), write |
| 1108 | /// it's decoded form (WTF-8) into the buf. | 1108 | /// its decoded form (WTF-8) into the buf. |
| 1109 | pub fn decodeStringBuf(esc: []const u8, buf: []u8) []u8 { | 1109 | pub fn decodeStringBuf(esc: []const u8, buf: []u8) []u8 { |
| 1110 | var result_i: usize = 0; | 1110 | var result_i: usize = 0; |
| 1111 | var i: usize = 0; | 1111 | var i: usize = 0; |
src/core/Transform.zig+3-3| ... | @@ -144,7 +144,7 @@ const BlockContext = struct { | ... | @@ -144,7 +144,7 @@ const BlockContext = struct { |
| 144 | /// mutable pointers to it. When `break :brk` is encountered | 144 | /// mutable pointers to it. When `break :brk` is encountered |
| 145 | const BreakTarget = struct { | 145 | const BreakTarget = struct { |
| 146 | label: ?[]const u8, | 146 | label: ?[]const u8, |
| 147 | /// This allows `continue` as well as implicit break targetting. | 147 | /// This allows `continue` as well as implicit break targeting. |
| 148 | is_loop: bool, | 148 | is_loop: bool, |
| 149 | /// If `null`, this label was unused. | 149 | /// If `null`, this label was unused. |
| 150 | block_index: ?Inst.Index = null, | 150 | block_index: ?Inst.Index = null, |
| ... | @@ -711,7 +711,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc | ... | @@ -711,7 +711,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc |
| 711 | }), | 711 | }), |
| 712 | .mutable => |idx| idx.toRef(), | 712 | .mutable => |idx| idx.toRef(), |
| 713 | .immutable => |ref| ref, | 713 | .immutable => |ref| ref, |
| 714 | .param => unreachable, //unresolved param | 714 | .param => unreachable, // unresolved param |
| 715 | }; | 715 | }; |
| 716 | }, | 716 | }, |
| 717 | 717 | ||
| ... | @@ -1038,7 +1038,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc | ... | @@ -1038,7 +1038,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc |
| 1038 | 1038 | ||
| 1039 | if (yes == .void and no == .void) { | 1039 | if (yes == .void and no == .void) { |
| 1040 | // when both branches do nothing, we can omit the branch, | 1040 | // when both branches do nothing, we can omit the branch, |
| 1041 | // however we still need to type-check the condition operand | 1041 | // but we still need to type-check the condition operand |
| 1042 | _ = try t.addInstRef(.{ | 1042 | _ = try t.addInstRef(.{ |
| 1043 | .tag = .ensure_bool, | 1043 | .tag = .ensure_bool, |
| 1044 | .data = EncodedData.encode(.ensure_bool, .{ | 1044 | .data = EncodedData.encode(.ensure_bool, .{ |