-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
native: for in string #24613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
native: for in string #24613
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -95,6 +95,7 @@ mut: | |
cmp_to_stack_top(r Register) | ||
cmp_var_reg(var Var, reg Register, config VarConfig) | ||
cmp_var(var Var, val i32, config VarConfig) | ||
cmp_reg2(reg Register, reg2 Register) | ||
cmp_zero(reg Register) | ||
convert_bool_to_string(r Register) | ||
convert_int_to_string(a Register, b Register) | ||
|
@@ -131,6 +132,7 @@ mut: | |
mov64(r Register, val Number) | ||
movabs(reg Register, val i64) | ||
patch_relative_jmp(pos i32, addr i64) | ||
pop2(r Register) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add |
||
prefix_expr(node ast.PrefixExpr) | ||
push(r Register) | ||
ret() | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
|
||
fn test_for_c_in_string() { | ||
$if windows { | ||
println('0') | ||
println('97') | ||
println('1') | ||
println('98') | ||
println('2') | ||
println('99') | ||
} $else { | ||
s := 'abc' | ||
for i, c in s { | ||
println(i) | ||
println(int(c)) | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
test_for_c_in_string() | ||
} |
This file contains hidden or 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,6 @@ | ||
0 | ||
97 | ||
1 | ||
98 | ||
2 | ||
99 |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use
cmp_reg2
instead ofcmp_reg
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because
cmp_reg
needs Amd64Register and not Register, so cmp_reg2 is a function that casts the Registers to Amd64Register and then callscmp_reg
. I did not change thecmp_reg
function as it is already used in a lot of places, to avoid big changes. (same for pop and pop2)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a place, that will need to call the interface version, instead of the CPU specific one?
i.e. why does it need to be in the public interface at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, there are a lot of calls to it
fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
, similar to this:That does not seem right to me -
vlib/v/gen/native/stmt.c.v
is supposed to have platform independent code, not pass the names of Amd64 specific registers around 🤔 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have something similar to:
main_reg := g.code_gen.main_reg()
for example:
sreg := g.code_gen.secondary_reg()
and then use that instead of
Amd64Register.rdx
in places, that are not supposed to be platform dependent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, that cleanup is better indeed to be in its own separate PR, not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I will clean this up when I'll have a better idea on how it could be organized in a cleaner way.