v2: static (for translated code only)

pull/4176/head
Alexander Medvednikov 2020-04-01 13:38:05 +02:00
parent 48832200bb
commit b1b811b5ed
4 changed files with 19 additions and 8 deletions

View File

@ -450,6 +450,7 @@ pub:
mut:
left_types []table.Type
right_types []table.Type
is_static bool // for translated code only
}
pub struct AsCast {

View File

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

View File

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

View File

@ -1,5 +1,3 @@
fn C.strlen() int
fn test_cstring() {
w := c'world'
hlen := C.strlen(c'hello')