diff --git a/doc/language-manual.md b/doc/language-manual.md index 3194dda9d0a3482e8a479808be7cfc9d488e50cc..380e9e3ebbd04ec66124c94b6022bf63d607491c 100644 --- a/doc/language-manual.md +++ b/doc/language-manual.md @@ -11,8 +11,8 @@ Key goals of this project are: It primarily focuses on merging some great points of Rust, Zig, and JavaScript's language designs: - **Rust** - Expressive control flow that is easy to write. -- **Zig** - Execute any code at compile time, everything is an expression. -- **JavaScript** - Garbage collected values with a versitile type system. +- **Zig** - Execute any code at compile time; everything is an expression. +- **JavaScript** - Garbage collected values with a versatile type system. ## Standard Library @@ -25,9 +25,9 @@ let print = @js("console").log; print("Hello, world!"); ``` -The `print` function is implemented by getting an external reference to the `console` JavaScript global, and then retriving the `log` property from it. +The `print` function is implemented by getting an external reference to the `console` JavaScript global and then retrieving the `log` property from it. -## Primative Data Types +## Primitive Data Types | name | ts equivilent | description | | ---------- | --------------------- | ---------------------------------------------- | @@ -36,7 +36,7 @@ The `print` function is implemented by getting an external reference to the `con | `bool` | `boolean` | either `true` or `false` | | `string` | `string` | a sequence of text characters | | `void` | `undefined` or `null` | detectable lack of a value | -| `opaque` | `unknown` or `any` | could be any value | +| `opaque` | `unknown` or `any` | could be any value | | `noreturn` | `never` | control flow prevents this value from existing | > **note**: `bigint` is planned but not added @@ -61,7 +61,7 @@ let true = 1 == 0; There are two types of variables, `let` and `var`. -`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. +`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. ```lang:run let hello: int = 1; diff --git a/src/core/Ast.zig b/src/core/Ast.zig index 01f6404f4a441ef307fea2911bc9230550b94560..730ba554c5c6e3355e3a83353b9511b9bf77adf8 100644 --- a/src/core/Ast.zig +++ b/src/core/Ast.zig @@ -1,11 +1,11 @@ //! The Abstract Syntax Tree preserves most details of the source code, //! as it is used for formatting. Before semantic analysis, this //! structure is normalized into `Teg`, which removes constructs like -//! grouping, unneded let bindings, and other transforms. +//! grouping, unneeded let bindings, and other transforms. //! //! `ast.nodes` contains nodes stored as three parts: //! - tag: the type of the node -//! - main_token: index to it's primary token, depends on the tag +//! - main_token: index to its primary token, depends on the tag //! - data: two u32 values, depends on the tag //! //! Many nodes encode all their metadata with just `node.data`, using @@ -20,7 +20,7 @@ //! - If the keyword before `main_token` is `kw_pub` it is a public variable. //! //! To make decoding these easier, many nodes contain a "full" variant, -//! such as `full.VarDecl`, which can be aquired with `ast.fullVarDecl(id)`. +//! such as `full.VarDecl`, which can be acquired with `ast.fullVarDecl(id)`. //! //! For nodes that must store more than 64 bits of payload data, an "extra" //! struct is stored out-of-line in the `extra` field. These can be read @@ -56,7 +56,7 @@ pub const Node = struct { /// main_token is the { /// data is .list (containing stmt slice) /// - /// This guarantees that the block either empty, or the last statement + /// This guarantees that either the block is empty or the last statement /// ends with a semicolon. block_void, /// main_token is the { @@ -332,7 +332,7 @@ pub const Node = struct { extra: ExtraIndex, body: NodeIndex, }, - /// either is a node list or a token list, depending on the node's tag + /// is either a node list or a token list, depending on the node's tag list: SubList, var_decl: struct { type: OptionalNodeIndex, @@ -398,7 +398,7 @@ pub const Span = struct { main: u32, }; -// This can be removed when the following issue is implemented: +// This can be removed when the following issues are implemented: // See: https://github.com/ziglang/zig/issues/104 // See: https://github.com/ziglang/zig/issues/3806 pub const OptionalNodeIndex = enum(u32) { diff --git a/src/core/Cache.zig b/src/core/Cache.zig index 49a4a49d428577d564b2d7495a65c21c68539943..8734e501f18f48b5941dd64d414932dc15d8e2c0 100644 --- a/src/core/Cache.zig +++ b/src/core/Cache.zig @@ -1,6 +1,6 @@ const std = @import("std"); -/// This is 128 bits - Even with 2^54 cache entries, the probably of a collision would be under 10^-6 +/// This is 128 bits - Even with 2^54 cache entries, the probability of a collision would be under 10^-6 pub const bin_digest_len = 16; pub const hex_digest_len = bin_digest_len * 2; pub const BinDigest = [bin_digest_len]u8; diff --git a/src/core/Comp.zig b/src/core/Comp.zig index 7a5a6be493cacaeb571011bdf35ccaa30c888e89..4091fa32abe46a9fa7a7db8b91f7d3859d33ab33 100644 --- a/src/core/Comp.zig +++ b/src/core/Comp.zig @@ -12,7 +12,7 @@ analyzed_instructions: usize = 0, options: Options = .{}, -// TODO: consider computing this dynamicly per-link +// TODO: consider computing this dynamically per-link current_compile_decls: std.ArrayListUnmanaged(Decl.Index) = .{}, pub fn init(comp: *Comp) !void { @@ -60,7 +60,7 @@ pub const File = struct { root_module: Decl.Index.Optional, status: enum { never_loader, - /// A failure occurred during loading the file. Retrying might succeed. + /// A failure occurred while loading the file. Retrying might succeed. retryable_failure, /// Errors during parse parse_failure, @@ -232,7 +232,7 @@ pub const Decl = struct { teg_decl_index: InternPool.TrackedInst.Index.Optional, /// Represents the "shallow" analysis status. For example, for decls that are functions, - /// the function type is analyzed with this set to `in_progress`, however, the semantic + /// the function type is analyzed with this set to `in_progress`; however, the semantic /// analysis of the function body is performed with this value set to `success`. Functions /// have their own analysis status field. analysis: enum { @@ -256,10 +256,10 @@ pub const Decl = struct { sema_failure, /// There will be a corresponding ErrorMsg in Zcu.failed_decls. codegen_failure, - /// Sematic analysis and constant value codegen of this Decl has + /// Semantic analysis and constant value codegen of this Decl has /// succeeded. However, the Decl may be outdated due to an in-progress /// update. Note that for a function, this does not mean codegen of the - /// function body succeded: that state is indicated by the function's + /// function body succeeded: that state is indicated by the function's /// `analysis` field. complete, }, @@ -268,7 +268,7 @@ pub const Decl = struct { is_pub: bool, - /// What kind of a declaration is this. + /// What kind of a declaration this is. kind: Kind, pub fn deinit(decl: *Decl, gpa: Allocator) void { diff --git a/src/core/InternPool.zig b/src/core/InternPool.zig index 92bac50ea2f5b886022525f8ee2c963ecae801c5..ed4fa838cf0bfb8c37952c0db0f26f1eb95b9fe3 100644 --- a/src/core/InternPool.zig +++ b/src/core/InternPool.zig @@ -8,7 +8,7 @@ items: std.MultiArrayList(Item) = .{}, extra: ExtraStore = .{}, /// In order to store references to strings in fewer bytes, we copy all -/// string bytes into here. String bytes can be null. It is up to whomever +/// string bytes into here. String bytes can be null. It is up to whoever /// is referencing the data here whether they want to store both index and length, /// thus allowing null bytes, or store only index, and use null-termination. The /// `string_bytes` array is agnostic to either usage. @@ -69,7 +69,7 @@ pub const EncodedData = dod.EncodedData(Tag, u32); pub const ExtraIndex = ExtraStore.Index; pub const Tag = enum(u8) { - /// This special tag represents a value which was removed from this pool via + /// This special tag represents a value that was removed from this pool via /// `InternPool.remove`. The item remains allocated to preserve indices, but /// lookups will consider it not equal to any other item, and all queries /// assert not this tag. `data` is unused. @@ -581,7 +581,7 @@ pub const TrackedInst = extern struct { inst: Teg.Inst.Index, comptime { - // The fields should be tightly packed. See also serialiation logic in `Compilation.saveState`. + // The fields should be tightly packed. See also serialization logic in `Compilation.saveState`. assert(@sizeOf(@This()) == Cache.bin_digest_len + @sizeOf(Teg.Inst.Index)); } @@ -882,7 +882,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void { try ip.map.ensureUnusedCapacity(gpa, static_keys.len); try ip.extra.list.ensureUnusedCapacity(gpa, static_keys.len); - // This inserts all the statically-known values into the intern pool in the + // This inserts all the statically known values into the intern pool in the // order expected. for (static_keys) |key| { _ = ip.get(gpa, key) catch unreachable; diff --git a/src/core/JsLink.zig b/src/core/JsLink.zig index 8b046e5624dec2fce61a50ce5b71b6282c46ee20..d60ac068a4b5996e19cb559f8099569716e90446 100644 --- a/src/core/JsLink.zig +++ b/src/core/JsLink.zig @@ -1,5 +1,5 @@ /// This is the JavaScript backend's linker. -/// It takes in a compilation, a list of `JsTree`s and creates a JavaScript +/// It takes in a compilation and a list of `JsTree`s and creates a JavaScript /// bundle out of them. comp: *Comp, @@ -453,7 +453,7 @@ pub fn indexOfNeedsEscape(slice: []const u8) ?usize { return null; } -// This function is loosely based off of Bun's `writeJSONString`, which +// This function is loosely based on Bun's `writeJSONString`, which // is a Zig port of esbuild's `printUnquotedUTF16` function. // Both projects are licensed under MIT fn writeString(decoded: []const u8, writer: anytype) !void { diff --git a/src/core/Parse.zig b/src/core/Parse.zig index b374d560d6570551f13126969a85e38916915e93..b51bd54db921125f098edd8e7f27b78f9f95ce5b 100644 --- a/src/core/Parse.zig +++ b/src/core/Parse.zig @@ -1,5 +1,5 @@ //! Parser takes a Token list and creates a Node list. It does not own the source code or -//! token data, however transferring into an `Ast` does move token list ownership. +//! token data, but transferring into an `Ast` does move token list ownership. gpa: Allocator, source: [:0]const u8, token_tags: []const Token.Tag, @@ -250,7 +250,7 @@ fn parseModuleMembers(p: *Parse) Error!SubList { try p.scratch.append(p.gpa, try p.parseExpression(true)); switch (first_tag) { - // some control flow and blocks are allowed to not have a + // some control flow and blocks are allowed to not have // trailing semicolons. this is a stylistic choice. .kw_if, .start_brace, @@ -425,7 +425,7 @@ fn parseBlockContents(p: *Parse) Error!struct { Node.Tag, SubList } { try p.scratch.append(p.gpa, try p.parseExpression(true)); switch (first_tag) { - // some control flow and blocks are allowed to not have a + // some control flow and blocks are allowed to not have // trailing semicolons. this is a stylistic choice. .kw_if, .start_brace, @@ -1027,13 +1027,13 @@ fn parseGroup(p: *Parse) Error!NodeIndex { // helpers -/// Append a node and return it's index. +/// Append a node and return its index. fn addNode(p: *Parse, node: Node) !NodeIndex { const trace = t.trace(@src()); defer trace.end(); try p.nodes.append(p.gpa, node); - // @intCast is always safe because 2^32 tokens alwayss produce less than + // @intCast is always safe because 2^32 tokens always produce less than // 2^32 nodes, and there is a 2^32 limit on source file bytes. return @intCast(p.nodes.len - 1); } diff --git a/src/core/Report.zig b/src/core/Report.zig index 19f9e105bf58485f40406c4cd14314061a55f8d4..183fc091721b3584c916d3c12472d5cc3d5424a6 100644 --- a/src/core/Report.zig +++ b/src/core/Report.zig @@ -358,7 +358,7 @@ pub const Warn = union(enum) { }, }; -/// A variant of std.builtin.StackTrace that stores it's data within itself +/// A variant of std.builtin.StackTrace that stores its data within itself /// instead of being a pointer. This allows capturing the stack trace and /// saving it for later printing. pub const StoredTrace = struct { @@ -603,7 +603,7 @@ pub fn dumpToStdErr(report: Report, comp: *Comp) !void { const tty = std.io.tty.detectConfig(stderr); if (false or - // Windows API uses it's own API calls, so a buffered writer + // Windows API uses its own API calls, so a buffered writer // cannot be used :/ (builtin.os.tag == .windows and tty == .windows_api) or // Debug stack trace printer writes directly to standard err, @@ -776,7 +776,7 @@ pub const MsgContext = struct { report: *const Report, utf8_source: [:0]const u8, - /// This arena is is a stack fallback with 16kb, then + /// This arena is a stack fallback with 16kb, then /// falling back to an arena allocator. This should /// make the cost of arbitrarily creating `Component` /// nodes extremely lightweight. diff --git a/src/core/Sema.zig b/src/core/Sema.zig index 2a73d9f080a482ed10d4266479c88e97ef39cf3a..ab8102b819e9c5fb281849965719614a18810339 100644 --- a/src/core/Sema.zig +++ b/src/core/Sema.zig @@ -42,7 +42,7 @@ pub const Error = error{ } || Comp.File.GetTegError; /// Instead of using a hash map for this, just pre-allocate a list long enough to hold everything. -/// This is fine because all instructions are going to be adacent in a single declaration. +/// This is fine because all instructions are going to be adjacent in a single declaration. const InstMap = struct { items: []Air.Inst.Ref.Optional, start: Teg.Inst.Index, diff --git a/src/core/Teg.zig b/src/core/Teg.zig index 931a6c2c56844746b3010f60260e42fdc9449ec6..09518dbe73162df109a92476fa72be455d2798ac 100644 --- a/src/core/Teg.zig +++ b/src/core/Teg.zig @@ -207,7 +207,7 @@ pub const Inst = struct { } }; - /// A reference to instruction, or to an InternPool index, or neither. + /// A reference to an instruction, or to an InternPool index, or to neither. /// /// If the integer tag value is < InternPool.static_len, then it /// corresponds to an InternPool index. Otherwise, this refers to a ZIR @@ -328,7 +328,7 @@ pub const Inst = struct { }; }; - /// Trailng data for function declarations + /// Trailing data for function declarations pub const DeclFn = struct { params: RefList, return_type: Ref, diff --git a/src/core/Tokenizer.zig b/src/core/Tokenizer.zig index d0256f8552eefec40dbb6dd72f64ebeb727772a4..3f1810f35b97f4cd4f2b472082a475a7a1e26916 100644 --- a/src/core/Tokenizer.zig +++ b/src/core/Tokenizer.zig @@ -1,10 +1,10 @@ -//! The tokenizer is extremely simple structure that, given a view of source +//! The tokenizer is an extremely simple structure that, given a view of source //! code, can stream tokens one at a time. A token is an 8-bit tag and a 32-bit //! offset to where that token is located. //! -//! Retriving payloads like string/numeric values, identifier names, etc is +//! Retrieving payloads like string/numeric values, identifier names, etc is //! done separately, either in Parse or Transform, when the respective data -//! is actually needed. Tokenization does guarante that such data is valid. +//! is actually needed. Tokenization does guarantee that such data is valid. code: [:0]const u8, pos: ByteOffset = 0, @@ -146,7 +146,7 @@ pub const Token = struct { /// Used so that parser does not need to do out of bounds checks eof, - /// Most tokens have statically known lexeme, such as "struct" or "+=" + /// Most tokens have statically known lexemes, such as "struct" or "+=" pub fn lexeme(tag: Tag) ?[]const u8 { return switch (tag) { .invalid => unreachable, @@ -290,7 +290,7 @@ pub const Token = struct { }); }; -/// When any of these error occurs, the tokenizer's position is set to +/// When any of these errors occurs, the tokenizer's position is set to /// the start of the offending token. pub const NextTokenError = error{ /// Generic token syntax error @@ -525,7 +525,7 @@ fn nextByte(t: Tokenizer) u8 { return t.code[t.pos + 1]; } -/// Remember that using this only makes sense if you know for certain that all +/// Remember that using this makes sense only if you know for certain that all /// previous bytes are ASCII, otherwise you may hit UB fn byteAt(t: Tokenizer, comptime offset: u32) ?u8 { if (offset == 1) @compileError("use nextByte()"); @@ -940,7 +940,7 @@ fn simpleToken(t: *Tokenizer, comptime tag: Token.Tag) Token { /// We are about to return an error, such as error.TrailingNumericSeparator. /// However, the character we ran into might actually be invalid UTF-8. -/// This utility just checks for that to make sure we dont mask error.InvalidUtf8 +/// This utility just checks for that to make sure we don't mask error.InvalidUtf8 fn maybeUTF8Error(t: *Tokenizer, comptime real_err: anytype) @Type(.{ .ErrorSet = &[_]std.builtin.Type.Error{ .{ .name = "InvalidUtf8" }, @@ -1003,7 +1003,7 @@ pub fn tokenLocation( .line_end = @intCast(utf8_source.len), }; - // Scan to by line until we go past the token start + // Scan by line until we go past the token start while (std.mem.indexOfScalarPos(u8, utf8_source, loc.line_start, '\n')) |i| { if (i >= token_start) { break; // Went past @@ -1058,7 +1058,7 @@ pub fn decodeStringCount(esc: []const u8) usize { // - 0x00 thru 0x7F -> one byte // - 0x80 thru 0xFF -> two bytes // - // we check the second byte anyways to ensure safe modes + // we check the second byte anyway to ensure safe modes // catch potential invalid string literals. 'x' => switch (esc[backslash + 3]) { '0'...'9', 'a'...'f', 'A'...'F' => { @@ -1105,7 +1105,7 @@ pub fn decodeStringCount(esc: []const u8) usize { } /// Given a valid string literal contents (excluding the quotes), write -/// it's decoded form (WTF-8) into the buf. +/// its decoded form (WTF-8) into the buf. pub fn decodeStringBuf(esc: []const u8, buf: []u8) []u8 { var result_i: usize = 0; var i: usize = 0; diff --git a/src/core/Transform.zig b/src/core/Transform.zig index b13a0335440160b5631ef6dc881433fa05503538..1de0a1bd0930e4d353ccc8162062919eb06047be 100644 --- a/src/core/Transform.zig +++ b/src/core/Transform.zig @@ -144,7 +144,7 @@ const BlockContext = struct { /// mutable pointers to it. When `break :brk` is encountered const BreakTarget = struct { label: ?[]const u8, - /// This allows `continue` as well as implicit break targetting. + /// This allows `continue` as well as implicit break targeting. is_loop: bool, /// If `null`, this label was unused. block_index: ?Inst.Index = null, @@ -711,7 +711,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc }), .mutable => |idx| idx.toRef(), .immutable => |ref| ref, - .param => unreachable, //unresolved param + .param => unreachable, // unresolved param }; }, @@ -1038,7 +1038,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc if (yes == .void and no == .void) { // when both branches do nothing, we can omit the branch, - // however we still need to type-check the condition operand + // but we still need to type-check the condition operand _ = try t.addInstRef(.{ .tag = .ensure_bool, .data = EncodedData.encode(.ensure_bool, .{