v2: static (for translated code only)
parent
48832200bb
commit
b1b811b5ed
|
@ -450,6 +450,7 @@ pub:
|
|||
mut:
|
||||
left_types []table.Type
|
||||
right_types []table.Type
|
||||
is_static bool // for translated code only
|
||||
}
|
||||
|
||||
pub struct AsCast {
|
||||
|
|
|
@ -578,6 +578,9 @@ fn (g mut Gen) gen_assert_stmt(a ast.AssertStmt) {
|
|||
|
||||
fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||
// g.write('/*assign_stmt*/')
|
||||
if assign_stmt.is_static {
|
||||
g.write('static ')
|
||||
}
|
||||
if assign_stmt.left.len > assign_stmt.right.len {
|
||||
// multi return
|
||||
mut or_stmts := []ast.Stmt
|
||||
|
|
|
@ -52,6 +52,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
|||
pref: &pref.Preferences{}
|
||||
scope: scope
|
||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||
|
||||
}
|
||||
p.init_parse_fns()
|
||||
p.read_first_token()
|
||||
|
@ -269,7 +270,7 @@ pub fn (p mut Parser) top_stmt() ast.Stmt {
|
|||
p.error('wrong pub keyword usage')
|
||||
return ast.Stmt{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.lsbr {
|
||||
return p.attribute()
|
||||
|
@ -354,7 +355,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||
pos: p.tok.position()
|
||||
}
|
||||
}
|
||||
.key_mut {
|
||||
.key_mut, .key_static {
|
||||
return p.assign_stmt()
|
||||
}
|
||||
.key_for {
|
||||
|
@ -780,6 +781,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
|
|||
node = ast.SizeOf{
|
||||
typ: sizeof_type
|
||||
// type_name: type_name
|
||||
|
||||
}
|
||||
}
|
||||
.key_typeof {
|
||||
|
@ -1050,6 +1052,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
|
|||
left: left
|
||||
right: right
|
||||
// right_type: typ
|
||||
|
||||
op: op
|
||||
pos: pos
|
||||
}
|
||||
|
@ -1454,6 +1457,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
|
|||
fields << ast.Field{
|
||||
name: name
|
||||
// typ: typ
|
||||
|
||||
}
|
||||
exprs << expr
|
||||
// TODO: once consts are fixed reg here & update in checker
|
||||
|
@ -1676,6 +1680,10 @@ fn (p mut Parser) parse_assign_rhs() []ast.Expr {
|
|||
}
|
||||
|
||||
fn (p mut Parser) assign_stmt() ast.Stmt {
|
||||
is_static := p.tok.kind == .key_static
|
||||
if is_static {
|
||||
p.next()
|
||||
}
|
||||
idents := p.parse_assign_lhs()
|
||||
pos := p.tok.position()
|
||||
op := p.tok.kind
|
||||
|
@ -1709,6 +1717,7 @@ fn (p mut Parser) assign_stmt() ast.Stmt {
|
|||
right: exprs
|
||||
op: op
|
||||
pos: pos
|
||||
is_static: is_static
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1849,7 +1858,7 @@ fn (p mut Parser) enum_decl() ast.EnumDecl {
|
|||
}
|
||||
// Allow commas after enum, helpful for
|
||||
// enum Color {
|
||||
// r,g,b
|
||||
// r,g,b
|
||||
// }
|
||||
if p.tok.kind == .comma {
|
||||
p.next()
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
fn C.strlen() int
|
||||
|
||||
fn test_cstring() {
|
||||
w := c'world'
|
||||
hlen := C.strlen(c'hello')
|
||||
|
|
Loading…
Reference in New Issue