Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interp-x86-3 errors when running code compiled from Lfun #24

Closed
nicball opened this issue May 27, 2023 · 1 comment
Closed

interp-x86-3 errors when running code compiled from Lfun #24

nicball opened this issue May 27, 2023 · 1 comment

Comments

@nicball
Copy link

nicball commented May 27, 2023

When compiling for tail calls, I emit code that modifies %rsp in functions' main body, which errors the interpretor:

R3/interp-x86-instr @ interp.rkt:916
(car ast):
addq $0, %rsp

R4/interp-x86-exp @ interp.rkt:1272
ast:
$0

interp-x86-exp @ interp.rkt:874
ast:
$0

R2/interp-x86-exp @ interp.rkt:472
ast:
$0

interp-x86-exp @ interp.rkt:261
ast:
$0

R1/interp-x86-exp @ interp.rkt:271
(observe-value result):
0

R2/interp-x86-exp @ interp.rkt:501
(observe-value result):
0

R3/interp-x86-exp @ interp.rkt:883
(observe-value result):
0

R4/interp-x86-exp @ interp.rkt:1281
(observe-value result):
0

R4/interp-x86-exp @ interp.rkt:1272
ast:
%rsp

interp-x86-exp @ interp.rkt:874
ast:
%rsp

R2/interp-x86-exp @ interp.rkt:472
ast:
%rsp

interp-x86-exp @ interp.rkt:261
ast:
%rsp

encountered exception while testing 'fun`, case functions_test_1
lookup: didn't find rsp in (r15 rax rdi rcx r15)
context...:
/home/nicball/code/eoc/interp.rkt:260:6
/home/nicball/code/eoc/interp.rkt:471:6
/home/nicball/code/eoc/interp.rkt:873:6
/home/nicball/code/eoc/interp.rkt:1271:6
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/collects/racket/match/compiler.rkt:559:40: f1310
/home/nicball/code/eoc/interp.rkt:1238:4: call-function method in interp-R4-class
/home/nicball/code/eoc/interp.rkt:1362:6
/home/nicball/code/eoc/utilities.rkt:1975:2
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:86:13: the-tests
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:61:0: apply-test-suite
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:139:7
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:136:2
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:61:0: apply-test-suite
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/pkgs/rackunit-lib/rackunit/text-ui.rkt:91:0: run-tests
/nix/store/y4an9j6cm3gb2bzjrljb0vxrxrb188fa-racket-8.8/share/racket/collects/racket/contract/private/arrow-val-first.rkt:489:18
body of "/home/nicball/code/eoc/run-tests.rkt"

Relevant part in my main function looks like this:

'mainstart

live-afters:
(list (set fun-ref.44016) (set %rdi fun-ref.44016) (set))

leaq id(%rip), %rcx
movq $42, %rdi
movq %rcx, %rax
subq $0, %r15
addq $0, %rsp
popq %rbp
jmp *%rax

It seems that the x86 interpretors treat preludes and conclusions specially without actually simulating %rsp and %rbp.

Am I implementing tail calls wrongly. Or this accompanying code is not sync with the book?

I am trying to understand interp.rkt and maybe come up with my PR. Your input on this issue would be much appreciated. Thanks in advance!

@nicball nicball closed this as completed May 27, 2023
@nicball nicball closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2023
@nicball
Copy link
Author

nicball commented May 27, 2023

This issue duplicates #16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant