From c324169af0f854cecb2f65e9ea83d7e757c5dda6 Mon Sep 17 00:00:00 2001 From: Henrixounez <30901439+Henrixounez@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:41:45 +0200 Subject: [PATCH] all: remove intermediate handling for both global definition syntaxes (#6546) --- vlib/builtin/builtin.v | 14 ++++++++------ vlib/builtin/builtin_windows.c.v | 2 +- vlib/builtin/string.v | 2 +- vlib/rand/rand.v | 2 +- vlib/sokol/sapp/sapp.v | 2 +- vlib/v/parser/parser.v | 31 ++++--------------------------- 6 files changed, 16 insertions(+), 37 deletions(-) diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index 3ebb8e5f69..65f16476ba 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -3,8 +3,10 @@ // that can be found in the LICENSE file. module builtin -__global g_m2_buf byteptr -__global g_m2_ptr byteptr +__global ( + g_m2_buf byteptr + g_m2_ptr byteptr +) type FnExitCb = fn() fn C.atexit(f FnExitCb) int @@ -125,10 +127,10 @@ pub fn println(s string) { } } -__global total_m i64=0 -__global nr_mallocs int=0 - -fn looo(){} // TODO remove, [ pratt +__global ( + total_m = i64(0) + nr_mallocs = int(0) +) [unsafe] pub fn malloc(n int) byteptr { diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index a9db49193c..fb74c0c0c6 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -60,7 +60,7 @@ const ( ) // g_original_codepage - used to restore the original windows console code page when exiting -__global g_original_codepage u32=0 +__global ( g_original_codepage = u32(0) ) // utf8 to stdout needs C.SetConsoleOutputCP(C.CP_UTF8) fn C.GetConsoleOutputCP() u32 fn C.SetConsoleOutputCP(wCodePageID u32) bool diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 6f87442fa2..fc75c7ebf4 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -1070,7 +1070,7 @@ pub fn (s string) ustring() ustring { // A hack that allows to create ustring without allocations. // It's called from functions like draw_text() where we know that the string is going to be freed // right away. Uses global buffer for storing runes []int array. -__global g_ustring_runes []int +__global ( g_ustring_runes []int ) pub fn (s string) ustring_tmp() ustring { if g_ustring_runes.len == 0 { diff --git a/vlib/rand/rand.v b/vlib/rand/rand.v index ad0f1ddf45..c8198e172d 100644 --- a/vlib/rand/rand.v +++ b/vlib/rand/rand.v @@ -12,7 +12,7 @@ pub struct PRNGConfigStruct { seed []u32 = util.time_seed_array(2) } -__global default_rng &wyrand.WyRandRNG +__global ( default_rng &wyrand.WyRandRNG ) fn init() { default_rng = new_default({}) } diff --git a/vlib/sokol/sapp/sapp.v b/vlib/sokol/sapp/sapp.v index 9316e11e2e..c6541e05f6 100644 --- a/vlib/sokol/sapp/sapp.v +++ b/vlib/sokol/sapp/sapp.v @@ -1,7 +1,7 @@ module sapp // Android needs a global reference to `g_desc` -__global g_desc C.sapp_desc +__global ( g_desc C.sapp_desc ) pub fn create_desc() C.sg_desc { mtl_desc := C.sg_mtl_context_desc { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 06c9e78416..3b42f60a21 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1679,33 +1679,7 @@ fn (mut p Parser) global_decl() ast.GlobalDecl { end_pos := p.tok.position() p.check(.key_global) if p.tok.kind != .lpar { - // Need to work for intermediate V Compiler for PRs process - // p.error('globals must be grouped, e.g. `__global ( a = int(1) )`') - pos := p.tok.position() - name := p.check_name() - typ := p.parse_type() - mut expr := ast.Expr{} - has_expr := p.tok.kind == .assign - if has_expr { - p.next() - expr = p.expr(0) - } - mut fields := []ast.GlobalField{} - field := ast.GlobalField{ - name: name - has_expr: has_expr - expr: expr - pos: pos - typ: typ - comments: []ast.Comment{} - } - fields << field - p.global_scope.register(field.name, field) - return ast.GlobalDecl{ - fields: fields - pos: start_pos.extend(end_pos) - end_comments: []ast.Comment{} - } + p.error('globals must be grouped, e.g. `__global ( a = int(1) )`') } p.next() // ( mut fields := []ast.GlobalField{} @@ -1722,6 +1696,9 @@ fn (mut p Parser) global_decl() ast.GlobalDecl { p.next() // = } typ := p.parse_type() + if p.tok.kind == .assign { + p.error('global assign must have the type around the value, use `__global ( name = type(value) )`') + } mut expr := ast.Expr{} if has_expr { if p.tok.kind != .lpar {