Skip to content

Commit

Permalink
Merge 08b7c34 into b84009c
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunkar authored Sep 5, 2024
2 parents b84009c + 08b7c34 commit 2b6b630
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
12 changes: 12 additions & 0 deletions compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl<'local, 'context> Interpreter<'local, 'context> {
"quoted_as_trait_constraint" => quoted_as_trait_constraint(self, arguments, location),
"quoted_as_type" => quoted_as_type(self, arguments, location),
"quoted_eq" => quoted_eq(arguments, location),
"quoted_tokens" => quoted_tokens(arguments, location),
"slice_insert" => slice_insert(interner, arguments, location),
"slice_pop_back" => slice_pop_back(interner, arguments, location, call_stack),
"slice_pop_front" => slice_pop_front(interner, arguments, location, call_stack),
Expand Down Expand Up @@ -535,6 +536,17 @@ fn quoted_as_type(
Ok(Value::Type(typ))
}

// fn tokens(quoted: Quoted) -> [Quoted]
fn quoted_tokens(arguments: Vec<(Value, Location)>, location: Location) -> IResult<Value> {
let argument = check_one_argument(arguments, location)?;
let value = get_quoted(argument)?;

Ok(Value::Slice(
value.iter().map(|token| Value::Quoted(Rc::new(vec![token.clone()]))).collect(),
Type::Slice(Box::new(Type::Quoted(QuotedType::Quoted))),
))
}

fn to_le_radix(
arguments: Vec<(Value, Location)>,
return_type: Type,
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/noir/standard_library/meta/quoted.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ stream doesn't parse to a type or if the type isn't a valid type in scope.

#include_code implements_example test_programs/compile_success_empty/comptime_type/src/main.nr rust

### tokens

#include_code tokens noir_stdlib/src/meta/quoted.nr rust

Returns a slice of the individual tokens that form this token stream.

## Trait Implementations

```rust
Expand Down
13 changes: 9 additions & 4 deletions noir_stdlib/src/meta/quoted.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ use crate::option::Option;

impl Quoted {
#[builtin(quoted_as_expr)]
// docs:start:as_expr
// docs:start:as_expr
fn as_expr(self) -> Option<Expr> {}
// docs:end:as_expr

#[builtin(quoted_as_module)]
// docs:start:as_module
// docs:start:as_module
fn as_module(self) -> Option<Module> {}
// docs:end:as_module

#[builtin(quoted_as_trait_constraint)]
// docs:start:as_trait_constraint
// docs:start:as_trait_constraint
fn as_trait_constraint(self) -> TraitConstraint {}
// docs:end:as_trait_constraint

#[builtin(quoted_as_type)]
// docs:start:as_type
// docs:start:as_type
fn as_type(self) -> Type {}
// docs:end:as_type

#[builtin(quoted_tokens)]
// docs:start:tokens
fn tokens(self) -> [Quoted] {}
// docs:end:tokens
}

impl Eq for Quoted {
Expand Down

0 comments on commit 2b6b630

Please sign in to comment.