another map bug fix + fix some warnings

pull/1397/head
Alexander Medvednikov 2019-07-31 10:46:00 +02:00
parent fa24a0cec5
commit ddb4f45b02
4 changed files with 9 additions and 9 deletions

View File

@ -193,6 +193,7 @@ fn (v mut V) compile() {
#include <signal.h>
#include <stdarg.h> // for va_list
#include <inttypes.h> // int64_t etc
#include <string.h> // memcpy
#define STRUCT_DEFAULT_VALUE {}
#define EMPTY_STRUCT_DECLARATION

View File

@ -2309,19 +2309,17 @@ fn format_str(str string) string {
}
fn (p mut Parser) string_expr() {
// println('.str EXPR')
str := p.lit
// No ${}, just return a simple string
if p.peek() != .dollar {
p.fgen('\'$str\'')
// println('before format: "$str"')
f := format_str(str)
// println('after format: "$str"')
// `C.puts('hi')` => `puts("hi");`
if p.calling_c || (p.pref.translated && p.mod == 'main') {
p.gen('"$f"')
}
else {
p.gen('tos2("$f")')
p.gen('tos2((byte*)"$f")')
}
p.next()
return
@ -2388,7 +2386,7 @@ fn (p mut Parser) string_expr() {
}
if complex_inter {
p.fgen('}')
}
}
p.fgen('\'')
// println("hello %d", num) optimization.
if p.cgen.nogen {

View File

@ -143,11 +143,10 @@ fn (m map) bs(query string, start, end int, out voidptr) {
*/
fn (m mut map) preorder_keys(node &Node) {
if node.is_empty {
return
}
if !node.is_empty {
m._keys[m.key_i] = node.key
m.key_i++
}
if !isnil(node.left) {
m.preorder_keys(node.left)
}

View File

@ -38,8 +38,10 @@ fn test_map() {
assert keys[1] == 'hello'
m.delete('hi')
assert m.size == 1
assert m['hi'] == 0
assert m.keys().len == 1
assert m.keys()[0] == 'hello'
////
mut users := map[string]User{}
users['1'] = User{'Peter'}