v2: process unsafe statements
							parent
							
								
									b1ea908b3b
								
							
						
					
					
						commit
						70f085be18
					
				| 
						 | 
				
			
			@ -13,10 +13,10 @@ FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | Selecto
 | 
			
		|||
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr | 	
 | 
			
		||||
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit
 | 
			
		||||
 | 
			
		||||
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 | 	
 | 
			
		||||
LineComment | MultiLineComment | AssertStmt
 | 
			
		||||
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 |
 | 
			
		||||
LineComment | MultiLineComment | AssertStmt | UnsafeStmt
 | 
			
		||||
 | 
			
		||||
pub type Type = StructType | ArrayType
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -421,6 +421,11 @@ pub:
 | 
			
		|||
	stmts []Stmt
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct UnsafeStmt {
 | 
			
		||||
pub:
 | 
			
		||||
	stmts []Stmt
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct AssignExpr {
 | 
			
		||||
pub:
 | 
			
		||||
	op   token.Kind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -191,6 +191,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
 | 
			
		|||
		ast.StructDecl {
 | 
			
		||||
			f.struct_decl(it)
 | 
			
		||||
		}
 | 
			
		||||
		ast.UnsafeStmt {
 | 
			
		||||
			f.writeln('unsafe {')
 | 
			
		||||
			f.stmts(it.stmts)
 | 
			
		||||
			f.writeln('}')
 | 
			
		||||
		}
 | 
			
		||||
		ast.VarDecl {
 | 
			
		||||
			// type_sym := f.table.get_type_symbol(it.typ)
 | 
			
		||||
			if it.is_mut {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,3 +118,9 @@ fn fn_with_assign_stmts() {
 | 
			
		|||
fn fn_with_multi_return() (int, string) {
 | 
			
		||||
	return 0, 'test'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn unsafe_fn() {
 | 
			
		||||
	unsafe {
 | 
			
		||||
		malloc(2)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -123,3 +123,6 @@ fn fn_with_multi_return() (int,string) {
 | 
			
		|||
	return 0,'test'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn unsafe_fn() {
 | 
			
		||||
unsafe { malloc(2) }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -291,8 +291,10 @@ pub fn (p mut Parser) stmt() ast.Stmt {
 | 
			
		|||
		}
 | 
			
		||||
		.key_unsafe {
 | 
			
		||||
			p.next()
 | 
			
		||||
			p.parse_block()
 | 
			
		||||
			return ast.Stmt{}
 | 
			
		||||
			stmts := p.parse_block()
 | 
			
		||||
			return ast.UnsafeStmt{
 | 
			
		||||
				stmts: stmts
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		.key_defer {
 | 
			
		||||
			p.next()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue