authorgravatar for 13513421+heimskr@users.noreply.github.comKai Tamkun <13513421+heimskr@users.noreply.github.com> 2024-06-02 21:32:46-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-06-02 21:32:46-07:00
log227021403e3604e6fc049ad2fa7575b05548244b
tree06836771054a46299091cc2111735cc17a25728a
parentf499572ffea4cab93d28e2480bcc9a4234f59089

chore: fix codebase and manual typos (#35)


12 files changed, 49 insertions(+), 49 deletions(-)

doc/language-manual.md+6-6
......@@ -11,8 +11,8 @@ Key goals of this project are:
1111It primarily focuses on merging some great points of Rust, Zig, and JavaScript's language designs:
1212
1313- **Rust** - Expressive control flow that is easy to write.
14- **Zig** - Execute any code at compile time, everything is an expression.
15- **JavaScript** - Garbage collected values with a versitile type system.
14- **Zig** - Execute any code at compile time; everything is an expression.
15- **JavaScript** - Garbage collected values with a versatile type system.
1616
1717## Standard Library
1818
......@@ -25,9 +25,9 @@ let print = @js("console").log;
2525print("Hello, world!");
2626```
2727
28The `print` function is implemented by getting an external reference to the `console` JavaScript global, and then retriving the `log` property from it.
28The `print` function is implemented by getting an external reference to the `console` JavaScript global and then retrieving the `log` property from it.
2929
30## Primative Data Types
30## Primitive Data Types
3131
3232| name | ts equivilent | description |
3333| ---------- | --------------------- | ---------------------------------------------- |
......@@ -36,7 +36,7 @@ The `print` function is implemented by getting an external reference to the `con
3636| `bool` | `boolean` | either `true` or `false` |
3737| `string` | `string` | a sequence of text characters |
3838| `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 |
4040| `noreturn` | `never` | control flow prevents this value from existing |
4141
4242> **note**: `bigint` is planned but not added
......@@ -61,7 +61,7 @@ let true = 1 == 0;
6161
6262There are two types of variables, `let` and `var`.
6363
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.
6565
6666```lang:run
6767let hello: int = 1;
src/core/Ast.zig+6-6
......@@ -1,11 +1,11 @@
11//! The Abstract Syntax Tree preserves most details of the source code,
22//! as it is used for formatting. Before semantic analysis, this
33//! 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.
55//!
66//! `ast.nodes` contains nodes stored as three parts:
77//! - 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
99//! - data: two u32 values, depends on the tag
1010//!
1111//! Many nodes encode all their metadata with just `node.data`, using
......@@ -20,7 +20,7 @@
2020//! - If the keyword before `main_token` is `kw_pub` it is a public variable.
2121//!
2222//! 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)`.
2424//!
2525//! For nodes that must store more than 64 bits of payload data, an "extra"
2626//! struct is stored out-of-line in the `extra` field. These can be read
......@@ -56,7 +56,7 @@ pub const Node = struct {
5656 /// main_token is the {
5757 /// data is .list (containing stmt slice)
5858 ///
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
6060 /// ends with a semicolon.
6161 block_void,
6262 /// main_token is the {
......@@ -332,7 +332,7 @@ pub const Node = struct {
332332 extra: ExtraIndex,
333333 body: NodeIndex,
334334 },
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
336336 list: SubList,
337337 var_decl: struct {
338338 type: OptionalNodeIndex,
......@@ -398,7 +398,7 @@ pub const Span = struct {
398398 main: u32,
399399};
400400
401// This can be removed when the following issue is implemented:
401// This can be removed when the following issues are implemented:
402402// See: https://github.com/ziglang/zig/issues/104
403403// See: https://github.com/ziglang/zig/issues/3806
404404pub const OptionalNodeIndex = enum(u32) {
src/core/Cache.zig+1-1
......@@ -1,6 +1,6 @@
11const std = @import("std");
22
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
44pub const bin_digest_len = 16;
55pub const hex_digest_len = bin_digest_len * 2;
66pub const BinDigest = [bin_digest_len]u8;
src/core/Comp.zig+6-6
......@@ -12,7 +12,7 @@ analyzed_instructions: usize = 0,
1212
1313options: Options = .{},
1414
15// TODO: consider computing this dynamicly per-link
15// TODO: consider computing this dynamically per-link
1616current_compile_decls: std.ArrayListUnmanaged(Decl.Index) = .{},
1717
1818pub fn init(comp: *Comp) !void {
......@@ -60,7 +60,7 @@ pub const File = struct {
6060 root_module: Decl.Index.Optional,
6161 status: enum {
6262 never_loader,
63 /// A failure occurred during loading the file. Retrying might succeed.
63 /// A failure occurred while loading the file. Retrying might succeed.
6464 retryable_failure,
6565 /// Errors during parse
6666 parse_failure,
......@@ -232,7 +232,7 @@ pub const Decl = struct {
232232 teg_decl_index: InternPool.TrackedInst.Index.Optional,
233233
234234 /// 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
236236 /// analysis of the function body is performed with this value set to `success`. Functions
237237 /// have their own analysis status field.
238238 analysis: enum {
......@@ -256,10 +256,10 @@ pub const Decl = struct {
256256 sema_failure,
257257 /// There will be a corresponding ErrorMsg in Zcu.failed_decls.
258258 codegen_failure,
259 /// Sematic analysis and constant value codegen of this Decl has
259 /// Semantic analysis and constant value codegen of this Decl has
260260 /// succeeded. However, the Decl may be outdated due to an in-progress
261261 /// 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
263263 /// `analysis` field.
264264 complete,
265265 },
......@@ -268,7 +268,7 @@ pub const Decl = struct {
268268
269269 is_pub: bool,
270270
271 /// What kind of a declaration is this.
271 /// What kind of a declaration this is.
272272 kind: Kind,
273273
274274 pub fn deinit(decl: *Decl, gpa: Allocator) void {
src/core/InternPool.zig+4-4
......@@ -8,7 +8,7 @@ items: std.MultiArrayList(Item) = .{},
88extra: ExtraStore = .{},
99
1010/// 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
1212/// is referencing the data here whether they want to store both index and length,
1313/// thus allowing null bytes, or store only index, and use null-termination. The
1414/// `string_bytes` array is agnostic to either usage.
......@@ -69,7 +69,7 @@ pub const EncodedData = dod.EncodedData(Tag, u32);
6969pub const ExtraIndex = ExtraStore.Index;
7070
7171pub 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
7373 /// `InternPool.remove`. The item remains allocated to preserve indices, but
7474 /// lookups will consider it not equal to any other item, and all queries
7575 /// assert not this tag. `data` is unused.
......@@ -581,7 +581,7 @@ pub const TrackedInst = extern struct {
581581 inst: Teg.Inst.Index,
582582
583583 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`.
585585 assert(@sizeOf(@This()) == Cache.bin_digest_len + @sizeOf(Teg.Inst.Index));
586586 }
587587
......@@ -882,7 +882,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void {
882882 try ip.map.ensureUnusedCapacity(gpa, static_keys.len);
883883 try ip.extra.list.ensureUnusedCapacity(gpa, static_keys.len);
884884
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
886886 // order expected.
887887 for (static_keys) |key| {
888888 _ = ip.get(gpa, key) catch unreachable;
src/core/JsLink.zig+2-2
......@@ -1,5 +1,5 @@
11/// 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
33/// bundle out of them.
44comp: *Comp,
55
......@@ -453,7 +453,7 @@ pub fn indexOfNeedsEscape(slice: []const u8) ?usize {
453453 return null;
454454}
455455
456// This function is loosely based off of Bun's `writeJSONString`, which
456// This function is loosely based on Bun's `writeJSONString`, which
457457// is a Zig port of esbuild's `printUnquotedUTF16` function.
458458// Both projects are licensed under MIT
459459fn writeString(decoded: []const u8, writer: anytype) !void {
src/core/Parse.zig+5-5
......@@ -1,5 +1,5 @@
11//! 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.
33gpa: Allocator,
44source: [:0]const u8,
55token_tags: []const Token.Tag,
......@@ -250,7 +250,7 @@ fn parseModuleMembers(p: *Parse) Error!SubList {
250250 try p.scratch.append(p.gpa, try p.parseExpression(true));
251251
252252 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
254254 // trailing semicolons. this is a stylistic choice.
255255 .kw_if,
256256 .start_brace,
......@@ -425,7 +425,7 @@ fn parseBlockContents(p: *Parse) Error!struct { Node.Tag, SubList } {
425425 try p.scratch.append(p.gpa, try p.parseExpression(true));
426426
427427 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
429429 // trailing semicolons. this is a stylistic choice.
430430 .kw_if,
431431 .start_brace,
......@@ -1027,13 +1027,13 @@ fn parseGroup(p: *Parse) Error!NodeIndex {
10271027
10281028// helpers
10291029
1030/// Append a node and return it's index.
1030/// Append a node and return its index.
10311031fn addNode(p: *Parse, node: Node) !NodeIndex {
10321032 const trace = t.trace(@src());
10331033 defer trace.end();
10341034
10351035 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
10371037 // 2^32 nodes, and there is a 2^32 limit on source file bytes.
10381038 return @intCast(p.nodes.len - 1);
10391039}
src/core/Report.zig+3-3
......@@ -358,7 +358,7 @@ pub const Warn = union(enum) {
358358 },
359359};
360360
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
362362/// instead of being a pointer. This allows capturing the stack trace and
363363/// saving it for later printing.
364364pub const StoredTrace = struct {
......@@ -603,7 +603,7 @@ pub fn dumpToStdErr(report: Report, comp: *Comp) !void {
603603 const tty = std.io.tty.detectConfig(stderr);
604604
605605 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
607607 // cannot be used :/
608608 (builtin.os.tag == .windows and tty == .windows_api) or
609609 // Debug stack trace printer writes directly to standard err,
......@@ -776,7 +776,7 @@ pub const MsgContext = struct {
776776 report: *const Report,
777777 utf8_source: [:0]const u8,
778778
779 /// This arena is is a stack fallback with 16kb, then
779 /// This arena is a stack fallback with 16kb, then
780780 /// falling back to an arena allocator. This should
781781 /// make the cost of arbitrarily creating `Component`
782782 /// nodes extremely lightweight.
src/core/Sema.zig+1-1
......@@ -42,7 +42,7 @@ pub const Error = error{
4242} || Comp.File.GetTegError;
4343
4444/// 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.
4646const InstMap = struct {
4747 items: []Air.Inst.Ref.Optional,
4848 start: Teg.Inst.Index,
src/core/Teg.zig+2-2
......@@ -207,7 +207,7 @@ pub const Inst = struct {
207207 }
208208 };
209209
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.
211211 ///
212212 /// If the integer tag value is < InternPool.static_len, then it
213213 /// corresponds to an InternPool index. Otherwise, this refers to a ZIR
......@@ -328,7 +328,7 @@ pub const Inst = struct {
328328 };
329329 };
330330
331 /// Trailng data for function declarations
331 /// Trailing data for function declarations
332332 pub const DeclFn = struct {
333333 params: RefList,
334334 return_type: Ref,
src/core/Tokenizer.zig+10-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
22//! code, can stream tokens one at a time. A token is an 8-bit tag and a 32-bit
33//! offset to where that token is located.
44//!
5//! Retriving payloads like string/numeric values, identifier names, etc is
5//! Retrieving payloads like string/numeric values, identifier names, etc is
66//! 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.
88code: [:0]const u8,
99pos: ByteOffset = 0,
1010
......@@ -146,7 +146,7 @@ pub const Token = struct {
146146 /// Used so that parser does not need to do out of bounds checks
147147 eof,
148148
149 /// Most tokens have statically known lexeme, such as "struct" or "+="
149 /// Most tokens have statically known lexemes, such as "struct" or "+="
150150 pub fn lexeme(tag: Tag) ?[]const u8 {
151151 return switch (tag) {
152152 .invalid => unreachable,
......@@ -290,7 +290,7 @@ pub const Token = struct {
290290 });
291291};
292292
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
294294/// the start of the offending token.
295295pub const NextTokenError = error{
296296 /// Generic token syntax error
......@@ -525,7 +525,7 @@ fn nextByte(t: Tokenizer) u8 {
525525 return t.code[t.pos + 1];
526526}
527527
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
529529/// previous bytes are ASCII, otherwise you may hit UB
530530fn byteAt(t: Tokenizer, comptime offset: u32) ?u8 {
531531 if (offset == 1) @compileError("use nextByte()");
......@@ -940,7 +940,7 @@ fn simpleToken(t: *Tokenizer, comptime tag: Token.Tag) Token {
940940
941941/// We are about to return an error, such as error.TrailingNumericSeparator.
942942/// 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
944944fn maybeUTF8Error(t: *Tokenizer, comptime real_err: anytype) @Type(.{
945945 .ErrorSet = &[_]std.builtin.Type.Error{
946946 .{ .name = "InvalidUtf8" },
......@@ -1003,7 +1003,7 @@ pub fn tokenLocation(
10031003 .line_end = @intCast(utf8_source.len),
10041004 };
10051005
1006 // Scan to by line until we go past the token start
1006 // Scan by line until we go past the token start
10071007 while (std.mem.indexOfScalarPos(u8, utf8_source, loc.line_start, '\n')) |i| {
10081008 if (i >= token_start) {
10091009 break; // Went past
......@@ -1058,7 +1058,7 @@ pub fn decodeStringCount(esc: []const u8) usize {
10581058 // - 0x00 thru 0x7F -> one byte
10591059 // - 0x80 thru 0xFF -> two bytes
10601060 //
1061 // we check the second byte anyways to ensure safe modes
1061 // we check the second byte anyway to ensure safe modes
10621062 // catch potential invalid string literals.
10631063 'x' => switch (esc[backslash + 3]) {
10641064 '0'...'9', 'a'...'f', 'A'...'F' => {
......@@ -1105,7 +1105,7 @@ pub fn decodeStringCount(esc: []const u8) usize {
11051105}
11061106
11071107/// 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.
11091109pub fn decodeStringBuf(esc: []const u8, buf: []u8) []u8 {
11101110 var result_i: usize = 0;
11111111 var i: usize = 0;
src/core/Transform.zig+3-3
......@@ -144,7 +144,7 @@ const BlockContext = struct {
144144 /// mutable pointers to it. When `break :brk` is encountered
145145 const BreakTarget = struct {
146146 label: ?[]const u8,
147 /// This allows `continue` as well as implicit break targetting.
147 /// This allows `continue` as well as implicit break targeting.
148148 is_loop: bool,
149149 /// If `null`, this label was unused.
150150 block_index: ?Inst.Index = null,
......@@ -711,7 +711,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc
711711 }),
712712 .mutable => |idx| idx.toRef(),
713713 .immutable => |ref| ref,
714 .param => unreachable, //unresolved param
714 .param => unreachable, // unresolved param
715715 };
716716 },
717717
......@@ -1038,7 +1038,7 @@ fn transformExpression(t: *Transform, decl: BlockContext, node: NodeIndex) Alloc
10381038
10391039 if (yes == .void and no == .void) {
10401040 // 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
10421042 _ = try t.addInstRef(.{
10431043 .tag = .ensure_bool,
10441044 .data = EncodedData.encode(.ensure_bool, .{