コード例 #1
0
ファイル: Regal.py プロジェクト: chadaustin/regal
def apiFuncDefineCode(apis, args):

    #

    code = ''
    for api in apis:

        tmp = []
        for function in api.functions:

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            rTypes = rType.strip()
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            c = ''
            c += 'REGAL_DECL %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)

            emue = [
                emuFindEntry(function, i['formulae'], i['member'], i['ifdef'])
                for i in emuRegal
            ]

            if function.needsContext:
                c += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'prefix')), '  '))
                c += '  %s\n' % logFunction(function, 'App')
                c += '  if (!_context) return'
                if typeIsVoid(rType):
                    c += ';\n'
                else:
                    if rTypes in api.defaults:
                        c += ' %s;\n' % (api.defaults[rTypes])
                    else:
                        if rType[-1] == '*' or typeIsVoidPointer(rType):
                            c += ' NULL;\n'
                        else:
                            c += ' (%s) 0;\n' % (rTypes)

                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'impl')), '  '))

                if getattr(function, 'regalRemap', None) != None and (
                        isinstance(function.regalRemap, list)
                        or isinstance(function.regalRemap, str)
                        or isinstance(function.regalRemap, unicode)):

                    # For an ES1 context, pass the call into the dispatch layers...

                    if function.category in [
                            'GL_REGAL_ES1_0_compatibility',
                            'GL_REGAL_ES1_1_compatibility'
                    ]:
                        c += '  #if REGAL_SYS_ES1\n'
                        c += '  if (_context->isES1()) // Pass-through for ES1 only\n'
                        c += '  {\n'
                        c += '    DispatchTableGL *_next = &_context->dispatcher.front();\n'
                        c += '    RegalAssert(_next);\n    '
                        if not typeIsVoid(rType):
                            c += 'return '
                        c += '_next->call(&_next->%s)(%s);\n' % (name,
                                                                 callParams)
                        if typeIsVoid(rType):
                            c += '    return;\n'
                        c += '  }\n'
                        c += '  #endif\n'

                    # For ES2 or GL context, remap the ES1 call

                    c += '  '
                    if not typeIsVoid(rType):
                        c += 'return '
                    if isinstance(function.regalRemap, list):
                        c += '\n  '.join(function.regalRemap) + '\n'
                    else:
                        c += '%s;\n' % (function.regalRemap)
                else:
                    if not getattr(function, 'regalOnly', False):
                        t = ''
                        t += 'DispatchTableGL *_next = &_context->dispatcher.front();\n'
                        t += 'RegalAssert(_next);\n'

                        t += listToString(
                            indent(stripVertical(emuCodeGen(emue, 'pre')), ''))

                        if not typeIsVoid(rType):
                            t += 'return '
                        t += '_next->call(&_next->%s)(%s);\n' % (name,
                                                                 callParams)

                        t += listToString(
                            indent(stripVertical(emuCodeGen(emue, 'post')),
                                   ''))

                        for i in emue:
                            if i != None and i['cond'] != None:
                                t = wrapCIf(i['cond'], indent(t))

                        c += indent(t)

                        c += listToString(
                            indent(stripVertical(emuCodeGen(emue, 'suffix')),
                                   '  '))

            else:
                c += '  %s\n' % logFunction(function, 'App')
                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'prefix')), '  '))

                if not getattr(function, 'regalOnly', False):
                    c += '  DispatchTableGlobal *_next = &dispatcherGlobal.front();\n'
                    c += '  RegalAssert(_next);\n'

                    if not typeIsVoid(rType):
                        if rTypes in api.defaults:
                            c += '  %s ret = %s;\n' % (rTypes,
                                                       api.defaults[rTypes])
                        else:
                            if rType[-1] == '*' or typeIsVoidPointer(rType):
                                c += '  %s ret = NULL;\n' % rTypes
                            else:
                                c += '  %s ret = (%s) 0;\n' % (rTypes, rTypes)

                    c += listToString(
                        indent(stripVertical(emuCodeGen(emue, 'impl')), '  '))
                    c += '  '
                    if not typeIsVoid(rType):
                        c += 'ret = '
                    c += '_next->call(&_next->%s)(%s);\n' % (name, callParams)

                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'init')), '  '))

                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'suffix')), '  '))
                if not typeIsVoid(rType):
                    c += '  return ret;\n'
            c += '}\n\n'

            tmp.append((category, indent(c, '  ')))

        tmp = listToString(unfoldCategory(tmp, '  /* %s */'))

        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += tmp

    return code
