From 5ed338dc2e03969cdb15b063031569079cb82304 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 5 Aug 2019 04:34:12 +0200 Subject: [PATCH] bring back map.str() --- compiler/tests/mut_test.v | 6 ++++++ tools/vget.v | 7 +++++-- vlib/builtin/map.v | 21 +++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 compiler/tests/mut_test.v diff --git a/compiler/tests/mut_test.v b/compiler/tests/mut_test.v new file mode 100644 index 0000000000..0d91d2cde1 --- /dev/null +++ b/compiler/tests/mut_test.v @@ -0,0 +1,6 @@ +fn test_mut() { + a := 1 + mut b := &a + *b = 10 + println(a) +} diff --git a/tools/vget.v b/tools/vget.v index c7a08ff5ab..a9bf8a2804 100644 --- a/tools/vget.v +++ b/tools/vget.v @@ -8,7 +8,7 @@ import ( const ( //url = 'http://localhost:8089' - url = 'http://vpm.vlang.io' + url = 'https://vpm.best' ) struct Mod { @@ -25,7 +25,10 @@ fn main() { } name := os.args.last() s := http.get_text(url + '/jsmod/$name') - mod := json.decode(Mod, s) or { return } + mod := json.decode(Mod, s) or { + println('Error. Make sure you are online.') + return + } home := os.home_dir() os.exec('git -C "$home/.vmodules" clone --depth=1 $mod.url $mod.name') println(s) diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 7a401bf8ee..7c8983183e 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -4,6 +4,8 @@ module builtin +import strings + struct map { element_size int root *Node @@ -243,16 +245,19 @@ pub fn (m map) free() { } pub fn (m map_string) str() string { - // return 'not impl' if m.size == 0 { return '{}' } // TODO use bytes buffer - mut s := '{\n' - //for key, val in m { - //val := m[entry.key] - //s += ' "$entry.key" => "$val"\n' - //} - s += '}' - return s + //mut sb := strings.new_builder(50) + //sb.writeln('{') + mut s := '{\n' + for key, val in m { + //sb.writeln(' "$entry.key" => "$val"') + s += ' "$key" => "$val"\n' + } + s += '}\n' + //sb.writeln('}') + //return sb.str() + return s }