Skip to content

Commit 857cc5a

Browse files
committed
feat: change ast.rs to match the functionality of the driver
1 parent fda737f commit 857cc5a

11 files changed

Lines changed: 561 additions & 103 deletions

File tree

doc/architecture.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# Architecture Note: Omitted Keywords
1+
# Architecture Notes
2+
3+
## Omitted Keywords
4+
25
The `crate` and `super` keywords were not added to the compiler because they
36
are unnecessary at this stage. Typically, they are used to resolve relative
47
paths during import parsing. However, in our architecture, the prefix before
58
the first `::` in a `use` statement is always an dependency root path. Since all
69
dependency root paths are unique and strictly bound to specific paths, the resolver
710
can always unambiguously resolve the path without needing relative pointers.
811

9-
# Architecture Note: Namespace Separation in SimplicityHL
12+
## Namespace Separation in SimplicityHL
1013

1114
SimplicityHL uses distinct namespaces for types and values. This allows the same identifier to refer to different things depending on where it appears in the code — the compiler determines the correct interpretation from syntactic context, with no risk of collision.
1215

@@ -19,3 +22,10 @@ fn main() {
1922
assert!(foo()); // value namespace - function
2023
}
2124
```
25+
26+
## The "main" identifier in aliases
27+
28+
In SimplicityHL, the string "main" is reserved exclusively for the program's entry point function.
29+
While a `TypeAlias` is technically allowed to use this name, we explicitly forbid aliasing imports
30+
to "main" using the `as` keyword. This avoids complicating the compiler's resolution logic and
31+
prevents accidental shadowing of the entry point.

fuzz/fuzz_targets/compile_parse_tree.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
#[cfg(any(fuzzing, test))]
44
fn do_test(data: &[u8]) {
55
use arbitrary::Arbitrary;
6+
use std::sync::Arc;
67

7-
use simplicityhl::error::WithContent;
8-
use simplicityhl::{ast, named, parse, ArbitraryOfType, Arguments};
8+
use simplicityhl::error::{ErrorCollector, WithContent};
9+
use simplicityhl::{ast, driver, named, parse, ArbitraryOfType, Arguments};
910

1011
let mut u = arbitrary::Unstructured::new(data);
1112
let parse_program = match parse::Program::arbitrary(&mut u) {
1213
Ok(x) => x,
1314
Err(_) => return,
1415
};
15-
let ast_program = match ast::Program::analyze(&parse_program) {
16+
17+
let mut error_handler = ErrorCollector::new();
18+
let driver_program = if let Some(program) =
19+
driver::Program::from_parse(&parse_program, Arc::from(""), &mut error_handler)
20+
{
21+
program
22+
} else {
23+
return;
24+
};
25+
26+
let ast_program = match ast::Program::analyze(&driver_program) {
1627
Ok(x) => x,
1728
Err(_) => return,
1829
};

0 commit comments

Comments
 (0)