コード例 #2
0
ファイル: Regal.py プロジェクト: swq0553/regal
def apiFuncDefineCode(apis, args):

  #

  code = ''
  for api in apis:

    tmp = []
    for function in api.functions:

      name       = function.name
      params     = paramsDefaultCode(function.parameters, True)
      callParams = paramsNameCode(function.parameters)
      rType      = typeCode(function.ret.type)
      rTypes     = rType.strip()
      category   = getattr(function, 'category', None)
      version    = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      c = ''
      c += 'REGAL_DECL %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)

      emue = [ emuFindEntry( function, i['formulae'], i['member'] ) for i in emuRegal ]

      if function.needsContext:
        c += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
        c += listToString(indent(stripVertical(emuCodeGen(emue,'prefix')),'  '))
        c += '  %s\n' % logFunction( function, 'App' )
        c += '  if (!_context) return'
        if typeIsVoid(rType):
          c += ';\n'
        else:
          if rTypes in api.defaults:
            c += ' %s;\n' % ( api.defaults[rTypes] )
          else:
            if rType[-1]=='*' or typeIsVoidPointer(rType):
              c += ' NULL;\n'
            else:
              c += ' (%s) 0;\n' % ( rTypes )

        c += listToString(indent(stripVertical(emuCodeGen(emue,'impl')),'  '))

        if getattr(function,'regalRemap',None)!=None and (isinstance(function.regalRemap, list) or isinstance(function.regalRemap, str) or isinstance(function.regalRemap, unicode)):

          # For an ES1 context, pass the call into the dispatch layers...

          if function.category in ['GL_REGAL_ES1_0_compatibility','GL_REGAL_ES1_1_compatibility']:
            c += '  #if REGAL_SYS_ES1\n'
            c += '  if (_context->isES1()) // Pass-through for ES1 only\n'
            c += '  {\n'
            c += '    DispatchTableGL *_next = &_context->dispatcher.front();\n'
            c += '    RegalAssert(_next);\n    '
            if not typeIsVoid(rType):
              c += 'return '
            c += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )
            if typeIsVoid(rType):
              c += '    return;\n'
            c += '  }\n'
            c += '  #endif\n'

          # For ES2 or GL context, remap the ES1 call

          c += '  '
          if not typeIsVoid(rType):
            c += 'return '
          if isinstance(function.regalRemap, list):
            c += '\n  '.join(function.regalRemap) + '\n'
          else:
            c += '%s;\n'%(function.regalRemap)
        else:
          if not getattr(function,'regalOnly',False):
            t = ''
            t += 'DispatchTableGL *_next = &_context->dispatcher.front();\n'
            t += 'RegalAssert(_next);\n'

            t += listToString(indent(stripVertical(emuCodeGen(emue,'pre')),''))

            if not typeIsVoid(rType):
              t += 'return '
            t += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

            t += listToString(indent(stripVertical(emuCodeGen(emue,'post')),''))

            for i in emue:
              if i!=None and i['cond']!=None:
                t = wrapCIf(i['cond'],indent(t))

            c += indent(t)

            c += listToString(indent(stripVertical(emuCodeGen(emue,'suffix')),'  '))

      else:
        c += '  %s\n' % logFunction(function, 'App' )
        c += listToString(indent(stripVertical(emuCodeGen(emue,'prefix')),'  '))

        if not getattr(function,'regalOnly',False):
          c += '  DispatchTableGlobal *_next = &dispatcherGlobal.front();\n'
          c += '  RegalAssert(_next);\n'

          if not typeIsVoid(rType):
            if rTypes in api.defaults:
              c += '  %s ret = %s;\n' % ( rTypes, api.defaults[rTypes] )
            else:
              if rType[-1]=='*' or typeIsVoidPointer(rType):
                c += '  %s ret = NULL;\n' % rTypes
              else:
                c += '  %s ret = (%s) 0;\n' % ( rTypes, rTypes )

          c += listToString(indent(stripVertical(emuCodeGen(emue,'impl')),'  '))
          c += '  '
          if not typeIsVoid(rType):
            c += 'ret = '
          c += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

        c += listToString(indent(stripVertical(emuCodeGen(emue,'init')),'  '))

        c += listToString(indent(stripVertical(emuCodeGen(emue,'suffix')),'  '))
        if not typeIsVoid(rType):
          c += '  return ret;\n'
      c += '}\n\n'

      tmp.append( (category, indent(c,'  ') ) )

    tmp = listToString(unfoldCategory(tmp,'  /* %s */'))

    if api.name in cond:
      tmp = wrapIf(cond[api.name], tmp)

    code += tmp

  return code
