Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Medium] Nested foreach #95

Closed
ShreyanJabade opened this issue Jul 1, 2021 · 1 comment
Closed

[Medium] Nested foreach #95

ShreyanJabade opened this issue Jul 1, 2021 · 1 comment

Comments

@ShreyanJabade
Copy link

Hello,
All the individual blocks are working perfectly now. Thank you for your consideration. I further tried stacking multiple features together. In the example below, there are nested foreach loops which gives an "'expr' object has no attribute '_int_field_info'" syntactical error.
I request you to look into this aspect.
Thank you

import vsc 
from vsc import *
import random
# random.seed(3)

level_list = [('level_'+str(level), auto()) for level in range(3)]
level_e = Enum('level', dict(level_list))

@vsc.randobj
class Parent:
    def __init__(self):
        self.id = 0
        self.c1 = vsc.rand_list_t(vsc.attr(Child1()))
        for i in range(10):    
            self.c1.append(vsc.attr(Child1()))

        self.c2 = vsc.rand_list_t(vsc.attr(Child2()))
        for i in range(10):
            self.c2.append(vsc.attr(Child2()))

        self.val = vsc.rand_uint16_t(5)

    @vsc.constraint
    def enum_inter_class(self):
        with vsc.foreach(self.c1, idx=True) as i:       
            with vsc.foreach(self.c1[i].a, idx=True) as j:
                with vsc.if_then(self.c1[i].a[0].enum_test == level_e.level_0):
                    self.c2[i].x[0].value == 0
                
                with vsc.else_if(self.c1[i].a[0].enum_test == level_e.level_1):
                    self.c2[i].x[0].value == 1

                with vsc.else_then:
                    self.c2[i].x[0].value == 2
        
@vsc.randobj
class Field():
    def __init__(self, name, def_value):
        self.name = name
        self.enum_test = vsc.rand_enum_t(level_e)
        self.value = vsc.rand_uint8_t(def_value)


@vsc.randobj
class Child1:
    def __init__(self):
        self.a = vsc.rand_list_t(vsc.attr(Field('a', 10)))
        for i in range(5):    
            self.a.append(vsc.attr(Field('a', 10)))

        self.b = vsc.rand_list_t(vsc.attr(Field('b', 10)))
        for i in range(5):    
            self.b.append(vsc.attr(Field('b', 10)))

        #self.enum_test = vsc.rand_enum_t(level_e)

    @vsc.constraint
    def test_c(self):
        self.a[0].value < self.a[1].value

@vsc.randobj
class Child2:
    def __init__(self):
        self.x = vsc.rand_list_t(vsc.attr(Field('x', 10)))
        for i in range(5):    
            self.x.append(vsc.attr(Field('x', 10)))

        self.y = vsc.rand_list_t(vsc.attr(Field('y', 10)))
        for i in range(5):    
            self.y.append(vsc.attr(Field('y', 10)))
    
    @vsc.constraint
    def test_c(self):
        self.x[0].value < self.x[1].value

inst=Parent()
inst.randomize()

for i in range(10):
    inst.randomize()
    print(inst.c1[0].a[0].enum_test)
    print(inst.c2[0].x[0].value)
    print()
    print(inst.c1[1].a[0].enum_test)
    print(inst.c2[1].x[0].value)
    #print(inst.val)
    print()
mballance added a commit that referenced this issue Jul 5, 2021
- (#95) Correct issues with multi-level nested foreach constraint

Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
@mballance
Copy link
Member

Hi @ShreyanJabade,
This issue has been corrected in the 0.4.8 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants