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

Save environment in peak class #27

Open
rdaly525 opened this issue Mar 19, 2019 · 1 comment
Open

Save environment in peak class #27

rdaly525 opened this issue Mar 19, 2019 · 1 comment
Assignees

Comments

@rdaly525
Copy link
Collaborator

Problem:

We are writing code like the following which uses the family closure to generate types, Instructions, and other local objects. When we call family generator, we lose (easy) access to the generated locals, as the closure only returns the peak class.

def gen_pe(family):
  alu = gen_alu(family)
  Bit = family.Bit
  Data = family.BitVector
  Inst = gen_inst(family)
  #...
  class PE(Peak):
    #Define peak class using the above generated locals

  return PE

Possible solution: Save the generated locals directly in the generated peak class

def gen_pe(family):
  alu = gen_alu(family)
  Bit = family.Bit
  Data = family.BitVector
  Inst = gen_inst(family)
  #...
  local_values = locals()
  class PE(Peak):
     env = dict_to_obj(local_values)
    #Define peak class using the above generated locals

  return PE

PE = gen_pe(BitVector)
Data = PE.env.Data

Ideally there is a syntactically more concise way of getting the same effect.

@leonardt
Copy link
Collaborator

Whatever the mechanism, after discussing with @cdonovick I think the right path is to somehow pass locals() and globals() to magma (rather than the current logic which only works if the decorator is at the top level).

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

3 participants