コード例 #3
0
def apiMissingFuncDefineCode(apis, args):

    code = ''
    categoryPrev = None

    for api in apis:

        code += '\n'
        if api.name in cond:
            code += '#if %s\n' % cond[api.name]

        for function in api.functions:

            if getattr(function, 'regalOnly', False) == True:
                continue

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            rTypes = rType.strip()
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            # Close prev category block.
            if categoryPrev and not (category == categoryPrev):
                code += '\n'

            # Begin new category block.
            if category and not (category == categoryPrev):
                code += '// %s\n\n' % category

            categoryPrev = category

            code += '  static %sREGAL_CALL %s(%s) \n{\n' % (rType, name,
                                                            params)
            for param in function.parameters:
                code += '    UNUSED_PARAMETER(%s);\n' % param.name
            code += '    Warning( "%s", " not available." );\n' % name

            if not typeIsVoid(rType):
                if rTypes in api.defaults:
                    code += '    return %s;\n' % (api.defaults[rTypes])
                else:
                    if rType[-1] == '*' or typeIsVoidPointer(rType):
                        code += '    return NULL;\n'
                    else:
                        code += '    return (%s) 0;\n' % (rTypes)

            code += '  }\n\n'

        if api.name in cond:
            code += '#endif // %s\n' % cond[api.name]
        code += '\n'

    return code
コード例 #4
0
def apiMissingFuncDefineCode(apis, args):

  code = ''
  categoryPrev = None

  for api in apis:

    code += '\n'
    if api.name in cond:
      code += '#if %s\n' % cond[api.name]

    for function in api.functions:

      if getattr(function,'regalOnly',False)==True:
        continue

      name   = function.name
      params = paramsDefaultCode(function.parameters, True)
      callParams = paramsNameCode(function.parameters)
      rType     = typeCode(function.ret.type)
      rTypes    = rType.strip()
      category  = getattr(function, 'category', None)
      version   = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      # Close prev category block.
      if categoryPrev and not (category == categoryPrev):
        code += '\n'

      # Begin new category block.
      if category and not (category == categoryPrev):
        code += '// %s\n\n' % category

      categoryPrev = category

      code += '  static %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)
      for param in function.parameters:
        code += '    UNUSED_PARAMETER(%s);\n' % param.name
      code += '    Warning( "%s", " not available." );\n' % name

      if not typeIsVoid(rType):
        if rTypes in api.defaults:
          code += '    return %s;\n' % ( api.defaults[rTypes] )
        else:
          if rType[-1]=='*' or typeIsVoidPointer(rType):
            code += '    return NULL;\n'
          else:
            code += '    return (%s) 0;\n' % ( rTypes )

      code += '  }\n\n'

    if api.name in cond:
      code += '#endif // %s\n' % cond[api.name]
    code += '\n'

  return code
コード例 #5
0
ファイル: RegalDispatchHttp.py プロジェクト: nigels-com/regal
def generateDispatchHttp(apis, args):

  # CodeGen for API functions.

  code = ''
  categoryPrev = None

  for api in apis:

    code += '\n'
    if api.name in cond:
      code += '#if %s\n' % cond[api.name]

    for function in api.functions:

      if getattr(function,'regalOnly',False)==True:
        continue

      name   = function.name
      params = paramsDefaultCode(function.parameters, True)
      callParams = paramsNameCode(function.parameters)
      rType  = typeCode(function.ret.type)
      rTypes    = rType.strip()
      category  = getattr(function, 'category', None)
      version   = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      # Close prev category block.
      if categoryPrev and not (category == categoryPrev):
        code += '\n'

      # Begin new category block.
      if category and not (category == categoryPrev):
        code += '// %s\n\n' % category

      categoryPrev = category

      code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'http_', name, params)

      generated = dispatchGenCode( function, formulae )

      retInit = ''
      if not typeIsVoid(rType):
        if rTypes in api.defaults:
          retInit += '%s' % ( api.defaults[rTypes] )
        else:
          if rType[-1]=='*' or typeIsVoidPointer(rType):
            retInit += 'NULL'
          else:
            retInit += '(%s) 0' % ( rTypes )

      if not typeIsVoid(rType):
        code += '    %s ret = %s;\n' % (rType, retInit)
      code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
      if function.needsContext:
        code += '    RegalAssert( _context );\n'

      code += '    if( _context ) {\n'
      if generated and 'pre' in generated:
        for i in generated['pre']:
          code += '      %s\n' % i

      code += '      if( _context->http.runState == RS_Next ) {\n'
      code += '        _context->http.runState = RS_Pause;\n'
      code += '      }\n'
      code += '      _context->http.YieldToHttpServer( _context );\n'

      code += '    }\n'

      if function.needsContext:
        code += '    DispatchTableGL *_next = _context ? _context->dispatcher.http.next() : NULL;\n'
      else:
        code += '    DispatchTableGlobal *_next = dispatcherGlobal.http.next();\n'

      code += '    RegalAssert(_next);\n'

      code += '    '

      if not typeIsVoid(rType):
        code += 'ret = '
      code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

      if generated and 'post' in generated:
        code += '    if( _context ) {\n'
        for i in generated['post']:
          code += '      %s\n' % i
        code += '    }\n'

      if not typeIsVoid(rType):
        code += '    return ret;\n'
      code += '}\n\n'

    if api.name in cond:
      code += '#endif // %s\n' % cond[api.name]
    code += '\n'

  # Close pending if block.
  if categoryPrev:
    code += '\n'

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GL_DISPATCH_INIT']     = apiDispatchFuncInitCode( apis, args, 'http' )
  substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode( apis, args, 'http' )

  outputCode( '%s/RegalDispatchHttp.cpp' % args.srcdir, dispatchHttpTemplate.substitute(substitute))
