From 615c64443b8a06fe3104955d86d910988eeccf5f Mon Sep 17 00:00:00 2001
From: Joe Groff <arcata@gmail.com>
Date: Thu, 1 Apr 2010 03:35:37 -0700
Subject: [PATCH] update M\ int-regs param-regs for x86-32 to give input regs
 for thiscall/fastcall

---
 basis/cpu/x86/32/32.factor | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor
index df5bdd2bb4..c707294e42 100755
--- a/basis/cpu/x86/32/32.factor
+++ b/basis/cpu/x86/32/32.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: locals alien.c-types alien.libraries alien.syntax arrays
-kernel fry math namespaces sequences system layouts io
+USING: locals alien alien.c-types alien.libraries alien.syntax
+arrays kernel fry math namespaces sequences system layouts io
 vocabs.loader accessors init combinators command-line make
 compiler compiler.units compiler.constants compiler.alien
 compiler.codegen compiler.codegen.fixup
@@ -83,11 +83,18 @@ M: x86.32 return-struct-in-registers? ( c-type -- ? )
 : struct-return@ ( n -- operand )
     [ next-stack@ ] [ stack-frame get params>> local@ ] if* ;
 
-! On x86, parameters are never passed in registers.
+! On x86, parameters are usually never passed in registers, except with Microsoft's
+! "thiscall" and "fastcall" abis
 M: int-regs return-reg drop EAX ;
-M: int-regs param-regs 2drop { } ;
 M: float-regs param-regs 2drop { } ;
 
+M: int-regs param-regs
+    nip {
+        { thiscall [ { ECX     } ] }
+        { fastcall [ { ECX EDX } ] }
+        [ drop { } ]
+    } case ;
+
 GENERIC: load-return-reg ( src rep -- )
 GENERIC: store-return-reg ( dst rep -- )