2020-01-23 23:04:46 +03:00
|
|
|
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
2019-12-22 04:34:37 +03:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module ast
|
|
|
|
|
|
|
|
import (
|
2019-12-27 07:43:17 +03:00
|
|
|
v.token
|
2020-01-22 23:34:38 +03:00
|
|
|
v.table
|
2019-12-22 04:34:37 +03:00
|
|
|
)
|
|
|
|
|
2020-03-06 15:43:22 +03:00
|
|
|
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
|
|
|
|
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
|
|
|
|
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
|
|
|
|
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | IfGuardExpr | ParExpr | OrExpr |
|
2020-03-03 17:06:21 +03:00
|
|
|
ConcatExpr | Type | AsCast
|
2019-12-28 16:11:05 +03:00
|
|
|
|
2020-03-06 15:43:22 +03:00
|
|
|
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
|
|
|
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
|
|
|
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
|
2020-02-26 22:45:03 +03:00
|
|
|
LineComment | MultiLineComment | AssertStmt | UnsafeStmt
|
2020-03-03 17:06:21 +03:00
|
|
|
// pub type Type = StructType | ArrayType
|
|
|
|
// pub struct StructType {
|
2020-03-04 17:48:43 +03:00
|
|
|
// fields []Field
|
2020-03-03 17:06:21 +03:00
|
|
|
// }
|
|
|
|
// pub struct ArrayType {}
|
|
|
|
pub struct Type {
|
2020-03-02 12:53:38 +03:00
|
|
|
pub:
|
2020-03-04 17:48:43 +03:00
|
|
|
typ table.Type
|
2020-03-02 12:53:38 +03:00
|
|
|
}
|
|
|
|
|
2020-01-06 18:13:12 +03:00
|
|
|
// | IncDecStmt k
|
2019-12-28 16:11:05 +03:00
|
|
|
// Stand-alone expression in a statement list.
|
|
|
|
pub struct ExprStmt {
|
|
|
|
pub:
|
|
|
|
expr Expr
|
2020-02-10 10:32:08 +03:00
|
|
|
typ table.Type
|
2019-12-28 16:11:05 +03:00
|
|
|
}
|
2019-12-22 04:34:37 +03:00
|
|
|
|
2019-12-26 13:21:41 +03:00
|
|
|
pub struct IntegerLiteral {
|
2019-12-26 05:40:18 +03:00
|
|
|
pub:
|
|
|
|
val int
|
|
|
|
}
|
2019-12-24 20:54:43 +03:00
|
|
|
|
2019-12-27 12:03:29 +03:00
|
|
|
pub struct FloatLiteral {
|
|
|
|
pub:
|
2019-12-28 11:43:22 +03:00
|
|
|
// val f64
|
2019-12-27 12:03:29 +03:00
|
|
|
val string
|
|
|
|
}
|
|
|
|
|
2019-12-24 20:54:43 +03:00
|
|
|
pub struct StringLiteral {
|
|
|
|
pub:
|
|
|
|
val string
|
|
|
|
}
|
2019-12-22 04:34:37 +03:00
|
|
|
|
2020-02-04 11:54:15 +03:00
|
|
|
pub struct CharLiteral {
|
|
|
|
pub:
|
|
|
|
val string
|
|
|
|
}
|
|
|
|
|
2019-12-29 10:51:55 +03:00
|
|
|
pub struct BoolLiteral {
|
|
|
|
pub:
|
|
|
|
val bool
|
|
|
|
}
|
|
|
|
|
2020-01-02 22:09:15 +03:00
|
|
|
// `foo.bar`
|
|
|
|
pub struct SelectorExpr {
|
|
|
|
pub:
|
2020-01-19 01:26:14 +03:00
|
|
|
pos token.Position
|
2020-01-02 22:09:15 +03:00
|
|
|
expr Expr
|
|
|
|
field string
|
|
|
|
}
|
|
|
|
|
2019-12-28 13:02:06 +03:00
|
|
|
// module declaration
|
2019-12-28 11:15:32 +03:00
|
|
|
pub struct Module {
|
|
|
|
pub:
|
2019-12-28 11:43:22 +03:00
|
|
|
name string
|
|
|
|
path string
|
|
|
|
expr Expr
|
2019-12-28 11:15:32 +03:00
|
|
|
}
|
|
|
|
|
2019-12-30 08:16:59 +03:00
|
|
|
pub struct Field {
|
|
|
|
pub:
|
|
|
|
name string
|
2020-01-19 01:26:14 +03:00
|
|
|
// type_idx int
|
2020-02-15 15:37:48 +03:00
|
|
|
mut:
|
2020-02-10 10:32:08 +03:00
|
|
|
typ table.Type
|
2020-02-18 00:50:04 +03:00
|
|
|
// typ2 Type
|
2020-02-03 09:02:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ConstDecl {
|
|
|
|
pub:
|
|
|
|
fields []Field
|
|
|
|
exprs []Expr
|
2020-02-27 00:43:37 +03:00
|
|
|
is_pub bool
|
2019-12-30 08:16:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct StructDecl {
|
|
|
|
pub:
|
2020-02-22 16:13:19 +03:00
|
|
|
pos token.Position
|
|
|
|
name string
|
|
|
|
fields []Field
|
|
|
|
is_pub bool
|
|
|
|
mut_pos int // mut:
|
|
|
|
pub_pos int // pub:
|
|
|
|
pub_mut_pos int // pub mut:
|
2019-12-30 08:16:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct StructInit {
|
|
|
|
pub:
|
2020-01-19 01:26:14 +03:00
|
|
|
pos token.Position
|
2020-02-10 10:32:08 +03:00
|
|
|
typ table.Type
|
2019-12-30 08:16:59 +03:00
|
|
|
fields []string
|
|
|
|
exprs []Expr
|
|
|
|
}
|
|
|
|
|
2019-12-28 11:15:32 +03:00
|
|
|
// import statement
|
|
|
|
pub struct Import {
|
|
|
|
pub:
|
2020-01-19 01:26:14 +03:00
|
|
|
pos token.Position
|
|
|
|
mod string
|
|
|
|
alias string
|
2019-12-31 21:42:16 +03:00
|
|
|
// expr Expr
|
2019-12-28 11:15:32 +03:00
|
|
|
}
|
|
|
|
|
2019-12-29 09:24:17 +03:00
|
|
|
pub struct Arg {
|
|
|
|
pub:
|
2020-02-10 10:32:08 +03:00
|
|
|
typ table.Type
|
2019-12-29 09:24:17 +03:00
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2019-12-27 15:57:49 +03:00
|
|
|
pub struct FnDecl {
|
|
|
|
pub:
|
2020-03-05 18:13:14 +03:00
|
|
|
name string
|
|
|
|
stmts []Stmt
|
|
|
|
typ table.Type
|
|
|
|
args []Arg
|
|
|
|
is_deprecated bool
|
|
|
|
is_pub bool
|
|
|
|
is_variadic bool
|
|
|
|
receiver Field
|
|
|
|
is_method bool
|
|
|
|
rec_mut bool // is receiver mutable
|
|
|
|
is_c bool
|
2020-03-06 18:31:40 +03:00
|
|
|
no_body bool // just a definition `fn C.malloc()`
|
2019-12-29 09:24:17 +03:00
|
|
|
}
|
|
|
|
|
2020-02-04 10:29:50 +03:00
|
|
|
pub struct BranchStmt {
|
|
|
|
pub:
|
|
|
|
tok token.Token
|
|
|
|
}
|
|
|
|
|
2019-12-29 09:24:17 +03:00
|
|
|
pub struct CallExpr {
|
|
|
|
pub:
|
2020-01-22 23:34:38 +03:00
|
|
|
// tok token.Token
|
2020-03-01 15:07:51 +03:00
|
|
|
pos token.Position
|
2020-01-19 01:26:14 +03:00
|
|
|
mut:
|
2020-01-22 23:34:38 +03:00
|
|
|
// func Expr
|
2020-03-01 15:07:51 +03:00
|
|
|
name string
|
|
|
|
args []Expr
|
|
|
|
is_c bool
|
|
|
|
muts []bool
|
2020-02-29 17:03:32 +03:00
|
|
|
or_block OrExpr
|
2020-01-07 03:08:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct MethodCallExpr {
|
|
|
|
pub:
|
2020-01-22 23:34:38 +03:00
|
|
|
// tok token.Token
|
2020-02-28 17:36:41 +03:00
|
|
|
pos token.Position
|
|
|
|
expr Expr
|
|
|
|
name string
|
|
|
|
args []Expr
|
|
|
|
muts []bool
|
|
|
|
or_block OrExpr
|
2020-03-06 12:52:03 +03:00
|
|
|
mut:
|
2020-03-01 15:07:51 +03:00
|
|
|
typ table.Type
|
2019-12-27 15:57:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Return {
|
|
|
|
pub:
|
2020-03-06 15:43:22 +03:00
|
|
|
pos token.Position
|
|
|
|
exprs []Expr
|
2019-12-27 15:57:49 +03:00
|
|
|
}
|
|
|
|
|
2019-12-22 04:34:37 +03:00
|
|
|
/*
|
|
|
|
pub enum Expr {
|
2020-01-22 23:34:38 +03:00
|
|
|
Binary(InfixExpr)
|
2019-12-22 04:34:37 +03:00
|
|
|
If(IfExpr)
|
|
|
|
Integer(IntegerExpr)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-12-24 20:54:43 +03:00
|
|
|
/*
|
2019-12-22 04:34:37 +03:00
|
|
|
pub struct Stmt {
|
|
|
|
pos int
|
|
|
|
//end int
|
|
|
|
}
|
2019-12-24 20:54:43 +03:00
|
|
|
*/
|
|
|
|
|
2019-12-28 11:43:22 +03:00
|
|
|
|
2019-12-24 20:54:43 +03:00
|
|
|
pub struct VarDecl {
|
|
|
|
pub:
|
2020-01-22 23:34:38 +03:00
|
|
|
name string
|
2020-02-27 23:51:40 +03:00
|
|
|
name2 string // TODO
|
2020-01-22 23:34:38 +03:00
|
|
|
expr Expr
|
2020-01-19 01:26:14 +03:00
|
|
|
is_mut bool
|
2020-01-22 23:34:38 +03:00
|
|
|
mut:
|
2020-02-10 10:32:08 +03:00
|
|
|
typ table.Type
|
2020-01-22 23:34:38 +03:00
|
|
|
pos token.Position
|
2019-12-24 20:54:43 +03:00
|
|
|
}
|
|
|
|
|
2020-02-03 09:02:54 +03:00
|
|
|
pub struct GlobalDecl {
|
|
|
|
pub:
|
|
|
|
name string
|
|
|
|
expr Expr
|
|
|
|
mut:
|
2020-02-10 10:32:08 +03:00
|
|
|
typ table.Type
|
2020-02-03 09:02:54 +03:00
|
|
|
}
|
|
|
|
|
2019-12-30 14:10:46 +03:00
|
|
|
pub struct File {
|
2019-12-24 20:54:43 +03:00
|
|
|
pub:
|
2020-02-18 00:50:04 +03:00
|
|
|
path string
|
|
|
|
mod Module
|
|
|
|
imports []Import
|
|
|
|
stmts []Stmt
|
2020-02-20 13:13:18 +03:00
|
|
|
scope &Scope
|
2020-02-17 14:25:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct IdentFunc {
|
|
|
|
pub mut:
|
|
|
|
return_type table.Type
|
2020-01-19 01:26:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct IdentVar {
|
2020-02-06 15:57:35 +03:00
|
|
|
pub mut:
|
2020-02-28 15:29:04 +03:00
|
|
|
typ table.Type
|
|
|
|
is_mut bool
|
|
|
|
is_static bool
|
2020-01-19 01:26:14 +03:00
|
|
|
}
|
|
|
|
|
2020-03-05 16:16:08 +03:00
|
|
|
pub type IdentInfo = IdentFunc | IdentVar
|
2020-01-19 01:26:14 +03:00
|
|
|
|
|
|
|
pub enum IdentKind {
|
2020-02-17 14:25:18 +03:00
|
|
|
unresolved
|
2020-01-19 01:26:14 +03:00
|
|
|
blank_ident
|
|
|
|
variable
|
2020-02-03 09:02:54 +03:00
|
|
|
constant
|
2020-02-17 14:25:18 +03:00
|
|
|
function
|
2019-12-24 20:54:43 +03:00
|
|
|
}
|
2019-12-28 16:11:05 +03:00
|
|
|
|
2019-12-22 04:34:37 +03:00
|
|
|
// A single identifier
|
2019-12-28 16:11:05 +03:00
|
|
|
pub struct Ident {
|
|
|
|
pub:
|
2020-02-10 10:32:08 +03:00
|
|
|
value string
|
|
|
|
is_c bool
|
2019-12-31 12:53:30 +03:00
|
|
|
tok_kind token.Kind
|
2020-01-19 01:26:14 +03:00
|
|
|
pos token.Position
|
|
|
|
mut:
|
2020-03-06 02:10:01 +03:00
|
|
|
name string
|
2020-01-19 01:26:14 +03:00
|
|
|
kind IdentKind
|
|
|
|
info IdentInfo
|
2019-12-22 04:34:37 +03:00
|
|
|
}
|
|
|
|
|
2020-02-07 16:49:14 +03:00
|
|
|
pub fn (i &Ident) var_info() IdentVar {
|
2020-02-06 19:38:02 +03:00
|
|
|
match i.info {
|
|
|
|
IdentVar {
|
|
|
|
return it
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// return IdentVar{}
|
|
|
|
panic('Ident.var_info(): info is not IdentVar variant')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:34:38 +03:00
|
|
|
pub struct InfixExpr {
|
2019-12-22 04:34:37 +03:00
|
|
|
pub:
|
2019-12-28 21:16:04 +03:00
|
|
|
// op BinaryOp
|
2020-01-22 23:34:38 +03:00
|
|
|
op token.Kind
|
|
|
|
pos token.Position
|
|
|
|
left Expr
|
2020-02-10 10:32:08 +03:00
|
|
|
left_type table.Type
|
2020-01-22 23:34:38 +03:00
|
|
|
right Expr
|
2020-02-10 10:32:08 +03:00
|
|
|
right_type table.Type
|
2019-12-22 04:34:37 +03:00
|
|
|
}
|
|
|
|
|
2020-01-22 23:34:38 +03:00
|
|
|
/*
|
|
|
|
// renamed to PrefixExpr
|
2019-12-25 15:39:58 +03:00
|
|
|
pub struct UnaryExpr {
|
|
|
|
pub:
|
2019-12-31 12:53:30 +03:00
|
|
|
// tok_kind token.Kind
|
2019-12-28 11:43:22 +03:00
|
|
|
// op BinaryOp
|
2019-12-31 12:53:30 +03:00
|
|
|
op token.Kind
|
2019-12-28 11:43:22 +03:00
|
|
|
left Expr
|
2019-12-25 15:39:58 +03:00
|
|
|
}
|
2020-01-22 23:34:38 +03:00
|
|
|
*/
|
|
|
|
|
2020-02-07 16:49:14 +03:00
|
|
|
|
2020-01-06 18:13:12 +03:00
|
|
|
pub struct PostfixExpr {
|
|
|
|
pub:
|
|
|
|
op token.Kind
|
|
|
|
expr Expr
|
2020-02-04 09:37:38 +03:00
|
|
|
pos token.Position
|
2020-01-06 18:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct PrefixExpr {
|
|
|
|
pub:
|
|
|
|
op token.Kind
|
|
|
|
right Expr
|
|
|
|
}
|
|
|
|
|
2020-01-07 14:14:10 +03:00
|
|
|
pub struct IndexExpr {
|
|
|
|
pub:
|
|
|
|
// op token.Kind
|
2020-02-03 09:44:52 +03:00
|
|
|
pos token.Position
|
2020-01-07 14:14:10 +03:00
|
|
|
left Expr
|
2020-01-22 23:34:38 +03:00
|
|
|
index Expr // [0], [start..end] etc
|
2020-02-03 13:29:50 +03:00
|
|
|
// typ table.Type
|
2020-01-07 14:14:10 +03:00
|
|
|
}
|
|
|
|
|
2019-12-28 21:16:04 +03:00
|
|
|
pub struct IfExpr {
|
2019-12-29 10:51:55 +03:00
|
|
|
pub:
|
2020-01-02 00:34:46 +03:00
|
|
|
tok_kind token.Kind
|
|
|
|
cond Expr
|
|
|
|
stmts []Stmt
|
2019-12-31 21:42:16 +03:00
|
|
|
else_stmts []Stmt
|
2020-01-02 22:09:15 +03:00
|
|
|
left Expr // `a` in `a := if ...`
|
2020-02-03 09:02:54 +03:00
|
|
|
pos token.Position
|
2020-02-15 15:37:48 +03:00
|
|
|
mut:
|
|
|
|
typ table.Type
|
2020-02-22 18:59:50 +03:00
|
|
|
has_else bool
|
2020-02-03 09:02:54 +03:00
|
|
|
}
|
|
|
|
|
2020-02-05 12:00:11 +03:00
|
|
|
pub struct MatchExpr {
|
|
|
|
pub:
|
2020-03-04 17:48:43 +03:00
|
|
|
tok_kind token.Kind
|
|
|
|
cond Expr
|
|
|
|
branches []MatchBranch
|
|
|
|
pos token.Position
|
2020-02-15 15:37:48 +03:00
|
|
|
mut:
|
2020-03-04 17:48:43 +03:00
|
|
|
expr_type table.Type // type of `x` in `match x {`
|
2020-02-05 12:00:11 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 13:59:45 +03:00
|
|
|
pub struct MatchBranch {
|
|
|
|
pub:
|
|
|
|
exprs []Expr
|
|
|
|
stmts []Stmt
|
|
|
|
pos token.Position
|
|
|
|
}
|
|
|
|
|
2020-02-03 09:02:54 +03:00
|
|
|
pub struct CompIf {
|
|
|
|
pub:
|
|
|
|
cond Expr
|
|
|
|
stmts []Stmt
|
|
|
|
else_stmts []Stmt
|
2019-12-22 04:34:37 +03:00
|
|
|
}
|
|
|
|
|
2019-12-30 08:16:59 +03:00
|
|
|
pub struct ForStmt {
|
|
|
|
pub:
|
2020-02-19 13:06:36 +03:00
|
|
|
cond Expr
|
|
|
|
stmts []Stmt
|
|
|
|
pos token.Position
|
|
|
|
is_inf bool // `for {}`
|
2020-01-07 02:14:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ForInStmt {
|
|
|
|
pub:
|
2020-02-28 17:36:41 +03:00
|
|
|
key_var string
|
|
|
|
val_var string
|
|
|
|
cond Expr
|
|
|
|
is_range bool
|
|
|
|
high Expr // `10` in `for i in 0..10 {`
|
|
|
|
stmts []Stmt
|
|
|
|
pos token.Position
|
2020-01-07 02:14:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ForCStmt {
|
|
|
|
pub:
|
|
|
|
init Stmt // i := 0;
|
|
|
|
cond Expr // i < 10;
|
2020-03-06 15:43:22 +03:00
|
|
|
// inc Stmt // i++;
|
|
|
|
inc Expr // i++;
|
2020-01-07 02:14:19 +03:00
|
|
|
stmts []Stmt
|
2019-12-30 08:16:59 +03:00
|
|
|
}
|
|
|
|
|
2019-12-28 21:16:04 +03:00
|
|
|
pub struct ReturnStmt {
|
2019-12-31 12:53:30 +03:00
|
|
|
tok_kind token.Kind // or pos
|
2020-01-22 23:34:38 +03:00
|
|
|
pos token.Position
|
2019-12-28 11:43:22 +03:00
|
|
|
results []Expr
|
2019-12-22 04:34:37 +03:00
|
|
|
}
|
|
|
|
|
2020-02-04 11:54:15 +03:00
|
|
|
// #include etc
|
|
|
|
pub struct HashStmt {
|
|
|
|
pub:
|
2020-03-05 02:43:02 +03:00
|
|
|
val string
|
2020-02-04 11:54:15 +03:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:42:57 +03:00
|
|
|
// filter(), map()
|
|
|
|
pub struct Lambda {
|
|
|
|
pub:
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2019-12-28 21:16:04 +03:00
|
|
|
pub struct AssignStmt {
|
|
|
|
pub:
|
2020-02-06 19:38:02 +03:00
|
|
|
left []Ident
|
|
|
|
right []Expr
|
2019-12-31 12:53:30 +03:00
|
|
|
op token.Kind
|
2020-02-27 13:12:30 +03:00
|
|
|
pos token.Position
|
2019-12-28 21:16:04 +03:00
|
|
|
}
|
2020-02-06 19:38:02 +03:00
|
|
|
|
2020-03-02 21:00:33 +03:00
|
|
|
pub struct AsCast {
|
|
|
|
pub:
|
|
|
|
typ table.Type
|
|
|
|
}
|
|
|
|
|
2020-02-03 09:02:54 +03:00
|
|
|
// e.g. `[unsafe_fn]`
|
|
|
|
pub struct Attr {
|
|
|
|
pub:
|
|
|
|
name string
|
|
|
|
}
|
2019-12-28 21:16:04 +03:00
|
|
|
|
2020-02-11 01:19:50 +03:00
|
|
|
pub struct EnumVal {
|
2020-02-10 22:33:34 +03:00
|
|
|
pub:
|
2020-02-25 17:02:34 +03:00
|
|
|
enum_name string
|
|
|
|
val string
|
|
|
|
pos token.Position
|
|
|
|
// name string
|
2020-02-11 01:19:50 +03:00
|
|
|
}
|
2020-02-10 22:33:34 +03:00
|
|
|
|
2020-02-11 01:19:50 +03:00
|
|
|
pub struct EnumDecl {
|
|
|
|
pub:
|
|
|
|
name string
|
|
|
|
is_pub bool
|
|
|
|
vals []string
|
|
|
|
}
|
|
|
|
|
2020-02-18 00:50:04 +03:00
|
|
|
pub struct TypeDecl {
|
2020-02-11 01:19:50 +03:00
|
|
|
pub:
|
|
|
|
name string
|
|
|
|
is_pub bool
|
2020-02-10 22:33:34 +03:00
|
|
|
}
|
|
|
|
|
2020-02-18 00:50:04 +03:00
|
|
|
pub struct DeferStmt {
|
2020-02-11 12:26:46 +03:00
|
|
|
pub:
|
2020-02-18 00:50:04 +03:00
|
|
|
stmts []Stmt
|
2020-02-11 12:26:46 +03:00
|
|
|
}
|
|
|
|
|
2020-02-26 22:45:03 +03:00
|
|
|
pub struct UnsafeStmt {
|
|
|
|
pub:
|
|
|
|
stmts []Stmt
|
|
|
|
}
|
|
|
|
|
2020-02-28 16:41:19 +03:00
|
|
|
// `(3+4)`
|
|
|
|
pub struct ParExpr {
|
|
|
|
pub:
|
|
|
|
expr Expr
|
|
|
|
}
|
|
|
|
|
2020-01-06 18:13:12 +03:00
|
|
|
pub struct AssignExpr {
|
|
|
|
pub:
|
2020-01-19 01:26:14 +03:00
|
|
|
op token.Kind
|
|
|
|
pos token.Position
|
2020-01-06 18:13:12 +03:00
|
|
|
left Expr
|
|
|
|
val Expr
|
|
|
|
}
|
|
|
|
|
2020-02-18 00:50:04 +03:00
|
|
|
pub struct GotoLabel {
|
2020-02-17 16:15:42 +03:00
|
|
|
pub:
|
2020-02-18 00:50:04 +03:00
|
|
|
name string
|
2020-02-17 16:15:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct GotoStmt {
|
|
|
|
pub:
|
2020-02-18 00:50:04 +03:00
|
|
|
name string
|
2020-02-17 16:15:42 +03:00
|
|
|
}
|
|
|
|
|
2019-12-30 11:38:12 +03:00
|
|
|
pub struct ArrayInit {
|
|
|
|
pub:
|
2020-03-04 17:48:43 +03:00
|
|
|
pos token.Position
|
|
|
|
exprs []Expr
|
2020-02-06 15:57:35 +03:00
|
|
|
mut:
|
2020-03-04 04:50:32 +03:00
|
|
|
elem_type table.Type
|
2020-03-04 17:48:43 +03:00
|
|
|
typ table.Type
|
2019-12-30 11:38:12 +03:00
|
|
|
}
|
|
|
|
|
2020-02-22 16:13:19 +03:00
|
|
|
pub struct MapInit {
|
|
|
|
pub:
|
|
|
|
pos token.Position
|
|
|
|
keys []Expr
|
|
|
|
vals []Expr
|
|
|
|
mut:
|
|
|
|
typ table.Type
|
|
|
|
}
|
|
|
|
|
2020-02-02 16:31:54 +03:00
|
|
|
// s[10..20]
|
|
|
|
pub struct RangeExpr {
|
|
|
|
pub:
|
|
|
|
low Expr
|
|
|
|
high Expr
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:43:17 +03:00
|
|
|
pub struct CastExpr {
|
|
|
|
pub:
|
|
|
|
typ table.Type
|
|
|
|
expr Expr
|
|
|
|
}
|
|
|
|
|
2020-02-26 17:51:05 +03:00
|
|
|
pub struct AssertStmt {
|
|
|
|
pub:
|
|
|
|
expr Expr
|
|
|
|
}
|
|
|
|
|
2020-02-28 17:36:41 +03:00
|
|
|
// `if [x := opt()] {`
|
|
|
|
pub struct IfGuardExpr {
|
2020-02-27 20:02:40 +03:00
|
|
|
pub:
|
|
|
|
var_name string
|
|
|
|
expr Expr
|
|
|
|
}
|
|
|
|
|
2020-02-28 17:36:41 +03:00
|
|
|
// `or { ... }`
|
|
|
|
pub struct OrExpr {
|
|
|
|
pub:
|
|
|
|
stmts []Stmt
|
|
|
|
// var_name string
|
|
|
|
// expr Expr
|
|
|
|
}
|
|
|
|
|
2020-02-18 19:29:47 +03:00
|
|
|
pub struct Assoc {
|
|
|
|
pub:
|
2020-03-01 15:07:51 +03:00
|
|
|
var_name string
|
|
|
|
fields []string
|
|
|
|
exprs []Expr
|
|
|
|
pos token.Position
|
2020-02-18 19:29:47 +03:00
|
|
|
}
|
|
|
|
|
2020-02-18 20:13:34 +03:00
|
|
|
pub struct SizeOf {
|
|
|
|
pub:
|
|
|
|
type_name string
|
|
|
|
}
|
|
|
|
|
2020-02-18 22:20:15 +03:00
|
|
|
pub struct LineComment {
|
|
|
|
pub:
|
|
|
|
text string
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct MultiLineComment {
|
|
|
|
pub:
|
|
|
|
text string
|
|
|
|
}
|
|
|
|
|
2020-03-01 16:57:54 +03:00
|
|
|
pub struct ConcatExpr {
|
|
|
|
pub:
|
|
|
|
vals []Expr
|
|
|
|
}
|
|
|
|
|
2020-02-19 21:54:36 +03:00
|
|
|
pub struct None {
|
|
|
|
pub:
|
|
|
|
foo int // todo
|
|
|
|
}
|
2019-12-26 05:40:18 +03:00
|
|
|
/*
|
|
|
|
enum BinaryOp {
|
|
|
|
sum
|
|
|
|
difference
|
|
|
|
product
|
|
|
|
quotient
|
|
|
|
remainder
|
|
|
|
bitwise_and
|
|
|
|
bitwise_or
|
|
|
|
bitwise_xor
|
|
|
|
left_shift
|
|
|
|
right_shift
|
|
|
|
|
|
|
|
equality
|
|
|
|
inequality
|
|
|
|
less_than
|
|
|
|
less_than_or_equal
|
|
|
|
more_than
|
|
|
|
more_than_or_equal
|
|
|
|
|
|
|
|
in_check
|
|
|
|
|
|
|
|
//These are suffixed with `bool` to prevent conflict with the keyword `or`
|
|
|
|
and_bool
|
|
|
|
or_bool
|
|
|
|
}
|
|
|
|
*/
|