Browse Source

* various fixes for tracking the stack and correctly loading the child node values to the stack, as well as setting the result location

git-svn-id: branches/wasm@48069 -
nickysn 4 years ago
parent
commit
28a7f25f4c
2 changed files with 12 additions and 4 deletions
  1. 10 4
      compiler/wasm32/nwasmadd.pas
  2. 2 0
      compiler/wasm32/nwasmflw.pas

+ 10 - 4
compiler/wasm32/nwasmadd.pas

@@ -261,6 +261,8 @@ interface
             (nf_short_bool in flags)) then
         begin
           secondpass(left);
+          thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
+
           current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i32])));
           thlcgwasm(hlcg).incblock;
           thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
@@ -271,6 +273,7 @@ interface
                    // inside of IF (the condition evaluated as true)
                    // for "and" must evaluate the right section
                    secondpass(right);
+                   thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,right.resultdef,right.location);
 
                    current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_else) );
                    thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
@@ -279,8 +282,6 @@ interface
                    // for "and" must end evaluation immediately
                    current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i32_const, 0) );
                    thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
-                   current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_end_if) );
-                   thlcgwasm(hlcg).decblock;
                 end;
               orn :
                 begin
@@ -296,12 +297,15 @@ interface
                    secondpass(right);
                    // inside of ELSE (the condition evaluated as false)
                    // for "and" must end evaluation immediately
-                   current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_end_if) );
-                   thlcgwasm(hlcg).decblock;
+                   thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,right.resultdef,right.location);
                 end;
               else
                 Internalerror(2019091902);
               end;
+          current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_end_if) );
+          thlcgwasm(hlcg).decblock;
+          set_result_location_reg;
+          thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
         end else
           inherited;
       end;
@@ -341,6 +345,8 @@ interface
           else
             internalerror(2011010413);
         end;
+        set_result_location_reg;
+        thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
       end;
 
 begin

+ 2 - 0
compiler/wasm32/nwasmflw.pas

@@ -67,6 +67,7 @@ uses
 procedure twasmwhilerepeatnode.pass_generate_code_condition;
 begin
   secondpass(left);
+  thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
 
   // reversing the condition
   if not (lnf_checknegate in loopflags) then
@@ -160,6 +161,7 @@ begin
   //todo: MOVE all current_asm_data actions to Wasm HL CodeGen
 
   secondpass(left); // condition exprssions
+  thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
 
   current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if));
   thlcgwasm(hlcg).incblock;