Skip to content

Commit

Permalink
Improvements to types and subtyping (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave authored Oct 20, 2023
1 parent a1814a5 commit af3b2d0
Show file tree
Hide file tree
Showing 52 changed files with 3,007 additions and 1,692 deletions.
34 changes: 23 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Consider checking out [current standing issues](https://github.com/kaleidawave/ezno/issues) before contributing. In general, leave an issue before putting in a PR.

*If any problems come up following the steps. Leave an issue*
If any problems come up in the following steps, please leave an issue :)

#### Setting up

Expand All @@ -14,21 +14,28 @@ then clone the repo with `git`:

```shell
git clone https://github.com/kaleidawave/ezno.git
# or using the GH CLI
gh repo clone kaleidawave/ezno
```

or using the GH CLI
Now in the `ezno` directory, `cargo run` should show the CLI.

## Development

If you don't want to run the whole Ezno CLI. You can run just the checker with

```shell
gh repo clone kaleidawave/ezno
cargo run -p ezno-checker -F ezno-parser --example check path/to/file.ts
```

Now in the `ezno` directory, `cargo run` should show the CLI

### Rules
If you want to test the lexing and parsing in Ezno's parser

- Won't merge PRs that introduce new errors. However will merge PRs which pick up or find existing issues
- Code **must** be formatted with `cargo format` inline with the current format configuration
- Use `cargo clippy` as guidance but lints are not a blocker
```shell
# Parsing, prints parse errors or the debug view of the AST
cargo run -p ezno-parser --example parse path/to/file.ts
# Lexing, prints lex errors or the tokens
cargo run -p ezno-parser --example lex path/to/file.ts
```

### Useful commands

Expand All @@ -39,7 +46,12 @@ Now in the `ezno` directory, `cargo run` should show the CLI
### The notify! macro

The checker crate has the `crate::utils::notify!` macro, which can be used to trace information when the `EZNO_DEBUG` environment variable is set.
## *Rules* for contributions

- Won't merge PRs that introduce new errors. However will merge PRs which pick up or find existing issues
- Code **must** be formatted with `cargo format` inline with the current format configuration
- Use `cargo clippy` as guidance for design but warning lints are not a blocker

### Oxc
## Oxc

If working on [oxc_type_synthesis](https://github.com/web-infra-dev/oxc/tree/main/crates/oxc_type_synthesis). You can (git) clone [oxc](https://github.com/web-infra-dev/oxc) alongside Ezno and then use path dependencies to work on them simultaneously.
If working on [oxc_type_synthesis](https://github.com/web-infra-dev/oxc/tree/main/crates/oxc_type_synthesis) **and Ezno simultaneously**. You can (git) clone [oxc](https://github.com/web-infra-dev/oxc) alongside Ezno and then use path dependencies to work on them simultaneously.
24 changes: 20 additions & 4 deletions checker/definitions/internal.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ↓↓ Ezno Functions ↓↓
declare function debug_context(): void performs const debug_context;
declare function print_type(t: any): void performs const print_type;
declare function debug_type(t: any): void performs const debug_type;
Expand All @@ -11,17 +12,30 @@ declare function context_id_chain(): void performs const context_id_chain;
declare function satisfies<T>(t: T): T performs const satisfies;

declare function compile_type_to_object<T>(): any performs const compile_type_to_object;
// ↑↑ Ezno Functions ↑↑

interface Array<T> {
length: number;
declare var undefined: undefined;

interface nominal Array<T> {
[index: number]: T;

length: number;

push(item: any) performs {
push(item: T) performs {
this[this.length] = item;
return ++this.length
}

pop(): T | undefined performs {
if (this.length === 0) {
return undefined
} else {
const value = this[--this.length];
delete this[this.length];
return value
}
}

last() performs {
return this[this.length - 1]
}
Expand All @@ -36,9 +50,11 @@ interface Math {
cbrt(x: number): number performs const cbrt;
}

interface string {
interface nominal string {
toUpperCase(): string performs const uppercase;
toLowerCase(): string performs const lowercase;

get length(): number performs const string_length;
}

interface Console {
Expand Down
55 changes: 55 additions & 0 deletions checker/examples/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#[cfg(feature = "ezno-parser")]
fn main() {
use ezno_checker::{check_project, synthesis};
use std::{
collections::HashSet,
env, fs,
path::{Path, PathBuf},
};

let name = env::args().nth(1).unwrap_or_else(|| "examples/test.ts".to_string());
let path = Path::new(&name);

let (diagnostics, post_check_data) = check_project::<_, synthesis::EznoParser>(
path.to_path_buf(),
HashSet::from_iter(std::iter::once(ezno_checker::INTERNAL_DEFINITION_FILE_PATH.into())),
|path: &std::path::Path| {
if path == &PathBuf::from(ezno_checker::INTERNAL_DEFINITION_FILE_PATH) {
Some(ezno_checker::INTERNAL_DEFINITION_FILE.to_owned())
} else {
Some(fs::read_to_string(path).unwrap())
}
},
None,
Default::default(),
);

let args: Vec<_> = env::args().collect();

if let Ok(mut post_check_data) = post_check_data {
if args.iter().any(|arg| arg == "--types") {
eprintln!("Types:");
for item in post_check_data.types.into_vec_temp() {
eprintln!("\t{:?}", item);
}
}
if args.iter().any(|arg| arg == "--events") {
eprintln!("Events on entry:");
let entry_module =
post_check_data.modules.remove(&post_check_data.entry_source).unwrap();
for item in entry_module.facts.get_events() {
eprintln!("\t{:?}", item);
}
}
}

eprintln!("Diagnostics:");
for diagnostic in diagnostics.into_iter() {
eprintln!("\t{}", diagnostic.reason())
}
}

#[cfg(not(feature = "ezno-parser"))]
fn main() {
println!("Requires 'ezno-parser'")
}
3 changes: 3 additions & 0 deletions checker/specification/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ publish = false
[workspace]
members = ["."]

[features]
all = []

[[test]]
name = "specification_test"
path = "test.rs"
Expand Down
13 changes: 5 additions & 8 deletions checker/specification/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::io::Write;
use std::path::Path;

fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=specification.md");
println!("cargo:rerun-if-changed=TODO.md");

let out_path = Path::new(&std::env::var("OUT_DIR")?).join("specification.rs");
let mut out = File::create(out_path)?;

Expand All @@ -19,14 +22,8 @@ fn main() -> Result<(), Box<dyn Error>> {
markdown_lines_append_test_to_rust(lines, &mut out)?;

if cfg!(feature = "all") {
let not_yet_implemented = read_to_string("./not_yet_implemented.md")?;
let mut lines = not_yet_implemented.lines().enumerate();

while let Some((_, line)) = lines.next() {
if line == "## TODO" {
break;
}
}
let not_yet_implemented = read_to_string("./to_implement.md")?;
let lines = not_yet_implemented.lines().enumerate();

writeln!(&mut out, "mod todo {{ use super::check_errors; ").unwrap();
markdown_lines_append_test_to_rust(lines, &mut out)?;
Expand Down
Loading

0 comments on commit af3b2d0

Please sign in to comment.