Advertisement
Guest User

Untitled

a guest
Jan 27th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.67 KB | None | 0 0
  1. ---
  2. compiler/evalffi.nim | 62 ++++++++++++++++++++++++++--------------------------
  3.  compiler/main.nim    |  4 ++--
  4.  lib/pure/dynlib.nim  |  2 +-
  5.  lib/system/excpt.nim |  2 +-
  6.  4 files changed, 35 insertions(+), 35 deletions(-)
  7.  
  8. diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim
  9. index 74f0663..a534046 100644
  10. --- a/compiler/evalffi.nim
  11. +++ b/compiler/evalffi.nim
  12. @@ -22,9 +22,9 @@ var
  13.    gDllCache = initTable[string, TLibHandle]()
  14.  
  15.  when defined(windows):
  16. -  var gExeHandle = loadLib(os.getAppFilename())
  17. +  var gExeHandle = LoadLib(os.getAppFilename())
  18.  else:
  19. -  var gExeHandle = loadLib()
  20. +  var gExeHandle = LoadLib()
  21.  
  22.  proc getDll(cache: var TDllCache; dll: string; info: TLineInfo): pointer =
  23.    result = cache[dll]
  24. @@ -32,7 +32,7 @@ proc getDll(cache: var TDllCache; dll: string; info: TLineInfo): pointer =
  25.      var libs: seq[string] = @[]
  26.      libCandidates(dll, libs)
  27.      for c in libs:
  28. -      result = loadLib(c)
  29. +      result = LoadLib(c)
  30.        if not result.isNil: break
  31.      if result.isNil:
  32.        globalError(info, "cannot load: " & dll)
  33. @@ -102,7 +102,7 @@ proc mapCallConv(cc: TCallingConvention, info: TLineInfo): TABI =
  34.    of ccStdCall: result = when defined(windows): STDCALL else: DEFAULT_ABI
  35.    of ccCDecl: result = DEFAULT_ABI
  36.    else:
  37. -    GlobalError(info, "cannot map calling convention to FFI")
  38. +    globalError(info, "cannot map calling convention to FFI")
  39.  
  40.  template rd(T, p: expr): expr {.immediate.} = (cast[ptr T](p))[]
  41.  template wr(T, p, v: expr) {.immediate.} = (cast[ptr T](p))[] = v
  42. @@ -151,7 +151,7 @@ proc getField(n: PNode; position: int): PSym =
  43.    else: discard
  44.  
  45.  proc packObject(x: PNode, typ: PType, res: pointer) =
  46. -  InternalAssert x.kind in {nkObjConstr, nkPar}
  47. +  internalAssert x.kind in {nkObjConstr, nkPar}
  48.    # compute the field's offsets:
  49.    discard typ.getSize
  50.    for i in countup(ord(x.kind == nkObjConstr), sonsLen(x) - 1):
  51. @@ -164,7 +164,7 @@ proc packObject(x: PNode, typ: PType, res: pointer) =
  52.        let field = getField(typ.n, i)
  53.        pack(it, field.typ, res +! field.offset)
  54.      else:
  55. -      GlobalError(x.info, "cannot pack unnamed tuple")
  56. +      globalError(x.info, "cannot pack unnamed tuple")
  57.  
  58.  const maxPackDepth = 20
  59.  var packRecCheck = 0
  60. @@ -193,7 +193,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
  61.      of 4: awr(int32, v.intVal.int32)
  62.      of 8: awr(int64, v.intVal.int64)
  63.      else:
  64. -      GlobalError(v.info, "cannot map value to FFI (tyEnum, tySet)")
  65. +      globalError(v.info, "cannot map value to FFI (tyEnum, tySet)")
  66.    of tyFloat: awr(float, v.floatVal)
  67.    of tyFloat32: awr(float32, v.floatVal)
  68.    of tyFloat64: awr(float64, v.floatVal)
  69. @@ -207,7 +207,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
  70.      elif v.kind in {nkStrLit..nkTripleStrLit}:
  71.        awr(cstring, cstring(v.strVal))
  72.      else:
  73. -      GlobalError(v.info, "cannot map pointer/proc value to FFI")
  74. +      globalError(v.info, "cannot map pointer/proc value to FFI")
  75.    of tyPtr, tyRef, tyVar:
  76.      if v.kind == nkNilLit:
  77.        # nothing to do since the memory is 0 initialized anyway
  78. @@ -217,7 +217,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
  79.      else:
  80.        if packRecCheck > maxPackDepth:
  81.          packRecCheck = 0
  82. -        GlobalError(v.info, "cannot map value to FFI " & typeToString(v.typ))
  83. +        globalError(v.info, "cannot map value to FFI " & typeToString(v.typ))
  84.        inc packRecCheck
  85.        pack(v.sons[0], typ.sons[0], res +! sizeof(pointer))
  86.        dec packRecCheck
  87. @@ -233,7 +233,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
  88.    of tyDistinct, tyGenericInst:
  89.      pack(v, typ.sons[0], res)
  90.    else:
  91. -    GlobalError(v.info, "cannot map value to FFI " & typeToString(v.typ))
  92. +    globalError(v.info, "cannot map value to FFI " & typeToString(v.typ))
  93.  
  94.  proc unpack(x: pointer, typ: PType, n: PNode): PNode
  95.  
  96. @@ -243,7 +243,7 @@ proc unpackObjectAdd(x: pointer, n, result: PNode) =
  97.      for i in countup(0, sonsLen(n) - 1):
  98.        unpackObjectAdd(x, n.sons[i], result)
  99.    of nkRecCase:
  100. -    GlobalError(result.info, "case objects cannot be unpacked")
  101. +    globalError(result.info, "case objects cannot be unpacked")
  102.    of nkSym:
  103.      var pair = newNodeI(nkExprColonExpr, result.info, 2)
  104.      pair.sons[0] = n
  105. @@ -262,14 +262,14 @@ proc unpackObject(x: pointer, typ: PType, n: PNode): PNode =
  106.      result = newNode(nkPar)
  107.      result.typ = typ
  108.      if typ.n.isNil:
  109. -      InternalError("cannot unpack unnamed tuple")
  110. +      internalError("cannot unpack unnamed tuple")
  111.      unpackObjectAdd(x, typ.n, result)
  112.    else:
  113.      result = n
  114.      if result.kind notin {nkObjConstr, nkPar}:
  115. -      GlobalError(n.info, "cannot map value from FFI")
  116. +      globalError(n.info, "cannot map value from FFI")
  117.      if typ.n.isNil:
  118. -      GlobalError(n.info, "cannot unpack unnamed tuple")
  119. +      globalError(n.info, "cannot unpack unnamed tuple")
  120.      for i in countup(ord(n.kind == nkObjConstr), sonsLen(n) - 1):
  121.        var it = n.sons[i]
  122.        if it.kind == nkExprColonExpr:
  123. @@ -288,7 +288,7 @@ proc unpackArray(x: pointer, typ: PType, n: PNode): PNode =
  124.    else:
  125.      result = n
  126.      if result.kind != nkBracket:
  127. -      GlobalError(n.info, "cannot map value from FFI")
  128. +      globalError(n.info, "cannot map value from FFI")
  129.    let baseSize = typ.sons[1].getSize
  130.    for i in 0 .. < result.len:
  131.      result.sons[i] = unpack(x +! i * baseSize, typ.sons[1], result.sons[i])
  132. @@ -312,7 +312,7 @@ proc unpack(x: pointer, typ: PType, n: PNode): PNode =
  133.          #echo "expected ", k, " but got ", result.kind
  134.          #debug result
  135.          return newNodeI(nkExceptBranch, n.info)
  136. -        #GlobalError(n.info, "cannot map value from FFI")
  137. +        #globalError(n.info, "cannot map value from FFI")
  138.      result.field = v
  139.  
  140.    template setNil() =
  141. @@ -337,19 +337,19 @@ proc unpack(x: pointer, typ: PType, n: PNode): PNode =
  142.    of tyInt16: awi(nkInt16Lit, rd(int16, x))
  143.    of tyInt32: awi(nkInt32Lit, rd(int32, x))
  144.    of tyInt64: awi(nkInt64Lit, rd(int64, x))
  145. -  of tyUInt: awi(nkUIntLit, rd(uint, x).biggestInt)
  146. -  of tyUInt8: awi(nkUInt8Lit, rd(uint8, x).biggestInt)
  147. -  of tyUInt16: awi(nkUInt16Lit, rd(uint16, x).biggestInt)
  148. -  of tyUInt32: awi(nkUInt32Lit, rd(uint32, x).biggestInt)
  149. -  of tyUInt64: awi(nkUInt64Lit, rd(uint64, x).biggestInt)
  150. +  of tyUInt: awi(nkUIntLit, rd(uint, x).BiggestInt)
  151. +  of tyUInt8: awi(nkUInt8Lit, rd(uint8, x).BiggestInt)
  152. +  of tyUInt16: awi(nkUInt16Lit, rd(uint16, x).BiggestInt)
  153. +  of tyUInt32: awi(nkUInt32Lit, rd(uint32, x).BiggestInt)
  154. +  of tyUInt64: awi(nkUInt64Lit, rd(uint64, x).BiggestInt)
  155.    of tyEnum:
  156.      case typ.getSize
  157. -    of 1: awi(nkIntLit, rd(uint8, x).biggestInt)
  158. -    of 2: awi(nkIntLit, rd(uint16, x).biggestInt)
  159. -    of 4: awi(nkIntLit, rd(int32, x).biggestInt)
  160. -    of 8: awi(nkIntLit, rd(int64, x).biggestInt)
  161. +    of 1: awi(nkIntLit, rd(uint8, x).BiggestInt)
  162. +    of 2: awi(nkIntLit, rd(uint16, x).BiggestInt)
  163. +    of 4: awi(nkIntLit, rd(int32, x).BiggestInt)
  164. +    of 8: awi(nkIntLit, rd(int64, x).BiggestInt)
  165.      else:
  166. -      GlobalError(n.info, "cannot map value from FFI (tyEnum, tySet)")
  167. +      globalError(n.info, "cannot map value from FFI (tyEnum, tySet)")
  168.    of tyFloat: awf(nkFloatLit, rd(float, x))
  169.    of tyFloat32: awf(nkFloat32Lit, rd(float32, x))
  170.    of tyFloat64: awf(nkFloat64Lit, rd(float64, x))
  171. @@ -374,7 +374,7 @@ proc unpack(x: pointer, typ: PType, n: PNode): PNode =
  172.        n.sons[0] = unpack(p, typ.sons[0], n.sons[0])
  173.        result = n
  174.      else:
  175. -      GlobalError(n.info, "cannot map value from FFI " & typeToString(typ))
  176. +      globalError(n.info, "cannot map value from FFI " & typeToString(typ))
  177.    of tyObject, tyTuple:
  178.      result = unpackObject(x, typ, n)
  179.    of tyArray, tyArrayConstr:
  180. @@ -391,7 +391,7 @@ proc unpack(x: pointer, typ: PType, n: PNode): PNode =
  181.      result = unpack(x, typ.sons[0], n)
  182.    else:
  183.      # XXX what to do with 'array' here?
  184. -    GlobalError(n.info, "cannot map value from FFI " & typeToString(typ))
  185. +    globalError(n.info, "cannot map value from FFI " & typeToString(typ))
  186.  
  187.  proc fficast*(x: PNode, destTyp: PType): PNode =
  188.    if x.kind == nkPtrLit and x.typ.kind in {tyPtr, tyRef, tyVar, tyPointer,
  189. @@ -414,7 +414,7 @@ proc fficast*(x: PNode, destTyp: PType): PNode =
  190.      dealloc a
  191.  
  192.  proc callForeignFunction*(call: PNode): PNode =
  193. -  InternalAssert call.sons[0].kind == nkPtrLit
  194. +  internalAssert call.sons[0].kind == nkPtrLit
  195.    
  196.    var cif: TCif
  197.    var sig: TParamList
  198. @@ -422,12 +422,12 @@ proc callForeignFunction*(call: PNode): PNode =
  199.    for i in 1..call.len-1:
  200.      sig[i-1] = mapType(call.sons[i].typ)
  201.      if sig[i-1].isNil:
  202. -      GlobalError(call.info, "cannot map FFI type")
  203. +      globalError(call.info, "cannot map FFI type")
  204.    
  205.    let typ = call.sons[0].typ
  206.    if prep_cif(cif, mapCallConv(typ.callConv, call.info), cuint(call.len-1),
  207.                mapType(typ.sons[0]), sig) != OK:
  208. -    GlobalError(call.info, "error in FFI call")
  209. +    globalError(call.info, "error in FFI call")
  210.    
  211.    var args: TArgList
  212.    let fn = cast[pointer](call.sons[0].intVal)
  213. diff --git a/compiler/main.nim b/compiler/main.nim
  214. index cdea7b5..584cfe9 100644
  215. --- a/compiler/main.nim
  216. +++ b/compiler/main.nim
  217. @@ -135,7 +135,7 @@ proc interactivePasses =
  218.    #setTarget(osNimrodVM, cpuNimrodVM)
  219.    initDefines()
  220.    defineSymbol("nimrodvm")
  221. -  when hasFFI: DefineSymbol("nimffi")
  222. +  when hasFFI: defineSymbol("nimffi")
  223.    registerPass(verbosePass)
  224.    registerPass(semPass)
  225.    registerPass(evalPass)
  226. @@ -324,7 +324,7 @@ proc mainCommand* =
  227.      wantMainModule()
  228.      when hasTinyCBackend:
  229.        extccomp.setCC("tcc")
  230. -      CommandCompileToC()
  231. +      commandCompileToC()
  232.      else:
  233.        rawMessage(errInvalidCommandX, command)
  234.    of "js", "compiletojs":
  235. diff --git a/lib/pure/dynlib.nim b/lib/pure/dynlib.nim
  236. index a64b7f1..b09716f 100644
  237. --- a/lib/pure/dynlib.nim
  238. +++ b/lib/pure/dynlib.nim
  239. @@ -55,7 +55,7 @@ when defined(posix):
  240.      RTLD_NOW {.importc: "RTLD_NOW", header: "<dlfcn.h>".}: int
  241.  
  242.    proc dlclose(lib: TLibHandle) {.importc, header: "<dlfcn.h>".}
  243. -  proc dlopen(path: CString, mode: int): TLibHandle {.
  244. +  proc dlopen(path: cstring, mode: int): TLibHandle {.
  245.        importc, header: "<dlfcn.h>".}
  246.    proc dlsym(lib: TLibHandle, name: cstring): pointer {.
  247.        importc, header: "<dlfcn.h>".}
  248. diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
  249. index a3f6669..e50ba7b 100644
  250. --- a/lib/system/excpt.nim
  251. +++ b/lib/system/excpt.nim
  252. @@ -23,7 +23,7 @@ else:
  253.    proc MessageBoxA(hWnd: cint, lpText, lpCaption: cstring, uType: int): int32 {.
  254.      header: "<windows.h>", nodecl.}
  255.  
  256. -  proc writeToStdErr(msg: CString) =
  257. +  proc writeToStdErr(msg: cstring) =
  258.      discard MessageBoxA(0, msg, nil, 0)
  259.  
  260.  proc showErrorMessage(data: cstring) =
  261. --
  262. 1.8.5.3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement