From b5cb1b1fe29a7632bd40be80bcfa0f48a49fa126 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 19 Mar 2020 10:07:31 +0100 Subject: [PATCH] cgen: map_get/map_set --- vlib/v/gen/cgen.v | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 89053c7ea3..05be9a5b00 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -65,7 +65,7 @@ pub fn (g mut Gen) typ(t table.Type) string { if styp.starts_with('C__') { styp = styp[3..] } - if styp in ['stat', 'dirent*', 'tm', 'tm*'] { + if styp in ['stat', 'dirent*', 'tm', 'tm*', 'winsize'] { // TODO perf and other C structs styp = 'struct $styp' } @@ -1261,6 +1261,25 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) { g.write('))') } } + else if sym.kind == .map { + info := sym.info as table.Map + elem_type_str := g.typ(info.value_type) + if g.is_assign_expr { + g.is_array_set = true + g.write('map_set(&') + g.expr(node.left) + g.write(', ') + g.expr(node.index) + g.write(', &($elem_type_str[]) { ') + } + else { + g.write('(*($elem_type_str*)map_get2(') + g.expr(node.left) + g.write(', ') + g.expr(node.index) + g.write('))') + } + } else if sym.kind == .string && !table.type_is_ptr(node.container_type) { g.write('string_at(') g.expr(node.left)