mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
Merge pull request #8109 from roc-lang/parse-module
Refactor parse into a Zig module
This commit is contained in:
commit
b9c76d33d7
37 changed files with 289 additions and 257 deletions
20
Glossary.md
20
Glossary.md
|
|
@ -80,8 +80,8 @@ That ID is used in [IRs](#ir) instead of the actual text to save memory.
|
|||
Identifier in the compiler:
|
||||
- new compiler:
|
||||
- [Ident](src/base/Ident.zig)
|
||||
- [Ident tokenization](src/check/parse/tokenize.zig): check the functions `chompIdentLower` and `chompIdentGeneral`, and their uses.
|
||||
- [Ident parsing](src/check/parse/Parser.zig): search `Ident`
|
||||
- [Ident tokenization](src/parse/tokenize.zig): check the functions `chompIdentLower` and `chompIdentGeneral`, and their uses.
|
||||
- [Ident parsing](src/parse/Parser.zig): search `Ident`
|
||||
- old compiler:
|
||||
- [IdentStr](crates/compiler/ident/src/lib.rs)
|
||||
- [module/ident.rs](crates/compiler/module/src/ident.rs)
|
||||
|
|
@ -94,7 +94,7 @@ Many keywords can not be used as a variable name.
|
|||
We have an [overview of all Roc keywords](https://www.roc-lang.org/tutorial#reserved-keywords).
|
||||
|
||||
Keywords in the compiler:
|
||||
- [new compiler](src/check/parse/tokenize.zig)
|
||||
- [new compiler](src/parse/tokenize.zig)
|
||||
- [old compiler](crates/compiler/parse/src/keyword.rs)
|
||||
|
||||
## Operator
|
||||
|
|
@ -104,7 +104,7 @@ Some examples: `+`, `=`, `==`, `>`. [A table of all operators in Roc](https://ww
|
|||
`+` is an example of binary operator because it works with two operands, e.g. `1 + 1`. Similarly `!` (e.g. `!Bool.false`) is a unary operator.
|
||||
|
||||
Operators in the compiler:
|
||||
- New compiler: search `Op` in [tokenize.zig](src/check/parse/tokenize.zig)
|
||||
- New compiler: search `Op` in [tokenize.zig](src/parse/tokenize.zig)
|
||||
- Old compiler: search `operator_help` in [expr.rs](crates/compiler/parse/src/expr.rs)
|
||||
|
||||
## Syntax
|
||||
|
|
@ -112,7 +112,7 @@ Operators in the compiler:
|
|||
The set of rules that define the correct structure and format of statements, expressions, and code blocks. It specifies how code should be written so that it can be interpreted and executed correctly. In other words, syntax determines how symbols, keywords, and punctuation must be arranged to form valid source code.
|
||||
|
||||
Syntax in the compiler:
|
||||
- New compiler: determined by the [tokenizer and parser](src/check/parse).
|
||||
- New compiler: determined by the [tokenizer and parser](src/parse).
|
||||
- Old compiler: determined by the [parser](crates/compiler/parse).
|
||||
|
||||
## Syntactic Sugar
|
||||
|
|
@ -142,7 +142,7 @@ In the compiler, the type signature specified in the source code has priority ov
|
|||
Type annotations are basically the same thing as type signatures and both terms are used interchangeably throughout the compiler.
|
||||
|
||||
Type signature in the code base:
|
||||
- New compiler: [Parser.zig](src/check/parse/Parser.zig) (search signature)
|
||||
- New compiler: [Parser.zig](src/parse/Parser.zig) (search signature)
|
||||
- Old compiler: [ast.rs](crates/compiler/parse/src/ast.rs) (search TypeAnnotation)
|
||||
|
||||
## Type Alias
|
||||
|
|
@ -176,7 +176,7 @@ Graph a := Dict a (List a) where a implements Eq
|
|||
Type variables don't have to be a single letter, they just have to start with a lowercase letter.
|
||||
|
||||
Parsing of type vars:
|
||||
- new compiler: search `ty_var` in [Parser.zig](src/check/parse/Parser.zig)
|
||||
- new compiler: search `ty_var` in [Parser.zig](src/parse/Parser.zig)
|
||||
- old compiler: search `parse_type_variable` in [type_annotation.rs](crates/compiler/parse/src/type_annotation.rs)
|
||||
|
||||
## Builtin
|
||||
|
|
@ -221,7 +221,7 @@ LowerIdent(3:1-3:4),OpColon(3:5-3:6),UpperIdent(3:7-3:10),Newline(1:1-1:1)
|
|||
```
|
||||
|
||||
New compiler:
|
||||
- [tokenize.zig](src/check/parse/tokenize.zig)
|
||||
- [tokenize.zig](src/parse/tokenize.zig)
|
||||
|
||||
Old compiler:
|
||||
- We did not do a separate tokenization step, everything happened in the [parser](crates/compiler/parse/src/parser.rs).
|
||||
|
|
@ -253,7 +253,7 @@ Compared to raw source code, this structured format is much easier to analyze an
|
|||
The AST is created by the [parser](#parsing).
|
||||
|
||||
New compiler:
|
||||
- See the `Node` struct in [this file](src/check/parse/AST.zig).
|
||||
- See the `Node` struct in [this file](src/parse/AST.zig).
|
||||
- You can see examples of ASTs in the .txt files in [this folder](src/snapshots).
|
||||
|
||||
Old compiler:
|
||||
|
|
@ -266,7 +266,7 @@ Old compiler:
|
|||
The step where the compiler checks if the source code follows the correct structure or “grammar” of the programming language. It takes the tokens produced by [tokenization](#tokenization) and organizes them to see if they make sense together, like checking the structure of sentences in a language. If the code is correct, the parser builds a tree-like structure ([AST](#ast)) that shows how the code is organized. If not, it reports errors.
|
||||
|
||||
Parser implementation:
|
||||
- new compiler: [src/check/parse](src/check/parse)
|
||||
- new compiler: [src/parse](src/parse)
|
||||
- old compiler: [crates/compiler/parse](crates/compiler/parse) (tokenization is not a separate step here)
|
||||
|
||||
## Symbol
|
||||
|
|
|
|||
142
build.zig
142
build.zig
|
|
@ -1,5 +1,6 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const modules = @import("build/modules.zig");
|
||||
const Dependency = std.Build.Dependency;
|
||||
const Import = std.Build.Module.Import;
|
||||
const InstallDir = std.Build.InstallDir;
|
||||
|
|
@ -42,81 +43,33 @@ pub fn build(b: *std.Build) void {
|
|||
}
|
||||
|
||||
// tracy profiler configuration
|
||||
const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
|
||||
const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
|
||||
const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (tracy != null);
|
||||
const tracy_callstack_depth: u32 = b.option(u32, "tracy-callstack-depth", "Declare callstack depth for Tracy data. Does nothing if -Dtracy_callstack is not provided") orelse 10;
|
||||
if (tracy_callstack) {
|
||||
const flag_enable_tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
|
||||
const flag_tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse (flag_enable_tracy != null);
|
||||
const flag_tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse (flag_enable_tracy != null);
|
||||
const flag_tracy_callstack_depth: u32 = b.option(u32, "tracy-callstack-depth", "Declare callstack depth for Tracy data. Does nothing if -Dtracy_callstack is not provided") orelse 10;
|
||||
if (flag_tracy_callstack) {
|
||||
std.log.warn("Tracy callstack is enable. This can significantly skew timings, but is important for understanding source location. Be cautious when generating timing and analyzing results.", .{});
|
||||
}
|
||||
|
||||
// Create compile time build options
|
||||
const build_options = b.addOptions();
|
||||
build_options.addOption(bool, "enable_tracy", tracy != null);
|
||||
build_options.addOption(bool, "enable_tracy", flag_enable_tracy != null);
|
||||
build_options.addOption(bool, "trace_eval", trace_eval);
|
||||
build_options.addOption([]const u8, "compiler_version", getCompilerVersion(b, optimize));
|
||||
if (target.result.os.tag == .macos and tracy_callstack) {
|
||||
if (target.result.os.tag == .macos and flag_tracy_callstack) {
|
||||
std.log.warn("Tracy callstack does not work on MacOS, disabling.", .{});
|
||||
build_options.addOption(bool, "enable_tracy_callstack", false);
|
||||
} else {
|
||||
build_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
|
||||
build_options.addOption(bool, "enable_tracy_callstack", flag_tracy_callstack);
|
||||
}
|
||||
build_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
|
||||
build_options.addOption(u32, "tracy_callstack_depth", tracy_callstack_depth);
|
||||
build_options.addOption(bool, "enable_tracy_allocation", flag_tracy_allocation);
|
||||
build_options.addOption(u32, "tracy_callstack_depth", flag_tracy_callstack_depth);
|
||||
|
||||
// Create common Modules
|
||||
const module_serialization = b.addModule("serialization", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/serialization/mod.zig"),
|
||||
});
|
||||
const module_collections = b.addModule("collections", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/collections/mod.zig"),
|
||||
});
|
||||
const module_base = b.addModule("base", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/base/mod.zig"),
|
||||
});
|
||||
const module_types = b.addModule("types", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/types/mod.zig"),
|
||||
});
|
||||
const module_builtins = b.addModule("builtins", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/builtins/mod.zig"),
|
||||
});
|
||||
const module_compile = b.addModule("compile", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/compile/mod.zig"),
|
||||
});
|
||||
const module_reporting = b.addModule("reporting", std.Build.Module.CreateOptions{
|
||||
.root_source_file = b.path("src/reporting/mod.zig"),
|
||||
});
|
||||
|
||||
// Configure module dependencies
|
||||
module_collections.addImport("serialization", module_serialization);
|
||||
|
||||
module_base.addImport("serialization", module_serialization);
|
||||
module_base.addImport("collections", module_collections);
|
||||
module_base.addImport("types", module_types);
|
||||
|
||||
module_types.addImport("serialization", module_serialization);
|
||||
module_types.addImport("base", module_base);
|
||||
module_types.addImport("collections", module_collections);
|
||||
module_types.addImport("compile", module_compile);
|
||||
|
||||
module_compile.addImport("base", module_base);
|
||||
module_compile.addImport("compile", module_compile);
|
||||
module_compile.addImport("collections", module_collections);
|
||||
module_compile.addImport("types", module_types);
|
||||
module_compile.addImport("builtins", module_builtins);
|
||||
module_compile.addImport("reporting", module_reporting);
|
||||
|
||||
module_reporting.addImport("reporting", module_reporting);
|
||||
module_reporting.addImport("base", module_base);
|
||||
const roc_modules = modules.RocModules.create(b, build_options);
|
||||
|
||||
// add main roc exe
|
||||
const roc_exe = addMainExe(b, build_options, target, optimize, strip, enable_llvm, use_system_llvm, user_llvm_path, tracy, module_builtins) orelse return;
|
||||
roc_exe.root_module.addImport("base", module_base);
|
||||
roc_exe.root_module.addImport("collections", module_collections);
|
||||
roc_exe.root_module.addImport("types", module_types);
|
||||
roc_exe.root_module.addImport("serialization", module_serialization);
|
||||
roc_exe.root_module.addImport("compile", module_compile);
|
||||
roc_exe.root_module.addImport("reporting", module_reporting);
|
||||
const roc_exe = addMainExe(b, roc_modules, target, optimize, strip, enable_llvm, use_system_llvm, user_llvm_path, flag_enable_tracy) orelse return;
|
||||
roc_modules.addAll(roc_exe);
|
||||
install_and_run(b, no_bin, roc_exe, roc_step, run_step);
|
||||
|
||||
// Add snapshot tool
|
||||
|
|
@ -127,13 +80,8 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
});
|
||||
snapshot_exe.root_module.addImport("base", module_base);
|
||||
snapshot_exe.root_module.addImport("builtins", module_builtins);
|
||||
snapshot_exe.root_module.addImport("types", module_types);
|
||||
snapshot_exe.root_module.addImport("collections", module_collections);
|
||||
snapshot_exe.root_module.addImport("compile", module_compile);
|
||||
snapshot_exe.root_module.addImport("reporting", module_reporting);
|
||||
add_tracy(b, build_options, snapshot_exe, target, false, tracy);
|
||||
roc_modules.addAll(snapshot_exe);
|
||||
add_tracy(b, roc_modules.build_options, snapshot_exe, target, false, flag_enable_tracy);
|
||||
install_and_run(b, no_bin, snapshot_exe, snapshot_step, snapshot_step);
|
||||
|
||||
// Add playground WASM executable
|
||||
|
|
@ -148,15 +96,9 @@ pub fn build(b: *std.Build) void {
|
|||
});
|
||||
playground_exe.entry = .disabled;
|
||||
playground_exe.rdynamic = true;
|
||||
playground_exe.root_module.addImport("base", module_base);
|
||||
playground_exe.root_module.addImport("builtins", module_builtins);
|
||||
playground_exe.root_module.addOptions("build_options", build_options);
|
||||
playground_exe.root_module.addImport("types", module_types);
|
||||
playground_exe.root_module.addImport("collections", module_collections);
|
||||
playground_exe.root_module.addImport("compile", module_compile);
|
||||
playground_exe.root_module.addImport("reporting", module_reporting);
|
||||
roc_modules.addAll(playground_exe);
|
||||
|
||||
add_tracy(b, build_options, playground_exe, b.resolveTargetQuery(.{
|
||||
add_tracy(b, roc_modules.build_options, playground_exe, b.resolveTargetQuery(.{
|
||||
.cpu_arch = .wasm32,
|
||||
.os_tag = .freestanding,
|
||||
}), false, null);
|
||||
|
|
@ -170,15 +112,8 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
});
|
||||
all_tests.root_module.addOptions("build_options", build_options);
|
||||
roc_modules.addAllToTest(all_tests);
|
||||
all_tests.root_module.addAnonymousImport("legal_details", .{ .root_source_file = b.path("legal_details") });
|
||||
all_tests.root_module.addImport("base", module_base);
|
||||
all_tests.root_module.addImport("builtins", module_builtins);
|
||||
all_tests.root_module.addImport("types", module_types);
|
||||
all_tests.root_module.addImport("collections", module_collections);
|
||||
all_tests.root_module.addImport("serialization", module_serialization);
|
||||
all_tests.root_module.addImport("compile", module_compile);
|
||||
all_tests.root_module.addImport("reporting", module_reporting);
|
||||
|
||||
const builtins_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/builtins/main.zig"),
|
||||
|
|
@ -187,7 +122,7 @@ pub fn build(b: *std.Build) void {
|
|||
.link_libc = true,
|
||||
});
|
||||
builtins_tests.root_module.stack_check = false;
|
||||
builtins_tests.root_module.addOptions("build_options", build_options);
|
||||
builtins_tests.root_module.addImport("build_options", roc_modules.build_options);
|
||||
|
||||
b.default_step.dependOn(&all_tests.step);
|
||||
b.default_step.dependOn(playground_step);
|
||||
|
|
@ -255,15 +190,9 @@ pub fn build(b: *std.Build) void {
|
|||
no_bin,
|
||||
target,
|
||||
optimize,
|
||||
build_options,
|
||||
tracy,
|
||||
roc_modules,
|
||||
flag_enable_tracy,
|
||||
name,
|
||||
module_builtins,
|
||||
module_base,
|
||||
module_types,
|
||||
module_collections,
|
||||
module_compile,
|
||||
module_reporting,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -276,15 +205,9 @@ fn add_fuzz_target(
|
|||
no_bin: bool,
|
||||
target: ResolvedTarget,
|
||||
optimize: OptimizeMode,
|
||||
build_options: *Step.Options,
|
||||
roc_modules: modules.RocModules,
|
||||
tracy: ?[]const u8,
|
||||
name: []const u8,
|
||||
builtins_module: *std.Build.Module,
|
||||
module_base: *std.Build.Module,
|
||||
module_types: *std.Build.Module,
|
||||
module_collections: *std.Build.Module,
|
||||
module_compile: *std.Build.Module,
|
||||
module_reporting: *std.Build.Module,
|
||||
) void {
|
||||
// We always include the repro scripts (no dependencies).
|
||||
// We only include the fuzzing scripts if `-Dfuzz` is set.
|
||||
|
|
@ -296,13 +219,8 @@ fn add_fuzz_target(
|
|||
// Work around instrumentation bugs on mac without giving up perf on linux.
|
||||
.optimize = if (target.result.os.tag == .macos) .Debug else .ReleaseSafe,
|
||||
});
|
||||
fuzz_obj.root_module.addImport("builtins", builtins_module);
|
||||
fuzz_obj.root_module.addImport("base", module_base);
|
||||
fuzz_obj.root_module.addImport("types", module_types);
|
||||
fuzz_obj.root_module.addImport("collections", module_collections);
|
||||
fuzz_obj.root_module.addImport("compile", module_compile);
|
||||
fuzz_obj.root_module.addImport("reporting", module_reporting);
|
||||
add_tracy(b, build_options, fuzz_obj, target, false, tracy);
|
||||
roc_modules.addAll(fuzz_obj);
|
||||
add_tracy(b, roc_modules.build_options, fuzz_obj, target, false, tracy);
|
||||
|
||||
const name_exe = b.fmt("fuzz-{s}", .{name});
|
||||
const name_repro = b.fmt("repro-{s}", .{name});
|
||||
|
|
@ -332,7 +250,7 @@ fn add_fuzz_target(
|
|||
|
||||
fn addMainExe(
|
||||
b: *std.Build,
|
||||
build_options: *Step.Options,
|
||||
roc_modules: modules.RocModules,
|
||||
target: ResolvedTarget,
|
||||
optimize: OptimizeMode,
|
||||
strip: ?bool,
|
||||
|
|
@ -340,7 +258,6 @@ fn addMainExe(
|
|||
use_system_llvm: bool,
|
||||
user_llvm_path: ?[]const u8,
|
||||
tracy: ?[]const u8,
|
||||
builtins_module: *std.Build.Module,
|
||||
) ?*Step.Compile {
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "roc",
|
||||
|
|
@ -388,7 +305,6 @@ fn addMainExe(
|
|||
config.addOption(bool, "llvm", enable_llvm);
|
||||
exe.root_module.addOptions("config", config);
|
||||
exe.root_module.addAnonymousImport("legal_details", .{ .root_source_file = b.path("legal_details") });
|
||||
exe.root_module.addImport("builtins", builtins_module);
|
||||
|
||||
if (enable_llvm) {
|
||||
const llvm_paths = llvmPaths(b, target, use_system_llvm, user_llvm_path) orelse return null;
|
||||
|
|
@ -398,7 +314,7 @@ fn addMainExe(
|
|||
try addStaticLlvmOptionsToModule(exe.root_module);
|
||||
}
|
||||
|
||||
add_tracy(b, build_options, exe, target, enable_llvm, tracy);
|
||||
add_tracy(b, roc_modules.build_options, exe, target, enable_llvm, tracy);
|
||||
return exe;
|
||||
}
|
||||
|
||||
|
|
@ -432,13 +348,13 @@ fn install_and_run(
|
|||
|
||||
fn add_tracy(
|
||||
b: *std.Build,
|
||||
build_options: *Step.Options,
|
||||
module_build_options: *std.Build.Module,
|
||||
base: *Step.Compile,
|
||||
target: ResolvedTarget,
|
||||
links_llvm: bool,
|
||||
tracy: ?[]const u8,
|
||||
) void {
|
||||
base.root_module.addOptions("build_options", build_options);
|
||||
base.root_module.addImport("build_options", module_build_options);
|
||||
if (tracy) |tracy_path| {
|
||||
const client_cpp = b.pathJoin(
|
||||
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
|
||||
|
|
|
|||
92
build/modules.zig
Normal file
92
build/modules.zig
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
const std = @import("std");
|
||||
const Build = std.Build;
|
||||
const Module = Build.Module;
|
||||
const Step = Build.Step;
|
||||
|
||||
pub const RocModules = struct {
|
||||
serialization: *Module,
|
||||
collections: *Module,
|
||||
base: *Module,
|
||||
types: *Module,
|
||||
builtins: *Module,
|
||||
compile: *Module,
|
||||
reporting: *Module,
|
||||
parse: *Module,
|
||||
tracy: *Module,
|
||||
build_options: *Module,
|
||||
|
||||
pub fn create(b: *Build, build_options_step: *Step.Options) RocModules {
|
||||
const self = RocModules{
|
||||
.serialization = b.addModule("serialization", .{ .root_source_file = b.path("src/serialization/mod.zig") }),
|
||||
.collections = b.addModule("collections", .{ .root_source_file = b.path("src/collections/mod.zig") }),
|
||||
.base = b.addModule("base", .{ .root_source_file = b.path("src/base/mod.zig") }),
|
||||
.types = b.addModule("types", .{ .root_source_file = b.path("src/types/mod.zig") }),
|
||||
.builtins = b.addModule("builtins", .{ .root_source_file = b.path("src/builtins/mod.zig") }),
|
||||
.compile = b.addModule("compile", .{ .root_source_file = b.path("src/compile/mod.zig") }),
|
||||
.reporting = b.addModule("reporting", .{ .root_source_file = b.path("src/reporting/mod.zig") }),
|
||||
.parse = b.addModule("parse", .{ .root_source_file = b.path("src/parse/mod.zig") }),
|
||||
.tracy = b.addModule("tracy", .{ .root_source_file = b.path("src/tracy.zig") }),
|
||||
.build_options = b.addModule("build_options", .{ .root_source_file = build_options_step.getOutput() }),
|
||||
};
|
||||
|
||||
self.tracy.addImport("build_options", self.build_options);
|
||||
|
||||
self.collections.addImport("serialization", self.serialization);
|
||||
|
||||
self.base.addImport("serialization", self.serialization);
|
||||
self.base.addImport("collections", self.collections);
|
||||
self.base.addImport("types", self.types);
|
||||
|
||||
self.types.addImport("serialization", self.serialization);
|
||||
self.types.addImport("base", self.base);
|
||||
self.types.addImport("collections", self.collections);
|
||||
self.types.addImport("compile", self.compile);
|
||||
|
||||
self.compile.addImport("base", self.base);
|
||||
self.compile.addImport("compile", self.compile);
|
||||
self.compile.addImport("collections", self.collections);
|
||||
self.compile.addImport("types", self.types);
|
||||
self.compile.addImport("builtins", self.builtins);
|
||||
self.compile.addImport("reporting", self.reporting);
|
||||
|
||||
self.reporting.addImport("reporting", self.reporting);
|
||||
self.reporting.addImport("base", self.base);
|
||||
|
||||
self.parse.addImport("parse", self.parse);
|
||||
self.parse.addImport("base", self.base);
|
||||
self.parse.addImport("compile", self.compile);
|
||||
self.parse.addImport("collections", self.collections);
|
||||
self.parse.addImport("tracy", self.tracy);
|
||||
self.parse.addImport("reporting", self.reporting);
|
||||
|
||||
self.tracy.addImport("builtins", self.builtins);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn addAll(self: RocModules, step: *Step.Compile) void {
|
||||
step.root_module.addImport("base", self.base);
|
||||
step.root_module.addImport("collections", self.collections);
|
||||
step.root_module.addImport("types", self.types);
|
||||
step.root_module.addImport("serialization", self.serialization);
|
||||
step.root_module.addImport("compile", self.compile);
|
||||
step.root_module.addImport("reporting", self.reporting);
|
||||
step.root_module.addImport("parse", self.parse);
|
||||
step.root_module.addImport("tracy", self.tracy);
|
||||
step.root_module.addImport("builtins", self.builtins);
|
||||
step.root_module.addImport("build_options", self.build_options);
|
||||
}
|
||||
|
||||
pub fn addAllToTest(self: RocModules, step: *Step.Compile) void {
|
||||
step.root_module.addImport("base", self.base);
|
||||
step.root_module.addImport("collections", self.collections);
|
||||
step.root_module.addImport("types", self.types);
|
||||
step.root_module.addImport("serialization", self.serialization);
|
||||
step.root_module.addImport("compile", self.compile);
|
||||
step.root_module.addImport("reporting", self.reporting);
|
||||
step.root_module.addImport("parse", self.parse);
|
||||
step.root_module.addImport("tracy", self.tracy);
|
||||
step.root_module.addImport("builtins", self.builtins);
|
||||
step.root_module.addImport("build_options", self.build_options);
|
||||
}
|
||||
};
|
||||
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const tracy = @import("tracy.zig");
|
||||
const fmt = @import("fmt.zig");
|
||||
const collections = @import("collections");
|
||||
const parse = @import("parse");
|
||||
const compile = @import("compile");
|
||||
|
||||
const tokenize = @import("check/parse/tokenize.zig");
|
||||
const parse = @import("check/parse.zig");
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const tracy = @import("tracy");
|
||||
const fmt = @import("fmt.zig");
|
||||
|
||||
const tokenize = parse.tokenize;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
|
|
|
|||
4
src/cache/CacheModule.zig
vendored
4
src/cache/CacheModule.zig
vendored
|
|
@ -8,7 +8,7 @@ const base = @import("base");
|
|||
const canonicalize = @import("../check/canonicalize.zig");
|
||||
const collections = @import("collections");
|
||||
const types = @import("types");
|
||||
const parse = @import("../check/parse.zig").parse;
|
||||
const parse = @import("parse");
|
||||
const compile = @import("compile");
|
||||
const SExprTree = base.SExprTree;
|
||||
const Filesystem = @import("../fs/Filesystem.zig");
|
||||
|
|
@ -697,7 +697,7 @@ test "cache filesystem roundtrip with in-memory storage" {
|
|||
const cir = &module_env;
|
||||
|
||||
// Parse and canonicalize
|
||||
var ast = try parse(&module_env);
|
||||
var ast = try parse.parse(&module_env);
|
||||
defer ast.deinit(gpa);
|
||||
|
||||
var canonicalizer = try canonicalize.init(cir, &ast, null);
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
# Check
|
||||
|
||||
Transforms Roc source code through parsing, canonicalization, and type checking.
|
||||
|
||||
- [src/check/parse.zig](./parse.zig) and [src/check/parse/](./parse/): Converts source text into an Abstract Syntax Tree (AST) through tokenization and parsing.
|
||||
- [src/check/canonicalize.zig](./canonicalize.zig) and [src/check/canonicalize/](./canonicalize/): Transforms AST into Canonical Intermediate Representation (CIR) with desugaring and scope resolution.
|
||||
- [src/check/check_types.zig](./check_types.zig) and [src/check/check_types/](./check_types/): Performs Hindley-Milner type inference with constraint solving and unification.
|
||||
|
|
@ -6,25 +6,23 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const parse = @import("parse.zig");
|
||||
const parse = @import("parse");
|
||||
const collections = @import("collections");
|
||||
const compile = @import("compile");
|
||||
const types = @import("types");
|
||||
const types_mod = types;
|
||||
const RocDec = @import("builtins").RocDec;
|
||||
const builtins = @import("builtins");
|
||||
const tracy = @import("tracy");
|
||||
|
||||
const tracy = @import("../tracy.zig");
|
||||
const tokenize = @import("parse/tokenize.zig");
|
||||
const Scope = @import("./canonicalize/Scope.zig");
|
||||
|
||||
// Import from compile module files directly
|
||||
const Node = ModuleEnv.Node;
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const tokenize = parse.tokenize;
|
||||
const RocDec = builtins.RocDec;
|
||||
const CompileNodeStore = compile.NodeStore;
|
||||
const AST = parse.AST;
|
||||
const Token = tokenize.Token;
|
||||
const DataSpan = base.DataSpan;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const Node = compile.ModuleEnv.Node;
|
||||
|
||||
/// Both the canonicalized expression and any free variables
|
||||
///
|
||||
|
|
@ -382,7 +380,7 @@ fn addBuiltinTypeBool(self: *Self, ir: *ModuleEnv) std.mem.Allocator.Error!void
|
|||
const Self = @This();
|
||||
|
||||
/// The intermediate representation of a canonicalized Roc program.
|
||||
/// After parsing a Roc program, the [ParseIR](src/check/parse/AST.zig) is transformed into a [canonical
|
||||
/// After parsing a Roc program, the [ParseIR](src/parse/AST.zig) is transformed into a [canonical
|
||||
/// form](src/check/canonicalize/ir.zig) called CanIR.
|
||||
///
|
||||
/// Canonicalization performs analysis to catch user errors, and sets up the state necessary to solve the types in a
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
const std = @import("std");
|
||||
const compile = @import("compile");
|
||||
const parse = @import("parse");
|
||||
|
||||
const AST = @import("../../parse/AST.zig");
|
||||
const canonicalize = @import("../../canonicalize.zig");
|
||||
const parse = @import("../../parse.zig");
|
||||
const tokenize = @import("../../parse/tokenize.zig");
|
||||
|
||||
const testing = std.testing;
|
||||
const AST = parse.AST;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const tokenize = parse.tokenize;
|
||||
const testing = std.testing;
|
||||
|
||||
test "exposed but not implemented - values" {
|
||||
const allocator = testing.allocator;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const parse = @import("../../parse.zig");
|
||||
const parse = @import("parse");
|
||||
|
||||
const canonicalize = @import("../../canonicalize.zig");
|
||||
const compile = @import("compile");
|
||||
const types = @import("types");
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const parse = @import("../../parse.zig");
|
||||
const parse = @import("parse");
|
||||
const compile = @import("compile");
|
||||
|
||||
const canonicalize = @import("../../canonicalize.zig");
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const expectEqual = testing.expectEqual;
|
||||
const collections = @import("collections");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ const testing = std.testing;
|
|||
const base = @import("base");
|
||||
const types = @import("types");
|
||||
const compile = @import("compile");
|
||||
const parse = @import("parse");
|
||||
|
||||
const parse = @import("../../parse.zig");
|
||||
const canonicalize = @import("../../canonicalize.zig");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ const testing = std.testing;
|
|||
const base = @import("base");
|
||||
const types = @import("types");
|
||||
const compile = @import("compile");
|
||||
|
||||
const parse = @import("./parse.zig");
|
||||
const parse = @import("parse");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const canonicalize = @import("./canonicalize.zig");
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const tracy = @import("../tracy.zig");
|
||||
const tracy = @import("tracy");
|
||||
const collections = @import("collections");
|
||||
const types_mod = @import("types");
|
||||
const can = @import("canonicalize.zig");
|
||||
|
|
|
|||
|
|
@ -3,18 +3,19 @@
|
|||
//! with different type instantiations.
|
||||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const types = @import("types");
|
||||
const parse = @import("parse");
|
||||
const compile = @import("compile");
|
||||
|
||||
const check_types = @import("../check_types.zig");
|
||||
const instantiate = @import("instantiate.zig");
|
||||
const parse = @import("../parse.zig");
|
||||
const canonicalize = @import("../canonicalize.zig");
|
||||
|
||||
const TypesStore = types.Store;
|
||||
const CIR = canonicalize.CIR;
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const testing = std.testing;
|
||||
const test_allocator = testing.allocator;
|
||||
|
||||
const TestEnv = struct {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const tracy = @import("../../tracy.zig");
|
||||
const tracy = @import("tracy");
|
||||
const collections = @import("collections");
|
||||
|
||||
const can = @import("../canonicalize.zig");
|
||||
const types_mod = @import("types");
|
||||
const snapshot = @import("./snapshot.zig");
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
//! Tests for static dispatch on nominal types with method-style syntax
|
||||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const parse = @import("../../parse.zig");
|
||||
const parse = @import("parse");
|
||||
|
||||
const canonicalize = @import("../../canonicalize.zig");
|
||||
const check_types = @import("../../check_types.zig");
|
||||
const types_mod = @import("../types");
|
||||
const CIR = canonicalize.CIR;
|
||||
|
||||
const CIR = canonicalize.CIR;
|
||||
const testing = std.testing;
|
||||
const test_allocator = testing.allocator;
|
||||
|
||||
// NOTE: These tests are currently commented out because they depend on nominal type
|
||||
|
|
|
|||
|
|
@ -42,14 +42,15 @@
|
|||
const std = @import("std");
|
||||
|
||||
const base = @import("base");
|
||||
const can = @import("../canonicalize.zig");
|
||||
const tracy = @import("../../tracy.zig");
|
||||
const tracy = @import("tracy");
|
||||
const collections = @import("collections");
|
||||
const types_mod = @import("types");
|
||||
const compile = @import("compile");
|
||||
|
||||
const can = @import("../canonicalize.zig");
|
||||
const problem_mod = @import("./problem.zig");
|
||||
const occurs = @import("./occurs.zig");
|
||||
const snapshot_mod = @import("./snapshot.zig");
|
||||
const compile = @import("compile");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
//! actual Roc code to ensure polymorphic values work correctly in practice.
|
||||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const parse = @import("parse.zig");
|
||||
const parse = @import("parse");
|
||||
const canonicalize = @import("canonicalize.zig");
|
||||
const check_types = @import("check_types.zig");
|
||||
const compile = @import("compile");
|
||||
|
||||
const testing = std.testing;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const CanonicalizedExpr = canonicalize.CanonicalizedExpr;
|
||||
const test_allocator = testing.allocator;
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
# Parse
|
||||
|
||||
Converts Roc source code into an Abstract Syntax Tree (AST) through tokenization and parsing.
|
||||
|
||||
- [src/check/parse/tokenize.zig](./tokenize.zig): Lexical analysis that breaks source text into tokens while preserving position information for diagnostics.
|
||||
- [src/check/parse/Parser.zig](./Parser.zig): Recursive descent parser that builds an AST from the token stream with error recovery.
|
||||
- [src/check/parse/AST.zig](./AST.zig): Abstract Syntax Tree representation with comprehensive node types for all Roc language constructs.
|
||||
- [src/check/parse/Node.zig](./Node.zig): Individual AST node definitions for expressions, patterns, statements, and type annotations.
|
||||
- [src/check/parse/NodeStore.zig](./NodeStore.zig): Efficient storage and indexing system for AST nodes with memory-optimized layouts.
|
||||
|
|
@ -2,20 +2,21 @@
|
|||
//! compile a Roc program.
|
||||
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const cache = @import("../cache/mod.zig");
|
||||
const parse = @import("parse");
|
||||
const collections = @import("collections");
|
||||
const types = @import("types");
|
||||
|
||||
const cache = @import("../cache/mod.zig");
|
||||
const Can = @import("../check/canonicalize.zig");
|
||||
const Scope = @import("../check/canonicalize/Scope.zig");
|
||||
const parse = @import("../check/parse.zig");
|
||||
const Filesystem = @import("../fs/Filesystem.zig");
|
||||
const types = @import("types");
|
||||
|
||||
const Package = base.Package;
|
||||
const ModuleImport = base.ModuleImport;
|
||||
const ModuleWork = base.ModuleWork;
|
||||
const ModuleWorkIdx = base.ModuleWorkIdx;
|
||||
const testing = std.testing;
|
||||
|
||||
const Self = @This();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,20 +4,21 @@ const std = @import("std");
|
|||
const builtin = @import("builtin");
|
||||
const build_options = @import("build_options");
|
||||
const base = @import("base");
|
||||
const tracy = @import("tracy.zig");
|
||||
const parse = @import("check/parse.zig");
|
||||
const parse = @import("parse");
|
||||
const reporting = @import("reporting");
|
||||
const compile = @import("compile");
|
||||
|
||||
const tracy = @import("tracy");
|
||||
const canonicalize = @import("check/canonicalize.zig");
|
||||
const Solver = @import("check/check_types.zig");
|
||||
const types_problem_mod = @import("check/check_types/problem.zig");
|
||||
const reporting = @import("reporting");
|
||||
const Filesystem = @import("fs/Filesystem.zig");
|
||||
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const AST = parse.AST;
|
||||
const cache_mod = @import("cache/mod.zig");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const AST = parse.AST;
|
||||
const CacheManager = cache_mod.CacheManager;
|
||||
const CacheConfig = cache_mod.CacheConfig;
|
||||
|
||||
const CacheResult = cache_mod.CacheResult;
|
||||
const CacheHit = cache_mod.CacheHit;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
//! Tests for the expression evaluator
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const eval = @import("../interpreter.zig");
|
||||
const parse = @import("parse");
|
||||
const types = @import("types");
|
||||
const base = @import("base");
|
||||
const parse = @import("../../check/parse.zig");
|
||||
const compile = @import("compile");
|
||||
|
||||
const eval = @import("../interpreter.zig");
|
||||
const canonicalize = @import("../../check/canonicalize.zig");
|
||||
const check_types = @import("../../check/check_types.zig");
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const types = @import("types");
|
||||
const stack = @import("../stack.zig");
|
||||
const layout_store = @import("../../layout/store.zig");
|
||||
const layout = @import("../../layout/layout.zig");
|
||||
|
||||
const test_allocator = testing.allocator;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const Layout = layout.Layout;
|
||||
const Closure = eval.Closure;
|
||||
const testing = std.testing;
|
||||
const test_allocator = testing.allocator;
|
||||
|
||||
/// Helper function to run an expression and expect a specific error.
|
||||
pub fn runExpectError(src: []const u8, expected_error: eval.EvalError, should_trace: enum { trace, no_trace }) !void {
|
||||
|
|
|
|||
11
src/fmt.zig
11
src/fmt.zig
|
|
@ -2,23 +2,22 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const parse = @import("check/parse.zig");
|
||||
const parse = @import("parse");
|
||||
const collections = @import("collections");
|
||||
const compile = @import("compile");
|
||||
|
||||
const Filesystem = @import("fs/Filesystem.zig");
|
||||
|
||||
const tracy = @import("tracy.zig");
|
||||
const tokenize = @import("check/parse/tokenize.zig");
|
||||
|
||||
const Parser = @import("check/parse/Parser.zig").Parser;
|
||||
const tracy = @import("tracy");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const Token = tokenize.Token;
|
||||
const Parser = parse.Parser;
|
||||
const AST = parse.AST;
|
||||
const Node = parse.Node;
|
||||
const NodeStore = parse.NodeStore;
|
||||
const SafeList = collections.SafeList;
|
||||
|
||||
const tokenize = parse.tokenize;
|
||||
const fatal = collections.utils.fatal;
|
||||
|
||||
const FormatFlags = enum {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@
|
|||
//! Other afl commands also available in `./zig-out/AFLplusplus/bin`
|
||||
|
||||
const std = @import("std");
|
||||
const fmt = @import("fmt.zig");
|
||||
const parse = @import("check/parse.zig");
|
||||
const parse = @import("parse");
|
||||
const base = @import("base");
|
||||
|
||||
const fmt = @import("fmt.zig");
|
||||
|
||||
/// Hook for AFL++ to initialize the fuzz test environment.
|
||||
pub export fn zig_fuzz_init() void {}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const tokenize = @import("check/parse/tokenize.zig");
|
||||
const collections = @import("collections");
|
||||
const parse = @import("parse");
|
||||
|
||||
/// Hook for AFL++ to initialize the fuzz test environment.
|
||||
pub export fn zig_fuzz_init() void {}
|
||||
|
|
@ -32,7 +32,7 @@ pub fn zig_fuzz_test_inner(buf: [*]u8, len: isize, debug: bool) void {
|
|||
|
||||
const buf_slice = buf[0..@intCast(len)];
|
||||
|
||||
tokenize.checkTokenizerInvariants(gpa, buf_slice, debug) catch {
|
||||
parse.tokenize.checkTokenizerInvariants(gpa, buf_slice, debug) catch {
|
||||
@panic("Out of memory");
|
||||
};
|
||||
}
|
||||
|
|
|
|||
17
src/main.zig
17
src/main.zig
|
|
@ -3,25 +3,26 @@
|
|||
//! Result is at `./zig-out/bin/roc`
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const build_options = @import("build_options");
|
||||
const fmt = @import("fmt.zig");
|
||||
const builtin = @import("builtin");
|
||||
const base = @import("base");
|
||||
const collections = @import("collections");
|
||||
const reporting = @import("reporting");
|
||||
const coordinate_simple = @import("coordinate_simple.zig");
|
||||
const tracy = @import("tracy.zig");
|
||||
const parse = @import("parse");
|
||||
const tracy = @import("tracy");
|
||||
|
||||
const fmt = @import("fmt.zig");
|
||||
const coordinate_simple = @import("coordinate_simple.zig");
|
||||
const Filesystem = @import("fs/Filesystem.zig");
|
||||
const cli_args = @import("cli_args.zig");
|
||||
const cache_mod = @import("cache/mod.zig");
|
||||
const CacheManager = cache_mod.CacheManager;
|
||||
const CacheConfig = cache_mod.CacheConfig;
|
||||
const tokenize = @import("check/parse/tokenize.zig");
|
||||
const parse = @import("check/parse.zig");
|
||||
const bench = @import("bench.zig");
|
||||
const linker = @import("linker.zig");
|
||||
|
||||
const CacheManager = cache_mod.CacheManager;
|
||||
const CacheConfig = cache_mod.CacheConfig;
|
||||
const tokenize = parse.tokenize;
|
||||
|
||||
const read_roc_file_path_shim_lib = if (builtin.is_test) &[_]u8{} else @embedFile("libread_roc_file_path_shim.a");
|
||||
const c = std.c;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,20 +13,22 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const base = @import("base");
|
||||
const tokenize = @import("tokenize.zig");
|
||||
const parse = @import("parse");
|
||||
const collections = @import("collections");
|
||||
const reporting = @import("reporting");
|
||||
const compile = @import("compile");
|
||||
|
||||
const Node = @import("Node.zig");
|
||||
const NodeStore = @import("NodeStore.zig");
|
||||
const Node = parse.Node;
|
||||
const NodeStore = parse.NodeStore;
|
||||
pub const Token = tokenize.Token;
|
||||
const TokenizedBuffer = tokenize.TokenizedBuffer;
|
||||
|
||||
const SExpr = base.SExpr;
|
||||
const SExprTree = base.SExprTree;
|
||||
const Ident = base.Ident;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const tokenize = parse.tokenize;
|
||||
|
||||
const AST = @This();
|
||||
|
||||
env: *ModuleEnv,
|
||||
|
|
@ -6,8 +6,10 @@
|
|||
//! be interpreted.
|
||||
|
||||
const collections = @import("collections");
|
||||
const AST = @import("AST.zig");
|
||||
const TokenIdx = @import("tokenize.zig").Token.Idx;
|
||||
const parse = @import("parse");
|
||||
|
||||
const AST = parse.AST;
|
||||
const TokenIdx = parse.tokenize.Token.Idx;
|
||||
|
||||
const Node = @This();
|
||||
|
||||
|
|
@ -6,10 +6,11 @@
|
|||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const collections = @import("collections");
|
||||
const parse = @import("parse");
|
||||
|
||||
const AST = @import("AST.zig");
|
||||
const Node = @import("Node.zig");
|
||||
const Token = @import("tokenize.zig").Token;
|
||||
const AST = parse.AST;
|
||||
const Node = parse.Node;
|
||||
const Token = parse.tokenize.Token;
|
||||
const Region = AST.TokenizedRegion;
|
||||
const Diagnostic = AST.Diagnostic;
|
||||
|
||||
|
|
@ -7,17 +7,18 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const tracy = @import("../../tracy.zig");
|
||||
const tokenize = @import("tokenize.zig");
|
||||
const tracy = @import("tracy");
|
||||
const collections = @import("collections");
|
||||
const parse = @import("parse");
|
||||
|
||||
const AST = @import("AST.zig");
|
||||
const Node = @import("Node.zig");
|
||||
const NodeStore = @import("NodeStore.zig");
|
||||
const AST = parse.AST;
|
||||
const Node = parse.Node;
|
||||
const NodeStore = parse.NodeStore;
|
||||
const NodeList = AST.NodeList;
|
||||
const TokenizedBuffer = tokenize.TokenizedBuffer;
|
||||
const Token = tokenize.Token;
|
||||
const TokenIdx = Token.Idx;
|
||||
const tokenize = parse.tokenize;
|
||||
|
||||
const MAX_PARSE_DIAGNOSTICS: usize = 1_000;
|
||||
|
||||
9
src/parse/README.md
Normal file
9
src/parse/README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Parse
|
||||
|
||||
Converts Roc source code into an Abstract Syntax Tree (AST) through tokenization and parsing.
|
||||
|
||||
- [src/parse/tokenize.zig](./tokenize.zig): Lexical analysis that breaks source text into tokens while preserving position information for diagnostics.
|
||||
- [src/parse/Parser.zig](./Parser.zig): Recursive descent parser that builds an AST from the token stream with error recovery.
|
||||
- [src/parse/AST.zig](./AST.zig): Abstract Syntax Tree representation with comprehensive node types for all Roc language constructs.
|
||||
- [src/parse/Node.zig](./Node.zig): Individual AST node definitions for expressions, patterns, statements, and type annotations.
|
||||
- [src/parse/NodeStore.zig](./NodeStore.zig): Efficient storage and indexing system for AST nodes with memory-optimized layouts.
|
||||
|
|
@ -5,23 +5,31 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const tracy = @import("../tracy.zig");
|
||||
const tokenize = @import("parse/tokenize.zig");
|
||||
const compile = @import("compile");
|
||||
const tracy = @import("tracy");
|
||||
|
||||
pub const tokenize = @import("tokenize.zig");
|
||||
|
||||
const TokenIndex = tokenize.TokenIndex;
|
||||
const TokenizedBuffer = tokenize.TokenizedBuffer;
|
||||
const NodeList = AST.NodeList;
|
||||
const Diagnostic = AST.Diagnostic;
|
||||
const Parser = @import("parse/Parser.zig");
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
|
||||
pub const Node = @import("parse/Node.zig");
|
||||
pub const NodeStore = @import("parse/NodeStore.zig");
|
||||
/// **AST.Parser**
|
||||
pub const Parser = @import("Parser.zig");
|
||||
|
||||
/// **AST.Node**
|
||||
pub const Node = @import("Node.zig");
|
||||
|
||||
/// **AST.NodeStore**
|
||||
pub const NodeStore = @import("NodeStore.zig");
|
||||
|
||||
/// Represents the intermediate representation or Abstract Syntax Tree (AST) of a parsed Roc file.
|
||||
pub const AST = @import("parse/AST.zig");
|
||||
pub const AST = @import("AST.zig");
|
||||
|
||||
test {
|
||||
_ = @import("parse/test/ast_node_store_test.zig");
|
||||
_ = @import("test/ast_node_store_test.zig");
|
||||
}
|
||||
|
||||
fn runParse(env: *ModuleEnv, parserCall: *const fn (*Parser) std.mem.Allocator.Error!u32) std.mem.Allocator.Error!AST {
|
||||
|
|
@ -8,8 +8,10 @@
|
|||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const collections = @import("collections");
|
||||
const tracy = @import("../../tracy.zig");
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const tracy = @import("tracy");
|
||||
const compile = @import("compile");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
|
||||
/// representation of a token in the source code, like '+', 'foo', '=', '{'
|
||||
/// these are represented by an offset into the bytes of the source code
|
||||
|
|
@ -14,18 +14,20 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const parse = @import("check/parse.zig");
|
||||
const build_options = @import("build_options");
|
||||
const parse = @import("parse");
|
||||
const reporting = @import("reporting");
|
||||
const types = @import("types");
|
||||
const compile = @import("compile");
|
||||
|
||||
const can = @import("check/canonicalize.zig");
|
||||
const check_types = @import("check/check_types.zig");
|
||||
const WasmFilesystem = @import("playground/WasmFilesystem.zig");
|
||||
const reporting = @import("reporting");
|
||||
const snapshot = @import("snapshot.zig");
|
||||
const types = @import("types");
|
||||
const problem = @import("check/check_types/problem.zig");
|
||||
|
||||
const SExprTree = base.SExprTree;
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const allocator: Allocator = .{
|
||||
|
|
|
|||
|
|
@ -3,21 +3,22 @@
|
|||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const compile = @import("compile");
|
||||
const parse = @import("../check/parse.zig");
|
||||
const parse = @import("parse");
|
||||
const types = @import("types");
|
||||
|
||||
const canonicalize = @import("../check/canonicalize.zig");
|
||||
const check_types = @import("../check/check_types.zig");
|
||||
const types = @import("types");
|
||||
const types_store = types.store;
|
||||
const layout_store = @import("../layout/store.zig");
|
||||
const layout = @import("../layout/layout.zig");
|
||||
const eval = @import("../eval/interpreter.zig");
|
||||
const stack = @import("../eval/stack.zig");
|
||||
|
||||
const writers = types.writers;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const target = base.target;
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const AST = parse.AST;
|
||||
const target = base.target;
|
||||
const writers = types.writers;
|
||||
const types_store = types.store;
|
||||
|
||||
/// Type of definition stored in the REPL history
|
||||
const DefKind = union(enum) {
|
||||
|
|
|
|||
|
|
@ -8,24 +8,25 @@
|
|||
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const parse = @import("parse");
|
||||
const compile = @import("compile");
|
||||
const types = @import("types");
|
||||
const reporting = @import("reporting");
|
||||
|
||||
const Solver = @import("check/check_types.zig");
|
||||
const canonicalize = @import("check/canonicalize.zig");
|
||||
const types_problem_mod = @import("check/check_types/problem.zig");
|
||||
const cache = @import("cache/mod.zig");
|
||||
const ModuleEnv = @import("compile").ModuleEnv;
|
||||
|
||||
const Solver = @import("check/check_types.zig");
|
||||
const parse = @import("check/parse.zig");
|
||||
const fmt = @import("fmt.zig");
|
||||
const types = @import("types");
|
||||
const reporting = @import("reporting");
|
||||
const tokenize = @import("check/parse/tokenize.zig");
|
||||
const repl = @import("repl/eval.zig");
|
||||
|
||||
const ModuleEnv = compile.ModuleEnv;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const SExprTree = base.SExprTree;
|
||||
const parallel = base.parallel;
|
||||
const AST = parse.AST;
|
||||
const Report = reporting.Report;
|
||||
const tokenize = parse.tokenize;
|
||||
const parallel = base.parallel;
|
||||
|
||||
var verbose_log: bool = false;
|
||||
var prng = std.Random.DefaultPrng.init(1234567890);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue