lwhjp / racket-asm

18 stars 2 forks source link

Failed to get the argument #2

Open Syntacticlosure opened 7 years ago

Syntacticlosure commented 7 years ago

There is a mistake in example. When I try to write an identity function f(x)=x such as this :

(define test-obj
  (assemble (prolog)
            (getarg r2 (arg 0))
            (mov r0 r2)
            (epilog)
            (ret r0)))

(define test (object->proc test-obj (_fun _int -> _int)))

It always returns zero no matter what the argument is. solution: change (arg 0) into (arg 3)

The problem may only happens on windows.

lwhjp commented 7 years ago

Thanks for the report!

I think this is due to the difference between Sys-V and Microsoft calling conventions on x86-64 (Microsoft uses RCX as the first argument, whereas this is the fourth on Sys-V). I have a generic solution planned for this, so I'll leave this issue open for now.

If you need to fix this urgently, you can change arg-regs in generic-x86-unit.rkt to be rcx rdx r8 r9 (see X86 calling conventions)