Ejemplo n.º 1
0
 def visit_stmt(self, node, src_info = None):
   #print "visit_stmt", node
   src_info = self.build_src_info(node)
   srcAddr = src_addr(src_info)
   if isinstance(node, ast.If):
     test = self.visit_expr(node.test)
     if_true = self.visit_stmt_sequence(node.body, src_info)
     if_false = self.visit_stmt_sequence(node.orelse, src_info)
     return LibPar.mk_if(test, if_true, if_false, srcAddr)
   elif isinstance(node, ast.Assign):
     assert len(node.targets) == 1
     return self.visit_assign(node.targets[0], node.value, src_info)
   elif isinstance(node, ast.Return):
     return self.visit_return(node, src_info)
     
   elif isinstance(node, ast.While):
     # infrequently used final iteration, not supported for now
     assert node.orelse == [] or node.orelse is None
     block = self.visit_stmt_sequence(node.body)
     test = self.visit_expr(node.test)
     return LibPar.mk_whileloop(test, block, srcAddr)
   elif isinstance(node, ast.Expr):
     return self.visit_expr(node.value)
   else:
     raise RuntimeError("Unsupported statement" + str(node))
Ejemplo n.º 2
0
def build_var(name, src_info = None):
  #Special case for booleans and None
  if name == 'True':
    return build_bool(True, src_info)
  elif name == 'False':
    return build_bool(False, src_info)
  elif name == 'None':
    return mk_none(src_info)
  else:
    return LibPar.mk_var(c_char_p(name), src_addr(src_info))
Ejemplo n.º 3
0
def mk_call(fn, positional_args, kw_names = [], kw_values = [], src_info=None):
  """
    lower-level helper for building a function call, 
    Assumes function is a Parakeet node and that keyword
    names have already been converted to character pointers
  """
  assert len(kw_names) == len(kw_values)
  
  args_array = list_to_ctypes_array(positional_args)
  n_args = c_int(len(positional_args))
  kw_names_array = list_to_ctypes_array(kw_names, c_char_p)
  kw_values_array = list_to_ctypes_array(kw_values)
  n_kwds = c_int(len(kw_names))
  srcAddr = src_addr(src_info)
  
  #print "mk_call", kw_names_array, kw_values_array   
  # paranode fun, paranode *args, int num_args,
  # char** keywords, paranode* keyword_values, int num_keyword_args,
  #  source_info_t *src_info
  return LibPar.mk_call(
    fn, args_array, n_args, kw_names_array, kw_values_array, n_kwds, srcAddr)
Ejemplo n.º 4
0
def build_bool(b, src_info = None):
  if b: 
    return LibPar.mk_bool_paranode(1, src_addr(src_info))
  else:
    return LibPar.mk_bool_paranode(0, src_addr(src_info))
Ejemplo n.º 5
0
def build_none(src_info = None):
  return LibPar.mk_none(src_addr(src_info))
Ejemplo n.º 6
0
def mk_block(stmts, src_info = None):
  arr = list_to_ctypes_array(stmts)
  return LibPar.mk_block(arr, len(stmts), src_addr(src_info))
Ejemplo n.º 7
0
def mk_tuple(elts, src_info = None):
  arr = list_to_ctypes_array(elts)
  return LibPar.mk_tuple(arr, len(arr), src_addr(src_info))
Ejemplo n.º 8
0
def mk_return(elts, src_info=None):
  arr = list_to_ctypes_array(elts) if len(elts) > 0 else None
  return LibPar.mk_return(arr, len(elts), src_addr(src_info))
Ejemplo n.º 9
0
def build_float(f, src_info = None):  
  return LibPar.mk_double_paranode(c_double(f), src_addr(src_info))
Ejemplo n.º 10
0
def build_long(l, src_info = None): 
  return LibPar.mk_int64_paranode(l, src_addr(src_info))
Ejemplo n.º 11
0
def build_int(i, src_info = None):
  return LibPar.mk_int32_paranode(i, src_addr(src_info))