コード例 #6
0
def generateDispatchHttp(apis, args):

    # CodeGen for API functions.

    code = ''
    categoryPrev = None

    for api in apis:

        code += '\n'
        if api.name in cond:
            code += '#if %s\n' % cond[api.name]

        for function in api.functions:

            if getattr(function, 'regalOnly', False) == True:
                continue

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            rTypes = rType.strip()
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            # Close prev category block.
            if categoryPrev and not (category == categoryPrev):
                code += '\n'

            # Begin new category block.
            if category and not (category == categoryPrev):
                code += '// %s\n\n' % category

            categoryPrev = category

            code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'http_',
                                                            name, params)

            generated = dispatchGenCode(function, formulae)

            retInit = ''
            if not typeIsVoid(rType):
                if rTypes in api.defaults:
                    retInit += '%s' % (api.defaults[rTypes])
                else:
                    if rType[-1] == '*' or typeIsVoidPointer(rType):
                        retInit += 'NULL'
                    else:
                        retInit += '(%s) 0' % (rTypes)

            if not typeIsVoid(rType):
                code += '    %s ret = %s;\n' % (rType, retInit)
            code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
            if function.needsContext:
                code += '    RegalAssert( _context );\n'

            code += '    if( _context ) {\n'
            if generated and 'pre' in generated:
                for i in generated['pre']:
                    code += '      %s\n' % i

            code += '#if REGAL_HTTP\n'
            code += '      if( _context->http.runState == RS_Next ) {\n'
            code += '        _context->http.runState = RS_Pause;\n'
            code += '      }\n'
            code += '      _context->http.YieldToHttpServer( _context );\n'
            code += '#endif\n'

            code += '    }\n'

            code += '#if REGAL_HTTP\n'

            if function.needsContext:
                code += '    DispatchTableGL *_next = _context ? _context->dispatcher.http.next() : NULL;\n'
            else:
                code += '    DispatchTableGlobal *_next = dispatcherGlobal.http.next();\n'

            code += '    RegalAssert(_next);\n'

            code += '    '

            if not typeIsVoid(rType):
                code += 'ret = '
            code += '_next->call(&_next->%s)(%s);\n' % (name, callParams)

            code += '#endif\n'

            if generated and 'post' in generated:
                code += '    if( _context ) {\n'
                for i in generated['post']:
                    code += '      %s\n' % i
                code += '    }\n'

            if not typeIsVoid(rType):
                code += '    return ret;\n'
            code += '}\n\n'

        if api.name in cond:
            code += '#endif // %s\n' % cond[api.name]
        code += '\n'

    # Close pending if block.
    if categoryPrev:
        code += '\n'

    # Output

    substitute = {}
    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['API_FUNC_DEFINE'] = code
    substitute['API_GL_DISPATCH_INIT'] = apiDispatchFuncInitCode(
        apis, args, 'http')
    substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode(
        apis, args, 'http')

    outputCode('%s/RegalDispatchHttp.cpp' % args.srcdir,
               dispatchHttpTemplate.substitute(substitute))
