mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: array << val
This commit is contained in:
parent
c14c81ace6
commit
260f708bb2
@ -810,8 +810,8 @@ pub fn (c mut Checker) index_expr(node mut ast.IndexExpr) table.Type {
|
||||
}
|
||||
else {}
|
||||
}
|
||||
node.container_type = typ
|
||||
if !is_range {
|
||||
node.container_type = typ
|
||||
typ_sym := c.table.get_type_symbol(typ)
|
||||
index_type := c.expr(node.index)
|
||||
index_type_sym := c.table.get_type_symbol(index_type)
|
||||
|
@ -218,7 +218,7 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
||||
ast.ForStmt {
|
||||
g.write('while (')
|
||||
g.expr(it.cond)
|
||||
g.writeln(') {')
|
||||
g.writeln(') { //1')
|
||||
for stmt in it.stmts {
|
||||
g.stmt(stmt)
|
||||
}
|
||||
@ -483,6 +483,7 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
// if it.left_type == table.string_type_idx {
|
||||
// g.write('/*$it.left_type str*/')
|
||||
// }
|
||||
// string + string
|
||||
if it.op == .plus && it.left_type == table.string_type_idx {
|
||||
g.write('string_add(')
|
||||
g.expr(it.left)
|
||||
@ -490,6 +491,14 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
g.expr(it.right)
|
||||
g.write(')')
|
||||
}
|
||||
// arr << val
|
||||
else if it.op == .left_shift && g.table.get_type_symbol(it.left_type).kind == .array {
|
||||
g.write('array_push(')
|
||||
g.expr(it.left)
|
||||
g.write(', ')
|
||||
g.expr(it.right)
|
||||
g.write(')')
|
||||
}
|
||||
else {
|
||||
// if it.op == .dot {
|
||||
// println('!! dot')
|
||||
@ -634,8 +643,17 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
|
||||
mut is_range := false
|
||||
match node.index {
|
||||
ast.RangeExpr {
|
||||
is_range = true
|
||||
g.write('array_slice(')
|
||||
// TODO should never be 0
|
||||
if node.container_type != 0 {
|
||||
sym := g.table.get_type_symbol(node.container_type)
|
||||
is_range = true
|
||||
if sym.kind == .string {
|
||||
g.write('string_substr(')
|
||||
}
|
||||
else if sym.kind == .array {
|
||||
g.write('array_slice(')
|
||||
}
|
||||
}
|
||||
g.expr(node.left)
|
||||
g.write(', ')
|
||||
if it.has_low {
|
||||
|
Loading…
Reference in New Issue
Block a user