Skip to content

Commit

Permalink
-- adding wit
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Dec 1, 2024
1 parent ab49f53 commit 04fac4c
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 6 deletions.
19 changes: 17 additions & 2 deletions crates/codegen/runtime/cargo/crate/src/runtime/compilation/unit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is generated automatically by infrastructure scripts. Please don't edit by hand.

use std::collections::btree_map::Keys;
use std::collections::BTreeMap;

use crate::compilation::File;
Expand All @@ -13,7 +14,21 @@ impl CompilationUnit {
Self { files }
}

pub fn files(&self) -> &BTreeMap<String, File> {
&self.files
pub fn files(&self) -> FilesIterator {
FilesIterator {
inner: self.files.clone().keys(),
}
}
}

pub struct FilesIterator {
inner: Keys<String, File>,
}

impl Iterator for FilesIterator {
type Item = File;

fn next(&mut self) -> Option<Self::Item> {
self.inner.next()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
interface compilation {
use cst.{node, cursor};

/// A single source file in the compilation unit.
resource file {
/// Returns the unique identifier of this file.
id: func() -> string;

/// Returns the syntax tree of this file.
tree: func() -> node;

/// Creates a cursor for traversing the syntax tree of this file.
create-tree-cursor: func() -> cursor;
}

/// Contains information about imports found in an added source file.
record add-file-response {
/// List of import strings found in the added file.
import-strings: list<string>,
}

/// A builder for creating compilation units.
/// Allows incrementally building a transitive list of all files and their imports.
resource compilation-builder {
/// Creates a new compilation builder for the specified language version.
create: static func(version: string) -> result<compilation-builder, string>;

/// Adds a source file to the compilation unit.
add-file: func(id: string, contents: string) -> result<add-file-response, string>;

/// Adds an import relationship between files.
add-import: func(file-id: string, import-string: string, imported-file-id: string) -> result<_, string>;

/// Builds and returns the final compilation unit.
build: func() -> compilation-unit;
}

/// A complete compilation unit containing all source files and their relationships.
resource compilation-unit {
/// Returns a map of all files in the compilation unit, keyed by their IDs.
files: func() -> files-iterator;
}

/// Iterator over files in the compilation unit.
resource files-iterator {
/// Returns the next file or None if there are no more files.
next: func() -> option<file>;
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nomic-foundation:slang;

world slang {
export ast;
export compilation;
export cst;
export parser;
export utils;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04fac4c

Please sign in to comment.