Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Dec 11, 2024
1 parent 5422e74 commit b44852a
Show file tree
Hide file tree
Showing 22 changed files with 1,063 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use crate::cst::KindTypes;
pub type BindingGraph = metaslang_bindings::BindingGraph<KindTypes>;
pub type Definition<'a> = metaslang_bindings::Definition<'a, KindTypes>;
pub type Reference<'a> = metaslang_bindings::Reference<'a, KindTypes>;
pub use metaslang_bindings::PathResolver;
pub type BindingLocation = metaslang_bindings::BindingLocation<KindTypes>;
pub type UserFileLocation = metaslang_bindings::UserFileLocation<KindTypes>;

pub use metaslang_bindings::{BuiltInLocation, PathResolver};

pub fn create_with_resolver(
version: Version,
Expand Down
40 changes: 40 additions & 0 deletions crates/codegen/runtime/cargo/wasm/src/runtime/config.json.jinja2
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"mappings": {
"nomic-foundation:slang:bindings:definition.id()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:bindings:definition.name-location()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:bindings:definition.definiens-location()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:bindings:reference.id()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:bindings:reference.location()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:bindings:binding-location": {
"Variant": {
"as_direct_union_of_resource_classes": true
}
},
"nomic-foundation:slang:bindings:user-file-location.file-id()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:bindings:user-file-location.cursor()": {
"Function": {
"as_getter": true
}
},
"nomic-foundation:slang:compilation:compilation-unit.language-version()": {
"Function": {
"as_getter": true
Expand Down

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
@@ -1,4 +1,70 @@
interface bindings {
use cst.{cursor};

/// A giant graph that contains name binding information for all source files within the compilation unit.
/// It stores cursors to all definitions and references, and can resolve the edges between them.
resource binding-graph {
/// If the provided cursor points at a definition `Identifier`, it will return the
/// corresponding definition. Otherwise, it will return `undefined`.
definition-at: func(cursor: cursor) -> option<definition>;

/// If the provided cursor points at a reference `Identifier`, it will return the
/// corresponding reference. Otherwise, it will return `undefined`.
reference-at: func(cursor: cursor) -> option<reference>;
}

/// Represents a definition in the binding graph.
resource definition {
/// Returns a unique numerical identifier of the definition.
/// It is only valid for the lifetime of the binding graph.
/// It can change between multiple graphs, even for the same source code input.
id: func() -> u32;

/// Returns the location of the definition's name.
/// For `contract X {}`, that is the location of the `X` `Identifier` node.
name-location: func() -> binding-location;

/// Returns the location of the definition's definiens.
/// For `contract X {}`, that is the location of the parent `ContractDefinition` node.
definiens-location: func() -> binding-location;
}

/// Represents a reference in the binding graph.
resource reference {
/// Returns a unique numerical identifier of the reference.
/// It is only valid for the lifetime of the binding graph.
/// It can change between multiple graphs, even for the same source code input.
id: func() -> u32;

/// Returns the location of the reference.
/// For `new X()`, that is the location of the `X` `Identifier` node.
location: func() -> binding-location;

/// Returns a list of all definitions related to this reference.
/// Most references have a single definition, but some have multiple, such as when a symbol
/// is imported from another file, and renamed (re-defined) in the current file.
definitions: func() -> list<definition>;
}

/// Represents a location of a symbol (definition or reference) in the binding graph.
/// It can either be in a user file, or a built-in in the language.
variant binding-location {
/// Represents a location of a user-defined symbol in a user file.
user-file(user-file-location),
/// Represents a location of a built-in symbol in the language.
built-in(built-in-location)
}

/// Represents a location of a user-defined symbol in a user file.
resource user-file-location {
/// Returns the ID of the file that contains the symbol.
file-id: func() -> string;

/// Returns a cursor to the CST node that contains the symbol.
cursor: func() -> cursor;
}

/// Represents a location of a built-in symbol in the language.
resource built-in-location {
}
}

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

Loading

0 comments on commit b44852a

Please sign in to comment.