-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: add comptime support for traversing the method parameters with `…
…$for arg in method.params {` (#22229)
- Loading branch information
Showing
12 changed files
with
100 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1250,6 +1250,7 @@ pub enum ComptimeForKind { | |
attributes | ||
values | ||
variants | ||
params | ||
} | ||
|
||
pub struct ComptimeFor { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module main | ||
|
||
struct Struct1 { | ||
num f64 | ||
} | ||
|
||
fn (mut s Struct1) do_thing(a f32, b voidptr) bool { | ||
return false | ||
} | ||
|
||
fn register[T]() []string { | ||
mut args := []string{} | ||
$for method in T.methods { | ||
$for arg in method.params { | ||
$if arg.typ is f32 { | ||
args << 'f32: ${arg.name} ${typeof(arg.typ).name}' | ||
} $else $if arg.typ is voidptr { | ||
args << '&void: ${arg.name} ${typeof(arg.typ).name}' | ||
} $else { | ||
} | ||
} | ||
} | ||
return args | ||
} | ||
|
||
pub fn test_main() { | ||
args := register[Struct1]() | ||
assert args[0] == 'f32: a f32' | ||
assert args[1] == '&void: b voidptr' | ||
} |