<commit_before>
from utils import parseFullSpec, SpecFile
from wrapper import wrapIfNecessary, unwrapClass
from generators import genTraceCall, genCall, genArgs
from wine import trace
from callback import wrap, unwrap, wrapToOrigin
import macros

type Dummy = object
  ## The empty struct needed to be used as return value in some functions and
  ## cause the compiller to generate code for in-memory return.

macro generateLinuxDecls*(specs: static[SpecFile]): untyped =
  ## Generates the libsteam_api.so bindings using given SpecFile.
  result = newStmtList()
  if specs.libpath.isNil:
    error("Spec file was not generated by dllparser or it was not found " &
          "any suitable libsteam_api.so!")
  let linkopt = newStrLitNode("'" & specs.libpath & "'")
  result.add quote do:
    {.passL:`linkopt`.}
  for s in specs.symbols:
    let name = newIdentNode(s.realname)
    let actualname = newStrLitNode(s.realname)
    var params = newTree(nnkFormalParams, genArgs(s.nargs))
    if s.swap:
      params[0] = bindSym("Dummy")
    var decl = quote do:
      proc `name`() {.codegenDecl:"extern $# $#$#", importc: `actualname`.}
    decl[3] = params
    result.add(decl)
  when defined(debug):
    echo(result.repr)

const toskip = ["SteamAPI_RunCallbacks_"]
  ## The list of symbols that should not be wrapped by debug output
  ## (they are being called very frequently).
const regcallback = @[
  "SteamAPI_RegisterCallback_",
  "SteamAPI_RegisterCallResult_",
]
  ## The list of symbols that take the CCallback object as a first argument.<commit_msg>Added attribute to ensure right calling convention for C interfaces<commit_after>
from utils import parseFullSpec, SpecFile
from wrapper import wrapIfNecessary, unwrapClass
from generators import genTraceCall, genCall, genArgs
from wine import trace
from callback import wrap, unwrap, wrapToOrigin
import macros

type Dummy = object
  a: uint64
  ## The empty struct needed to be used as return value in some functions and
  ## cause the compiller to generate code for in-memory return (CSteamID).

macro generateLinuxDecls*(specs: static[SpecFile]): untyped =
  ## Generates the libsteam_api.so bindings using given SpecFile.
  result = newStmtList()
  if specs.libpath.isNil:
    error("Spec file was not generated by dllparser or it was not found " &
          "any suitable libsteam_api.so!")
  let linkopt = newStrLitNode("'" & specs.libpath & "'")
  result.add quote do:
    {.passL:`linkopt`.}
  for s in specs.symbols:
    let name = newIdentNode(s.realname)
    let actualname = newStrLitNode(s.realname)
    var params = newTree(nnkFormalParams, genArgs(s.nargs))
    if s.swap:
      params[0] = bindSym("Dummy")
    var decl = quote do:
      proc `name`() {.codegenDecl:"extern $# __attribute__((sysv_abi)) $#$#",
                      importc: `actualname`.}
    decl[3] = params
    result.add(decl)
  when defined(debug):
    echo(result.repr)

const toskip = ["SteamAPI_RunCallbacks_"]
  ## The list of symbols that should not be wrapped by debug output
  ## (they are being called very frequently).
const regcallback = @[
  "SteamAPI_RegisterCallback_",
  "SteamAPI_RegisterCallResult_",
]
  ## The list of symbols that take the CCallback object as a first argument.
{'fraction_non_alphanumeric': 0.0946654332408264, 'fraction_numerical': 0.0018501387604070306, 'mean_word_length': 4.006172839506172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3472747', 'n_tokens_mistral': 1013, 'n_tokens_neox': 987, 'n_words': 340}