Parser: Support multiple components in one file, change args to params with defaults
This commit is contained in:
1 parent
635d466874
commit
81d51d5617
38 files changed
+2151
-455
No files matched your search
@@ -0,0 +1,82 @@
|
||||
"""Tests for LLVM IR code generation with conditional rendering."""
|
||||
|
||||
import pytest
|
||||
from ritz.parser import parse_component
|
||||
from ritz.llvm_codegen_signals import generate_llvm_ir
|
||||
|
||||
|
||||
def test_if_statement_codegen():
|
||||
"""Test LLVM IR generation for if statement."""
|
||||
source = """
|
||||
from ritz.syntax import *
|
||||
|
||||
@component
|
||||
def Toggle():
|
||||
visible = signal(1)
|
||||
|
||||
if visible:
|
||||
with P():
|
||||
yield "I am visible!"
|
||||
"""
|
||||
ir = parse_component(source)
|
||||
llvm_ir = generate_llvm_ir(ir)
|
||||
|
||||
# Should have signal global
|
||||
assert "@signal_visible = global i32 1" in llvm_ir
|
||||
|
||||
# Should have conditional branch
|
||||
assert "br i1" in llvm_ir
|
||||
|
||||
# Should have basic blocks for then/else/merge
|
||||
assert "if.then." in llvm_ir
|
||||
assert "if.end." in llvm_ir
|
||||
|
||||
|
||||
def test_if_else_codegen():
|
||||
"""Test LLVM IR generation for if/else."""
|
||||
source = """
|
||||
from ritz.syntax import *
|
||||
|
||||
@component
|
||||
def Toggle():
|
||||
visible = signal(1)
|
||||
|
||||
if visible:
|
||||
with P():
|
||||
yield "Shown"
|
||||
else:
|
||||
with P():
|
||||
yield "Hidden"
|
||||
"""
|
||||
ir = parse_component(source)
|
||||
llvm_ir = generate_llvm_ir(ir)
|
||||
|
||||
# Should have conditional branch
|
||||
assert "br i1" in llvm_ir
|
||||
|
||||
# Should have both then and else blocks
|
||||
assert "if.then." in llvm_ir
|
||||
assert "if.else." in llvm_ir
|
||||
|
||||
|
||||
def test_if_comparison_codegen():
|
||||
"""Test LLVM IR generation for if with comparison."""
|
||||
source = """
|
||||
from ritz.syntax import *
|
||||
|
||||
@component
|
||||
def Counter():
|
||||
count = signal(0)
|
||||
|
||||
if count > 5:
|
||||
with P():
|
||||
yield "High count!"
|
||||
"""
|
||||
ir = parse_component(source)
|
||||
llvm_ir = generate_llvm_ir(ir)
|
||||
|
||||
# Should have icmp instruction for comparison
|
||||
assert "icmp" in llvm_ir
|
||||
|
||||
# Should have greater-than comparison (sgt = signed greater than)
|
||||
assert "sgt" in llvm_ir or ">" in llvm_ir
|
||||
Reference in new issue
Block a user