all: remove intermediate handling for both global definition syntaxes (#6546)

pull/6550/head
Henrixounez 2020-10-03 15:41:45 +02:00 committed by GitHub
parent 7e13518cc2
commit c324169af0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 37 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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({})
}

View File

@ -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 {

View File

@ -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 {