コード例 #7
0
ファイル: Regal.py プロジェクト: phuang/regal
def apiFuncDefineCode(apis, args):

    #

    code = ""
    for api in apis:

        tmp = []
        for function in api.functions:

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            rTypes = rType.strip()
            category = getattr(function, "category", None)
            version = getattr(function, "version", None)

            if category:
                category = category.replace("_DEPRECATED", "")
            elif version:
                category = version.replace(".", "_")
                category = "GL_VERSION_" + category

            c = ""
            c += "REGAL_DECL %sREGAL_CALL %s(%s) \n{\n" % (rType, name, params)

            emue = [emuFindEntry(function, i["formulae"], i["member"]) for i in emuRegal]

            if function.needsContext:
                c += "  RegalContext *_context = REGAL_GET_CONTEXT();\n"
                c += listToString(indent(emuCodeGen(emue, "prefix"), "  "))
                c += "  %s\n" % logFunction(function, "App")
                c += "  if (!_context) return"
                if typeIsVoid(rType):
                    c += ";\n"
                else:
                    if rTypes in api.defaults:
                        c += " %s;\n" % (api.defaults[rTypes])
                    else:
                        if rType[-1] == "*" or typeIsVoidPointer(rType):
                            c += " NULL;\n"
                        else:
                            c += " (%s) 0;\n" % (rTypes)

                c += listToString(indent(emuCodeGen(emue, "impl"), "  "))

                if getattr(function, "regalRemap", None) != None and (
                    isinstance(function.regalRemap, list)
                    or isinstance(function.regalRemap, str)
                    or isinstance(function.regalRemap, unicode)
                ):

                    # For an ES1 context, pass the call into the dispatch layers...

                    if function.category in ["GL_REGAL_ES1_0_compatibility", "GL_REGAL_ES1_1_compatibility"]:
                        c += "  #if REGAL_SYS_ES1\n"
                        c += "  if (_context->isES1()) // Pass-through for ES1 only\n"
                        c += "  {\n"
                        c += "    DispatchTableGL *_next = &_context->dispatcher.front();\n"
                        c += "    RegalAssert(_next);\n    "
                        if not typeIsVoid(rType):
                            c += "return "
                        c += "_next->call(&_next->%s)(%s);\n" % (name, callParams)
                        if typeIsVoid(rType):
                            c += "    return;\n"
                        c += "  }\n"
                        c += "  #endif\n"

                    # For ES2 or GL context, remap the ES1 call

                    c += "  "
                    if not typeIsVoid(rType):
                        c += "return "
                    if isinstance(function.regalRemap, list):
                        c += "\n  ".join(function.regalRemap) + "\n"
                    else:
                        c += "%s;\n" % (function.regalRemap)
                else:
                    if getattr(function, "regalOnly", False) == False:
                        t = ""
                        t += "DispatchTableGL *_next = &_context->dispatcher.front();\n"
                        t += "RegalAssert(_next);\n"

                        t += listToString(indent(emuCodeGen(emue, "pre"), ""))

                        if not typeIsVoid(rType):
                            t += "return "
                        t += "_next->call(&_next->%s)(%s);\n" % (name, callParams)

                        t += listToString(indent(emuCodeGen(emue, "post"), ""))

                        for i in emue:
                            if i != None and i["cond"] != None:
                                t = wrapCIf(i["cond"], indent(t))

                        c += indent(t)

                        c += listToString(indent(emuCodeGen(emue, "suffix"), "  "))

            else:
                c += "  %s\n" % logFunction(function, "App")
                c += listToString(indent(emuCodeGen(emue, "prefix"), "  "))

                if getattr(function, "regalOnly", False) == False:
                    c += "  DispatchTableGlobal *_next = &dispatcherGlobal.front();\n"
                    c += "  RegalAssert(_next);\n"

                    if not typeIsVoid(rType):
                        if rTypes in api.defaults:
                            c += "  %s ret = %s;\n" % (rTypes, api.defaults[rTypes])
                        else:
                            if rType[-1] == "*" or typeIsVoidPointer(rType):
                                c += "  %s ret = NULL;\n" % rTypes
                            else:
                                c += "  %s ret = (%s) 0;\n" % (rTypes, rTypes)

                    c += listToString(indent(emuCodeGen(emue, "impl"), "  "))
                    c += "  "
                    if not typeIsVoid(rType):
                        c += "ret = "
                    c += "_next->call(&_next->%s)(%s);\n" % (name, callParams)

                c += listToString(indent(emuCodeGen(emue, "init"), "  "))

                c += listToString(indent(emuCodeGen(emue, "suffix"), "  "))
                if not typeIsVoid(rType):
                    c += "  return ret;\n"
            c += "}\n\n"

            tmp.append((category, indent(c, "  ")))

        tmp = listToString(unfoldCategory(tmp, "  /* %s */"))

        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += tmp

    return code