Пример #1
0
   def pycode(self):
      global _in_pro, _in_function, _classes_used

      pars = []
      keys = []
      extra = []
      method = False

      # import ipdb; ipdb.set_trace()
      plist = self.subroutine_body.parameter_list

      if self.subroutine_body.method_name.DCOLON is None:
         name = pycode(self.subroutine_body.method_name)
         if name[-8:].lower() == '__define':       # class definition
            if plist:
               print "Class definition with parameters -- probably not allowed!"
            return ClassDefinition(name[:-8], find_structure_body(self))
      else:
         # Method definition
         classname, name = map(pycode, self.subroutine_body.method_name.IDENTIFIER)
         # methodname = pycode(methodname)
         # classname = pycode(classname)
         method = True



      if plist:
	 for p in plist.get_items():
	    if p.EXTRA:
               extra = pycode(p.IDENTIFIER) if p.IDENTIFIER else "extra"
               continue
	    if p.EQUALS:
	       keys.append((pycode(p.IDENTIFIER[0]), pycode(p.IDENTIFIER[1])))
	    else:
	       pars.append(pycode(p.IDENTIFIER))

      fmap = i2py_map.get_subroutine_map(name)
      if not fmap:
         inpars  = range(1, len(pars)+1)
	 outpars = inpars
	 inkeys  = [ k[0] for k in keys ]
	 outkeys = inkeys

      if self.PRO:
         _in_pro = True
	 if not fmap:
	    fmap = i2py_map.map_pro(name, inpars=inpars, outpars=outpars,
	                       inkeys=inkeys, outkeys=outkeys, method=method)
      elif self.FUNCTION:
         _in_function = True
	 if not fmap:
	    fmap = i2py_map.map_func(name, inpars=inpars, inkeys=inkeys, method=method)
      else:
         raise RuntimeError("not PRO, not FUNCTION, then what?")

      try:
         header, body = fmap.pydef(pars, keys, extra=extra)
      except i2py_map.Error, e:
         error.mapping_error(str(e), self.lineno)
	 header, body = '', ''
Пример #2
0
   def pycode(self):
      global _in_pro, _in_function, _classes_used

      pars = []
      keys = []
      extra = []
      method = False

      # import ipdb; ipdb.set_trace()
      plist = self.subroutine_body.parameter_list

      if self.subroutine_body.method_name.DCOLON is None:
         name = pycode(self.subroutine_body.method_name)
         if name[-8:].lower() == '__define':       # class definition
            if plist:
               print "Class definition with parameters -- probably not allowed!"
            return ClassDefinition(name[:-8], find_structure_body(self))
      else:
         # Method definition
         classname, name = map(pycode, self.subroutine_body.method_name.IDENTIFIER)
         # methodname = pycode(methodname)
         # classname = pycode(classname)
         method = True



      if plist:
	 for p in plist.get_items():
	    if p.EXTRA:
               extra = pycode(p.IDENTIFIER) if p.IDENTIFIER else "extra"
               continue
	    if p.EQUALS:
	       keys.append((pycode(p.IDENTIFIER[0]), pycode(p.IDENTIFIER[1])))
	    else:
	       pars.append(pycode(p.IDENTIFIER))

      fmap = i2py_map.get_subroutine_map(name)
      if not fmap:
         inpars  = range(1, len(pars)+1)
	 outpars = inpars
	 inkeys  = [ k[0] for k in keys ]
	 outkeys = inkeys

      if self.PRO:
         _in_pro = True
	 if not fmap:
	    fmap = i2py_map.map_pro(name, inpars=inpars, outpars=outpars,
	                       inkeys=inkeys, outkeys=outkeys, method=method)
      elif self.FUNCTION:
         _in_function = True
	 if not fmap:
	    fmap = i2py_map.map_func(name, inpars=inpars, inkeys=inkeys, method=method)
      else:
         raise RuntimeError("not PRO, not FUNCTION, then what?")

      try:
         header, body = fmap.pydef(pars, keys, extra=extra)
      except i2py_map.Error, e:
         error.mapping_error(str(e), self.lineno)
	 header, body = '', ''
Пример #3
0
# Variable maps
#
################################################################################

# pi is in Numeric/numarray
map_var('!DPI', 'pi')
map_var('!RADEG', '_radeg', '_radeg = 180.0 / pi')

################################################################################
#
# Procedure maps
#
################################################################################

map_pro('ON_ERROR',
        inpars=[1],
        callfunc=(lambda i, o: '# ON_ERROR, %s' % i[0]))
map_pro('ON_IOERROR',
        inpars=[1],
        callfunc=(lambda i, o: '# ON_IOERROR, %s' % i[0]))
map_pro('CATCH',
        inpars=[1],
        inkeys=['CANCEL'],
        callfunc=lambda i, o: '# CATCH, %s' % i)
map_pro('PRINT',
        inpars=range(1, 101),
        noptional=100,
        inkeys=['FORMAT'],
        callfunc=(lambda i, o: 'print( ' + ', '.join(i) + ')'))

################################################################################
Пример #4
0
################################################################################


# pi is in Numeric/numarray
map_var("!DPI", "pi")
map_var("!RADEG", "_radeg", "_radeg = 180.0 / pi")


################################################################################
#
# Procedure maps
#
################################################################################


map_pro("ON_ERROR", inpars=[1], callfunc=(lambda i, o: "# ON_ERROR, %s" % i[0]))
map_pro("ON_IOERROR", inpars=[1], callfunc=(lambda i, o: "# ON_IOERROR, %s" % i[0]))
map_pro("CATCH", inpars=[1], inkeys=["CANCEL"], callfunc=lambda i, o: "# CATCH, %s" % i)
map_pro(
    "PRINT", inpars=range(1, 101), noptional=100, inkeys=["FORMAT"], callfunc=(lambda i, o: "print " + ", ".join(i))
)


################################################################################
#
# Function maps
#
################################################################################

########################################################
# Things with different names in Python