@@ -7,7 +7,7 @@ mod r#while;
77mod judgment;
88mod loop_back;
99
10- use crate :: compiler:: ast:: ssa_ir:: { Code , LocalMap , OpCode , ValueGuessType } ;
10+ use crate :: compiler:: ast:: ssa_ir:: { Code , LocalMap , OpCode , ValueAlloc , ValueGuessType } ;
1111use crate :: compiler:: ast:: ASTStmtTree ;
1212use crate :: compiler:: file:: SourceFile ;
1313use crate :: compiler:: lints:: Lint :: UnusedExpression ;
@@ -38,17 +38,18 @@ impl<'a> Semantic<'a> {
3838 pub fn semantic ( & mut self , stmt_tree : ASTStmtTree ) -> Result < ( Code , LocalMap ) , ParserError > {
3939 let code = & mut Code :: new ( true ) ;
4040 let mut global = LocalMap :: new ( ) ;
41+ let value_alloc = & mut ValueAlloc :: new ( ) ;
4142
4243 if let ASTStmtTree :: Root ( stmts) = stmt_tree {
4344 for stmt in stmts {
4445 match stmt {
4546 ASTStmtTree :: Var { name, value } => {
46- let opcode = var_semantic ( self , name, value, code , true , & mut global) ?;
47+ let opcode = var_semantic ( self , name, value, value_alloc , true , & mut global) ?;
4748 code. get_code_table ( ) . append_code ( & opcode) ;
4849 }
4950 ASTStmtTree :: Expr ( expr) => {
5051 let ref_expr = expr. clone ( ) ;
51- let ret_m = expr_semantic ( self , Some ( expr) , code ) ?;
52+ let ret_m = expr_semantic ( self , Some ( expr) , value_alloc ) ?;
5253 code. get_code_table ( ) . append_code ( & ret_m. 2 ) ;
5354 if !check_expr_operand ( & ret_m. 0 , & OpCode :: Store ( None ) , 0 ) {
5455 Compiler :: warning_info_expr (
@@ -68,15 +69,15 @@ impl<'a> Semantic<'a> {
6869 self . compiler_data ( )
6970 . symbol_table
7071 . add_element ( name, ElementType :: Library ) ;
71- code . alloc_value ( token, ValueGuessType :: Ref ) ;
72+ value_alloc . alloc_value ( token, ValueGuessType :: Ref ) ;
7273 }
7374 ASTStmtTree :: Loop {
7475 token : _token,
7576 cond,
7677 body,
7778 is_easy,
7879 } => {
79- let ret_m = while_semantic ( self , & cond, body, code , & mut global, is_easy) ?;
80+ let ret_m = while_semantic ( self , & cond, body, value_alloc , & mut global, is_easy) ?;
8081 code. get_code_table ( ) . append_code ( & ret_m) ;
8182 }
8283 ASTStmtTree :: Function { name, args, body } => {
@@ -86,7 +87,7 @@ impl<'a> Semantic<'a> {
8687 native_function_semantic ( self , name, & args, code) ?;
8788 }
8889 ASTStmtTree :: If { cond, then_body, else_body} => {
89- let ret_m = judgment_semantic ( self , & cond, then_body, else_body, code , & mut global) ?;
90+ let ret_m = judgment_semantic ( self , & cond, then_body, else_body, value_alloc , & mut global) ?;
9091 code. get_code_table ( ) . append_code ( & ret_m) ;
9192 }
9293 _ => todo ! ( ) ,
0 commit comments