summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--changelog.md2
-rw-r--r--compiler/ast.nim3
-rw-r--r--compiler/ccgtypes.nim2
-rw-r--r--compiler/wordrecg.nim4
-rw-r--r--doc/manual.rst4
-rw-r--r--lib/nimbase.h2
6 files changed, 13 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index e749fcb79..25fc3535c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -159,6 +159,8 @@ proc mydiv(a, b): int {.raises: [].} =
   The reason for this is that `DivByZeroDefect` inherits from `Defect` and
   with `--panics:on` `Defects` become unrecoverable errors.
 
+- Added `thiscall` calling convention as specified by Microsoft, mostly for hooking purpose
+
 ## Compiler changes
 
 - Specific warnings can now be turned into errors via `--warningAsError[X]:on|off`.
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 3fe75d1f3..97aa3a992 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -25,12 +25,13 @@ type
     ccInline,                 # proc should be inlined
     ccNoInline,               # proc should not be inlined
     ccFastCall,               # fastcall (pass parameters in registers)
+    ccThisCall,               # thiscall (parameters are pushed right-to-left)
     ccClosure,                # proc has a closure
     ccNoConvention            # needed for generating proper C procs sometimes
 
 const
   CallingConvToStr*: array[TCallingConvention, string] = ["", "stdcall",
-    "cdecl", "safecall", "syscall", "inline", "noinline", "fastcall",
+    "cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "thiscall",
     "closure", "noconv"]
 
 type
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 1e82a9725..96b59cd60 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -238,7 +238,7 @@ const
     "N_STDCALL", "N_CDECL", "N_SAFECALL",
     "N_SYSCALL", # this is probably not correct for all platforms,
                  # but one can #define it to what one wants
-    "N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_CLOSURE", "N_NOCONV"]
+    "N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_THISCALL", "N_CLOSURE", "N_NOCONV"]
 
 proc cacheGetType(tab: TypeCache; sig: SigHash): Rope =
   # returns nil if we need to declare this type
diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim
index 446897844..454224ae4 100644
--- a/compiler/wordrecg.nim
+++ b/compiler/wordrecg.nim
@@ -51,7 +51,7 @@ type
     wLineDir, wStackTrace, wLineTrace, wLink, wCompile,
     wLinksys, wDeprecated, wVarargs, wCallconv, wDebugger,
     wNimcall, wStdcall, wCdecl, wSafecall, wSyscall, wInline, wNoInline,
-    wFastcall, wClosure, wNoconv, wOn, wOff, wChecks, wRangeChecks,
+    wFastcall, wThiscall, wClosure, wNoconv, wOn, wOff, wChecks, wRangeChecks,
     wBoundChecks, wOverflowChecks, wNilChecks,
     wFloatChecks, wNanChecks, wInfChecks, wStyleChecks, wStaticBoundchecks,
     wNonReloadable, wExecuteOnReload,
@@ -139,7 +139,7 @@ const
     "push", "pop", "define", "undef", "linedir", "stacktrace", "linetrace",
     "link", "compile", "linksys", "deprecated", "varargs",
     "callconv", "debugger", "nimcall", "stdcall",
-    "cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "closure",
+    "cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "thiscall", "closure",
     "noconv", "on", "off", "checks", "rangechecks", "boundchecks",
     "overflowchecks", "nilchecks",
     "floatchecks", "nanchecks", "infchecks", "stylechecks", "staticboundchecks",
diff --git a/doc/manual.rst b/doc/manual.rst
index 2c39b3e73..1472dd4e6 100644
--- a/doc/manual.rst
+++ b/doc/manual.rst
@@ -1917,6 +1917,10 @@ Nim supports these `calling conventions`:idx:\:
     Fastcall means different things to different C compilers. One gets whatever
     the C ``__fastcall`` means.
 
+`thiscall`:idx:
+    This is thiscall calling convention as specified by Microsoft, used on C++
+    class member functions on the x86 architecture
+
 `syscall`:idx:
     The syscall convention is the same as ``__syscall`` in C. It is used for
     interrupts.
diff --git a/lib/nimbase.h b/lib/nimbase.h
index 0b0188b55..e43492b76 100644
--- a/lib/nimbase.h
+++ b/lib/nimbase.h
@@ -173,12 +173,14 @@ __AVR__
 #  define N_STDCALL(rettype, name) rettype __stdcall name
 #  define N_SYSCALL(rettype, name) rettype __syscall name
 #  define N_FASTCALL(rettype, name) rettype __fastcall name
+#  define N_THISCALL(rettype, name) rettype __thiscall name
 #  define N_SAFECALL(rettype, name) rettype __stdcall name
 /* function pointers with calling convention: */
 #  define N_CDECL_PTR(rettype, name) rettype (__cdecl *name)
 #  define N_STDCALL_PTR(rettype, name) rettype (__stdcall *name)
 #  define N_SYSCALL_PTR(rettype, name) rettype (__syscall *name)
 #  define N_FASTCALL_PTR(rettype, name) rettype (__fastcall *name)
+#  define N_THISCALL_PTR(rettype, name) rettype (__thiscall *name)
 #  define N_SAFECALL_PTR(rettype, name) rettype (__stdcall *name)
 
 #  ifdef __cplusplus