Re: implementing non local returns in C++



Vend wrote:
On 11 Ott, 12:05, jono <raromau...@xxxxxxxxxx> wrote:

hi all,

can anyone suggest any resources or tricks helpful for implementing tail
calls and continuations in a Scheme interpreter built using C++?


If you are writing an interpreter then you don't need to implement the
Scheme stack as the C++ stack.

i don't need to, but i have. i currently have a great deal of transparency in translating between C++ code and Scheme code in my extension language. evaluation of nested lists is already an implicit stack, but i don't need top manage it explicitly, and thats an advantage i want to keep. you're right tho, i may need to reconsider...

C tricks such as setjmp/longjmp and stack manipulations won't cut it. i
need something that works similarly to C++ exception handling, but more
efficient.


I don't think it's possible. If it was, compiler developers would
already have implemented exceptions that way.

well, yes and no. compiler developers have optimised exception handling for error handling, which makes it too inefficient but otherwise ideal for my purposes. the inefficiency is becos the compiler makes a record of the stack as it unwinds. Stroustrup describes exceptions as a "non local control structure" that can be seen primarily as "an alternative return mechanism". he also says that implementing an exception that "isn't all that expensive compared to calling a function [...] is possible, but hard."

i guess, as i'm not prepared to develop my own compiler, i'm looking for a magic trick. surely one is out there somewhere.




-- Posted on news://freenews.netfront.net - Complaints to news@xxxxxxxxxxxx --

.



Relevant Pages

  • R5.97RS - as a single file of ASCII [LONG] (revised)
    ... Revised5 Report on the Algorithmic Language Scheme) ... version 4 reference manual. ... regular identifier in Scheme, bound to a procedure that adds ...
    (comp.lang.scheme)
  • R5.97RS - as a single file of ascii [LONG]
    ... Revised5 Report on the Algorithmic Language Scheme) ... version 4 reference manual. ... regular identifier in Scheme, bound to a procedure that adds ...
    (comp.lang.scheme)
  • R5.97RS - as a plain ascii text file [LONG]
    ... Revised5 Report on the Algorithmic Language Scheme) ... version 4 reference manual. ... regular identifier in Scheme, bound to a procedure that adds ...
    (rec.games.roguelike.development)
  • Re: x86 exception handling and stack demand
    ... When an exception occurs that will be passed down to user mode as an SEH exception, the kernel arranges for control to return to user mode at a special function in NTDLL, with several parameters on the stack containing information about the exception. ... In XP and later, the system stores a pointer to the initial stack allocation block in the TEB that is used by the kernel to decommit the stack via NtFreeVirtualMemory when the thread is terminated in a non-graceful fashion, closing this leak. ...
    (microsoft.public.win32.programmer.kernel)
  • [PATCH] x86: style fascism for xen assemblies
    ... * a view to being able to inline as much as possible. ... push %eax ... * This is run where a normal iret would be run, with the same stack setup: ... In order to deliver the nested exception properly, ...
    (Linux-Kernel)

Loading