How to use the expression.gen_E_new function in Expression

To help you get started, we’ve selected a few Expression examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plum-umd / pasket / pasket / meta / clazz.py View on Github external
  @staticmethod
  def call_init(tname, params=[]):
    args = []
    try:
      cls = class_lookup(tname)
      inits = cls.mtd_by_name(tname) # AttributeError if cls is NoneType
      for init in inits:
        _args = method.sig_match(init.params, params)
        # try to find best matched one
        if len(args) <= len(_args): args = _args
    except (AttributeError, IndexError): pass
    f = exp.gen_E_id(tname)
    args = map(exp.to_expression, args)
    return exp.gen_E_new(exp.gen_E_call(f, args)), args
github plum-umd / pasket / pasket / meta / clazz.py View on Github external
@takes(AST)
@returns(Clazz)
def parse_enum(node):
  _kind = node.getText()
  cls = Clazz(kind=_kind)
  cls.name = node.getChild(0).getChild(0).getText()
  _nodes = node.getChildren()[1:] # exclude name
  constants = util.implode_id(util.mk_v_node_w_children(_nodes)).split(',')
  for c in constants:
    # define representative field
    fld = field.Field(clazz=cls, mods=C.PBST, typ=cls.name, name=c)
    cls.add_fld(fld)
    # initialize it in 
    f = exp.gen_E_id(cls.name)
    init_e = exp.gen_E_new(exp.gen_E_call(f, []))
    init_s = st.gen_S_assign(exp.gen_E_id(c), init_e)
    cls.clinit_fld(fld, [init_s])
  return cls