Files
Viper_RegressionTesting/G4/App/caller1.vp
T

41 lines
1.1 KiB
Plaintext

import t
import stdio
import stdlib
import memhub
from g4node import G4Node, new_g4node
# ============================================================
# caller1: import G4Node and access the Next field directly (no accessor).
# Direct n.Next access emits a GEP; a missing stub field makes it out of bounds.
# ============================================================
def caller1_make_chain(pool: memhub.MemBuddy*) -> G4Node*:
"""Create a 3-node chain, accessing Next directly."""
a: G4Node* = new_g4node(pool)
b: G4Node* = new_g4node(pool)
c: G4Node* = new_g4node(pool)
if a is None or b is None or c is None:
return None
a.IntVal = 100
b.IntVal = 200
c.IntVal = 300
# Access Next directly (bypass g4node_set_next).
a.Next = b
b.Next = c
return a
def caller1_sum_chain(head: G4Node*) -> int:
"""Sum the chain by walking Next directly."""
if head is None:
return 0
total: int = int(head.IntVal)
cur: G4Node* = head
# Access Next directly (bypass g4node_get_next).
while cur.Next is not None:
cur = cur.Next
total = total + int(cur.IntVal)
return total