Exemplo n.º 1
0
    def pycode(self):
        if self.DOT and self.LPAREN:
            # FIXME: implement this!
            error.conversion_error(
                "can't handle '<struct>.(<field_index>)' yet", self.lineno)
            return ''

        if self.DOT or (not self.IDENTIFIER):
            return Node.pycode(self)

        if self.argument_list:
            pars, keys = self.argument_list.get_pars_and_keys()
        else:
            pars = []
            keys = []

        name = str(self.IDENTIFIER)
        fmap = map.get_subroutine_map(name)

        if not fmap:
            keys = ['%s=%s' % (k[0], k[1]) for k in keys]
            return '%s(%s)' % (pycode(self.IDENTIFIER), ', '.join(pars + keys))

        try:
            return fmap.pycall(pars, keys)
        except map.Error, e:
            error.mapping_error(str(e), self.lineno)
            return ''
Exemplo n.º 2
0
   def pycode(self):
      if self.assignment_statement:
         # FIXME: implement this!
         error.conversion_error("can't handle assignment in expressions yet",
	                        self.lineno)
         return ''
      return Node.pycode(self)
Exemplo n.º 3
0
 def pycode(self):
     if self.assignment_statement:
         # FIXME: implement this!
         error.conversion_error(
             "can't handle assignment in expressions yet", self.lineno)
         return ''
     return Node.pycode(self)
Exemplo n.º 4
0
 def pycode(self):
     if self.LBRACE:
         # FIXME: implement this!
         error.conversion_error("can't handle structures yet", self.lineno)
         return ''
     if self.LBRACKET:
         return 'concatenate(%s)' % Node.pycode(self)
     return Node.pycode(self)
Exemplo n.º 5
0
   def pycode(self):
      if self.GOTO:
         error.conversion_error('cannot convert GOTO statements; please ' +
	                        'remove them and try again', self.lineno)
         return pycomment(str(self))
      if not self.RETURN:
         return str(self[0]).lower()
      if _in_pro:
         return 'return _ret()'
      if _in_function:
         return 'return ' + pycode(self.expression)
      error.syntax_error('RETURN outside of PRO or FUNCTION', self.lineno)
      return ''
Exemplo n.º 6
0
   def pycode(self):
      if self.GOTO:
         error.conversion_error('cannot convert GOTO statements; please ' +
	                        'remove them and try again', self.lineno)
         return pycomment(str(self))
      if not self.RETURN:
         return str(self[0]).lower()
      if _in_pro:
         return 'return _ret()'
      if _in_function:
         return 'return ' + pycode(self.expression)
      error.syntax_error('RETURN outside of PRO or FUNCTION', self.lineno)
      return ''
Exemplo n.º 7
0
def indgen_dispatch(i, o):

    def _error_ret():
        return '#{ INDGEN(%s) [%s]}#' % (", ".join(i), ", ".join(o))

    typename = config.inttype

    kws = filter(lambda x: x.find('=') != -1, i)
    if len(kws) == 0:
        return indgen_worker(typename, i, o)

    if len(kws) > 1: 
        # error.conversion_error("multiple keywords to INDGEN", 0)
        return _error_ret()

    types = {
        'BYTE' : 'uint8', 
        'COMPLEX':      'complex64',
        'DCOMPLEX':	'complex128',
        'DOUBLE':	'float64',
        'FLOAT':	'float32',
        'L64':		'int64',
        'LONG':		'int32',
        'STRING':	None,
        'UINT':		config.uinttype,
        'UL64':		'uint64',
        'ULONG':        'uint32',
    }

    for ii in range(len(i)):
        m = re.match('(\w+)=(\w+)', i[ii])
        if m:
            key, val = m.groups()
            key = key.upper()
            if key == 'TYPE':
                return indgen_worker(typemap[int(val)], i, o)
            if key == 'STRING':
                # error.conversion_error("INDGEN with /STRING not supported", 0)
                return _error_ret()
            if key not in types:
                error.conversion_error("unknown keyword to INDGEN", 0)
            try:
                res = eval(val, {})
            except:
                res = True
            if res:
                typename = types[key]
            i.pop(ii)
            break

    return indgen_worker(typename, i, o)
Exemplo n.º 8
0
def indgen_dispatch(i, o):
    def _error_ret():
        return "#{ INDGEN(%s) [%s]}#" % (", ".join(i), ", ".join(o))

    typename = config.inttype

    kws = filter(lambda x: x.find("=") != -1, i)
    if len(kws) == 0:
        return indgen_worker(typename, i, o)

    if len(kws) > 1:
        # error.conversion_error("multiple keywords to INDGEN", 0)
        return _error_ret()

    types = {
        "BYTE": "uint8",
        "COMPLEX": "complex64",
        "DCOMPLEX": "complex128",
        "DOUBLE": "float64",
        "FLOAT": "float32",
        "L64": "int64",
        "LONG": "int32",
        "STRING": None,
        "UINT": config.uinttype,
        "UL64": "uint64",
        "ULONG": "uint32",
    }

    for ii in range(len(i)):
        m = re.match("(\w+)=(\w+)", i[ii])
        if m:
            key, val = m.groups()
            key = key.upper()
            if key == "TYPE":
                return indgen_worker(typemap[int(val)], i, o)
            if key == "STRING":
                # error.conversion_error("INDGEN with /STRING not supported", 0)
                return _error_ret()
            if key not in types:
                error.conversion_error("unknown keyword to INDGEN", 0)
            try:
                res = eval(val, {})
            except:
                res = True
            if res:
                typename = types[key]
            i.pop(ii)
            break

    return indgen_worker(typename, i, o)
Exemplo n.º 9
0
    def get_pars_and_keys(self):
        pars = []
        keys = []

        for a in self.get_items():
            if a.EXTRA:
                # FIXME: implement this!
                error.conversion_error("can't handle _EXTRA yet", self.lineno)
                return ''
            if a.DIVIDE:
                keys.append((pycode(a.IDENTIFIER), 'True'))
            elif a.IDENTIFIER:
                keys.append((pycode(a.IDENTIFIER), pycode(a.expression)))
            else:
                pars.append(pycode(a.expression))

        return (pars, keys)
Exemplo n.º 10
0
    def pycode(self):
        global _in_pro, _in_function

        pars = []
        keys = []

        plist = self.subroutine_body.parameter_list
        if plist:
            for p in plist.get_items():
                if p.EXTRA:
                    # FIXME: implement this!
                    error.conversion_error("can't handle _EXTRA yet",
                                           self.lineno)
                    return ''
                if p.EQUALS:
                    keys.append(
                        (pycode(p.IDENTIFIER[0]), pycode(p.IDENTIFIER[1])))
                else:
                    pars.append(pycode(p.IDENTIFIER))

        name = str(self.subroutine_body.IDENTIFIER)
        fmap = 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 = map.map_pro(name,
                                   inpars=inpars,
                                   outpars=outpars,
                                   inkeys=inkeys,
                                   outkeys=outkeys)
        else:
            _in_function = True
            if not fmap:
                fmap = map.map_func(name, inpars=inpars, inkeys=inkeys)

        try:
            header, body = fmap.pydef(pars, keys)
        except map.Error, e:
            error.mapping_error(str(e), self.lineno)
            header, body = '', ''
Exemplo n.º 11
0
 def pycode(self):
     if self.TIMES:
         # FIXME: implement this!
         error.conversion_error("can't handle pointers yet", self.lineno)
         return ''
     return Node.pycode(self)