@@ -529,7 +529,7 @@ TEST(LLVMCodeAnalyzer_ListTypeAnalysis, ClearAfterWriteInLoop)
529529 appendList->args .push_back ({ Compiler::StaticType::Unknown, &value });
530530 list.addInstruction (appendList);
531531
532- auto loopStart = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginWhileLoop , false );
532+ auto loopStart = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatLoop , false );
533533 list.addInstruction (loopStart);
534534
535535 auto appendList1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::AppendToList, false );
@@ -567,25 +567,38 @@ TEST(LLVMCodeAnalyzer_ListTypeAnalysis, WhileLoop)
567567 appendList->args .push_back ({ Compiler::StaticType::Unknown, &value });
568568 list.addInstruction (appendList);
569569
570+ auto loopCond = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, false );
571+ list.addInstruction (loopCond);
572+
573+ // Read an item in loop condition
574+ auto getItem = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::GetListItem, false );
575+ LLVMConstantRegister index (Compiler::StaticType::Number, 0 );
576+ getItem->targetList = &targetList;
577+ getItem->args .push_back ({ Compiler::StaticType::Number, &index });
578+ list.addInstruction (getItem);
579+
580+ LLVMRegister sourceValue (Compiler::StaticType::Unknown);
581+ sourceValue.isRawValue = false ;
582+ sourceValue.instruction = getItem;
583+ getItem->functionReturnReg = &sourceValue;
584+
570585 auto loopStart = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginWhileLoop, false );
571586 list.addInstruction (loopStart);
572587
588+ // Change the type in the loop
573589 auto appendList1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::AppendToList, false );
574590 LLVMConstantRegister value1 (Compiler::StaticType::Number, 5 );
575591 appendList1->targetList = &targetList;
576592 appendList1->args .push_back ({ Compiler::StaticType::Unknown, &value1 });
577593 list.addInstruction (appendList1);
578594
579- auto clearList2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::ClearList, false );
580- clearList2->targetList = &targetList;
581- list.addInstruction (clearList2);
582-
583595 auto loopEnd = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, false );
584596 list.addInstruction (loopEnd);
585597
586598 analyzer.analyzeScript (list);
587599
588- ASSERT_EQ (appendList1->targetType , Compiler::StaticType::Bool);
600+ ASSERT_EQ (getItem->targetType , Compiler::StaticType::Number | Compiler::StaticType::Bool);
601+ ASSERT_EQ (appendList1->targetType , Compiler::StaticType::Number | Compiler::StaticType::Bool);
589602}
590603
591604TEST (LLVMCodeAnalyzer_ListTypeAnalysis, RepeatUntilLoop)
@@ -605,25 +618,38 @@ TEST(LLVMCodeAnalyzer_ListTypeAnalysis, RepeatUntilLoop)
605618 appendList->args .push_back ({ Compiler::StaticType::Unknown, &value });
606619 list.addInstruction (appendList);
607620
621+ auto loopCond = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, false );
622+ list.addInstruction (loopCond);
623+
624+ // Read an item in loop condition
625+ auto getItem = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::GetListItem, false );
626+ LLVMConstantRegister index (Compiler::StaticType::Number, 0 );
627+ getItem->targetList = &targetList;
628+ getItem->args .push_back ({ Compiler::StaticType::Number, &index });
629+ list.addInstruction (getItem);
630+
631+ LLVMRegister sourceValue (Compiler::StaticType::Unknown);
632+ sourceValue.isRawValue = false ;
633+ sourceValue.instruction = getItem;
634+ getItem->functionReturnReg = &sourceValue;
635+
608636 auto loopStart = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatUntilLoop, false );
609637 list.addInstruction (loopStart);
610638
639+ // Change the type in the loop
611640 auto appendList1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::AppendToList, false );
612641 LLVMConstantRegister value1 (Compiler::StaticType::Number, 5 );
613642 appendList1->targetList = &targetList;
614643 appendList1->args .push_back ({ Compiler::StaticType::Unknown, &value1 });
615644 list.addInstruction (appendList1);
616645
617- auto clearList2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::ClearList, false );
618- clearList2->targetList = &targetList;
619- list.addInstruction (clearList2);
620-
621646 auto loopEnd = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, false );
622647 list.addInstruction (loopEnd);
623648
624649 analyzer.analyzeScript (list);
625650
626- ASSERT_EQ (appendList1->targetType , Compiler::StaticType::Bool);
651+ ASSERT_EQ (getItem->targetType , Compiler::StaticType::Number | Compiler::StaticType::Bool);
652+ ASSERT_EQ (appendList1->targetType , Compiler::StaticType::Number | Compiler::StaticType::Bool);
627653}
628654
629655TEST (LLVMCodeAnalyzer_ListTypeAnalysis, LoopMultipleWrites_UnknownType)
0 commit comments