diff --git a/crates/codegen/runtime/cargo/crate/src/runtime/compilation/unit.rs b/crates/codegen/runtime/cargo/crate/src/runtime/compilation/unit.rs index 05cf54e5a3..2e58aa002b 100644 --- a/crates/codegen/runtime/cargo/crate/src/runtime/compilation/unit.rs +++ b/crates/codegen/runtime/cargo/crate/src/runtime/compilation/unit.rs @@ -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; @@ -13,7 +14,21 @@ impl CompilationUnit { Self { files } } - pub fn files(&self) -> &BTreeMap { - &self.files + pub fn files(&self) -> FilesIterator { + FilesIterator { + inner: self.files.clone().keys(), + } + } +} + +pub struct FilesIterator { + inner: Keys, +} + +impl Iterator for FilesIterator { + type Item = File; + + fn next(&mut self) -> Option { + self.inner.next() } } diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/compilation.wit.jinja2 b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/compilation.wit.jinja2 new file mode 100644 index 0000000000..019868110e --- /dev/null +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/compilation.wit.jinja2 @@ -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, + } + + /// 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; + + /// Adds a source file to the compilation unit. + add-file: func(id: string, contents: string) -> result; + + /// 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; + } + +} diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/compilation.wit b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/compilation.wit new file mode 100644 index 0000000000..8e29ef2c48 --- /dev/null +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/compilation.wit @@ -0,0 +1,52 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +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, + } + + /// 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; + + /// Adds a source file to the compilation unit. + add-file: func(id: string, contents: string) -> result; + + /// 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; + } + +} diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/world.wit b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/world.wit index 287bf6aa6a..13f1b36316 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/world.wit +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/generated/world.wit @@ -4,6 +4,7 @@ package nomic-foundation:slang; world slang { export ast; + export compilation; export cst; export parser; export utils; diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/world.wit.jinja2 b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/world.wit.jinja2 index ed0bb2f9af..943d78cac7 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/world.wit.jinja2 +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/world.wit.jinja2 @@ -2,6 +2,7 @@ package nomic-foundation:slang; world slang { export ast; + export compilation; export cst; export parser; export utils; diff --git a/crates/solidity/outputs/cargo/crate/src/generated/compilation/unit.rs b/crates/solidity/outputs/cargo/crate/src/generated/compilation/unit.rs index 111129f781..f7119c89d2 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/compilation/unit.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/compilation/unit.rs @@ -2,6 +2,7 @@ // 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; @@ -15,7 +16,21 @@ impl CompilationUnit { Self { files } } - pub fn files(&self) -> &BTreeMap { - &self.files + pub fn files(&self) -> FilesIterator { + FilesIterator { + inner: self.files.clone().keys(), + } + } +} + +pub struct FilesIterator { + inner: Keys, +} + +impl Iterator for FilesIterator { + type Item = File; + + fn next(&mut self) -> Option { + self.inner.next() } } diff --git a/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/compilation.wit b/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/compilation.wit new file mode 100644 index 0000000000..8e29ef2c48 --- /dev/null +++ b/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/compilation.wit @@ -0,0 +1,52 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +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, + } + + /// 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; + + /// Adds a source file to the compilation unit. + add-file: func(id: string, contents: string) -> result; + + /// 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; + } + +} diff --git a/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/world.wit b/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/world.wit index 287bf6aa6a..13f1b36316 100644 --- a/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/world.wit +++ b/crates/solidity/outputs/cargo/wasm/src/generated/interface/generated/world.wit @@ -4,6 +4,7 @@ package nomic-foundation:slang; world slang { export ast; + export compilation; export cst; export parser; export utils; diff --git a/crates/testlang/outputs/cargo/crate/src/generated/compilation/unit.rs b/crates/testlang/outputs/cargo/crate/src/generated/compilation/unit.rs index 111129f781..f7119c89d2 100644 --- a/crates/testlang/outputs/cargo/crate/src/generated/compilation/unit.rs +++ b/crates/testlang/outputs/cargo/crate/src/generated/compilation/unit.rs @@ -2,6 +2,7 @@ // 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; @@ -15,7 +16,21 @@ impl CompilationUnit { Self { files } } - pub fn files(&self) -> &BTreeMap { - &self.files + pub fn files(&self) -> FilesIterator { + FilesIterator { + inner: self.files.clone().keys(), + } + } +} + +pub struct FilesIterator { + inner: Keys, +} + +impl Iterator for FilesIterator { + type Item = File; + + fn next(&mut self) -> Option { + self.inner.next() } } diff --git a/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/compilation.wit b/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/compilation.wit new file mode 100644 index 0000000000..8e29ef2c48 --- /dev/null +++ b/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/compilation.wit @@ -0,0 +1,52 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +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, + } + + /// 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; + + /// Adds a source file to the compilation unit. + add-file: func(id: string, contents: string) -> result; + + /// 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; + } + +} diff --git a/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/world.wit b/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/world.wit index 287bf6aa6a..13f1b36316 100644 --- a/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/world.wit +++ b/crates/testlang/outputs/cargo/wasm/src/generated/interface/generated/world.wit @@ -4,6 +4,7 @@ package nomic-foundation:slang; world slang { export ast; + export compilation; export cst; export parser; export utils;