简体   繁体   English

如何在DrScheme中实现Tail Call Optimization?

[英]How is Tail Call Optimization implemented in DrScheme?

I've heard that trampolining is an ineffective way of implementing TCO. 我听说蹦床是实施TCO的一种无效方式。 How does DrScheme (PLAI Scheme, technically) do it? DrScheme(PLAI Scheme,技术上)如何做到这一点? Does it do it the 'right' way (that is, produce assembly code which directly branches to the tail call, instead of going through the stack and trampolining)? 它是以“正确”的方式做到的(也就是说,生成直接分支到尾部调用的汇编代码,而不是通过堆栈和trampolining)?

Matthew Flatt, the chief implementor of MzScheme (now PLT Scheme) told me in June 2008 that at one time they compiled down to virtual-machine code, in which case it is easy to write a VM that does proper tail calls. MzScheme(现为PLT Scheme)的主要实现者Matthew Flatt在2008年6月告诉我,他们曾经编译成虚拟机代码,在这种情况下,编写一个能够正确执行尾调用的VM很容易。 Now, however, the system is mature enough that on x86 they use a simple JIT. 但是,现在系统已经足够成熟,在x86上它们使用简单的JIT。 In either case, there is no trampolining---the PLT Scheme guys know their business. 在任何一种情况下,都没有蹦床 - PLT计划的人都知道他们的业务。

The implementors of PLT Scheme are quite active in their Google group , where you can get a quick answer from the people who write the code. PLT Scheme的实施者在他们的谷歌小组中非常活跃,你可以从编写代码的人那里快速得到答案。

I'm not sure they read SO, though, so your best bet would probably be asking there. 不过,我不确定他们是这样读的,所以你最好的选择可能就是问那里。

Trampolines are used in implementations that translate Scheme code into a target language X (C, Java, etc.) that doesn't support Proper Tail Calls. Trampolines用于将Scheme代码转换为不支持Proper Tail Calls的目标语言X(C,Java等)的实现中。 PLT Scheme employs JIT-compilation - and therefore trampolines are not needed. PLT Scheme采用JIT编译 - 因此不需要蹦床。 For the exact implementation strategy used, ask the question on the PLT mailing list. 有关使用的确切实施策略,请在PLT邮件列表中提出问题。

PS: You can read more on trampolines in the various "Compile Scheme to C" papers available on ReadScheme.org . PS:你可以在ReadScheme.org上的各种“Compile Scheme to C”论文中阅读更多关于蹦床的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM