mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
bare: fix str[idx]
This commit is contained in:
parent
0c5854e371
commit
5a1de13e10
@ -211,8 +211,11 @@ fn (p mut Parser) index_get(typ string, fn_ph int, cfg IndexConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if cfg.is_str && !p.builtin_mod && !p.pref.is_bare {
|
else if cfg.is_str && !p.builtin_mod {
|
||||||
if cfg.is_slice {
|
if p.pref.is_bare {
|
||||||
|
p.gen(index_expr)
|
||||||
|
}
|
||||||
|
else if cfg.is_slice {
|
||||||
p.gen('string_substr2($index_expr)')
|
p.gen('string_substr2($index_expr)')
|
||||||
} else {
|
} else {
|
||||||
p.gen('string_at($index_expr)')
|
p.gen('string_at($index_expr)')
|
||||||
|
@ -1856,10 +1856,10 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
|
|||||||
if is_str {
|
if is_str {
|
||||||
typ = 'byte'
|
typ = 'byte'
|
||||||
// Direct faster access to .str[i] in builtin modules
|
// Direct faster access to .str[i] in builtin modules
|
||||||
if p.builtin_mod {
|
if p.builtin_mod || p.pref.is_bare {
|
||||||
p.gen('.str[')
|
p.gen('.str[')
|
||||||
close_bracket = true
|
close_bracket = true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Bounds check everywhere else
|
// Bounds check everywhere else
|
||||||
p.gen(', ')
|
p.gen(', ')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
|
fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
|
||||||
|
|
||||||
fn write(fd int, data voidptr, nbytes u64) int {
|
fn write(fd int, data voidptr, nbytes int) int {
|
||||||
return syscall5(
|
return syscall5(
|
||||||
1, // SYS_write
|
1, // SYS_write
|
||||||
fd,
|
fd,
|
||||||
@ -12,6 +12,9 @@ fn write(fd int, data voidptr, nbytes u64) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
write(1, c'hallo\n', 6)
|
write(1, c'hello\n', 6)
|
||||||
|
s := 'test string'
|
||||||
|
write(1, s.str, s.len)
|
||||||
|
a := s[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user