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 <signal.h>
#include <stdarg.h> // for va_list #include <stdarg.h> // for va_list
#include <inttypes.h> // int64_t etc #include <inttypes.h> // int64_t etc
#include <string.h> // memcpy
#define STRUCT_DEFAULT_VALUE {} #define STRUCT_DEFAULT_VALUE {}
#define EMPTY_STRUCT_DECLARATION #define EMPTY_STRUCT_DECLARATION

View File

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

View File

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