Skip to content

Commit 285dda3

Browse files
committed
2 parents b11fe78 + fbf8189 commit 285dda3

File tree

2 files changed

+50
-23
lines changed

2 files changed

+50
-23
lines changed

doc/sagittarius/continuations.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[§2] Continuations libraries {#lib.sagittarius.continuations}
2+
--------------------------------------------------------------
3+
4+
This library provides continuation enhancement. The main capabilities
5+
this library provieds are below
6+
7+
- Continuation prompt
8+
- Composable continuation
9+
- Delimited continuation
10+

src/vm.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,14 +2001,6 @@ static void remove_prompt(SgVM *vm, SgPrompt *prompt)
20012001
node = node->next;
20022002
}
20032003
}
2004-
2005-
static SgObject remove_prompt_cc(SgObject r, void **data)
2006-
{
2007-
SgVM *vm = theVM;
2008-
SgPrompt *prompt = (SgPrompt *)data[0];
2009-
remove_prompt(vm, prompt);
2010-
return r;
2011-
}
20122004

20132005
SgObject Sg_VMCallCP(SgObject proc, SgObject tag,
20142006
SgObject handler, SgObject args)
@@ -2025,8 +2017,6 @@ SgObject Sg_VMCallCP(SgObject proc, SgObject tag,
20252017
PUSH_PROMPT_CONT(vm, prompt);
20262018
FP(vm) = SP(vm);
20272019
install_prompt(vm, prompt);
2028-
2029-
Sg_VMPushCC(remove_prompt_cc, (void **)&prompt, 1);
20302020

20312021
return Sg_VMApply(proc, args);
20322022
}
@@ -2391,7 +2381,10 @@ static SG_DEFINE_SUBR(default_exception_handler_rec, 1, 0,
23912381

23922382
static SgContFrame *skip_prompt_frame(SgContFrame *cont)
23932383
{
2394-
while (PROMPT_FRAME_MARK_P(cont)) cont = cont->prev;
2384+
while (PROMPT_FRAME_MARK_P(cont)) {
2385+
remove_prompt(theVM, (SgPrompt *)cont->pc);
2386+
cont = cont->prev;
2387+
}
23952388
return cont;
23962389
}
23972390

@@ -2926,20 +2919,40 @@ static void print_argument(SgVM *vm, SgContFrame *cont,
29262919
# include <dlfcn.h>
29272920
static int print_c_pc(SgVM *vm, SgObject pfmt, SgContFrame *cont)
29282921
{
2929-
if (cont->fp == C_CONT_MARK) {
2930-
Dl_info info;
2931-
/* pc == after function */
2932-
if (dladdr((void *)cont->pc, &info) && info.dli_sname) {
2933-
SgObject pc = SG_INTERN("pc");
2934-
SgObject name = Sg_Utf8sToUtf32s(info.dli_sname, strlen(info.dli_sname));
2935-
Sg_Printf(vm->logPort, UC(";; %p "),
2936-
(uintptr_t)cont + offsetof(SgContFrame, pc));
2937-
Sg_Format(vm->logPort, pfmt, SG_LIST2(pc, name), TRUE);
2938-
return TRUE;
2939-
}
2922+
Dl_info info;
2923+
/* pc == after function */
2924+
if (dladdr((void *)cont->pc, &info) && info.dli_sname) {
2925+
SgObject pc = SG_INTERN("pc");
2926+
SgObject name = Sg_Utf8sToUtf32s(info.dli_sname, strlen(info.dli_sname));
2927+
Sg_Printf(vm->logPort, UC(";; %p "),
2928+
(uintptr_t)cont + offsetof(SgContFrame, pc));
2929+
Sg_Format(vm->logPort, pfmt, SG_LIST2(pc, name), TRUE);
2930+
return TRUE;
29402931
}
29412932
return FALSE;
29422933
}
2934+
#elif _WIN32
2935+
# include <dbghelp.h>
2936+
# pragma comment(lib, "dbghelp.lib")
2937+
static int print_c_pc(SgVM *vm, SgObject pfmt, SgContFrame *cont)
2938+
{
2939+
#define SYM_LEN 256
2940+
char buffer[sizeof(SYMBOL_INFO) + sizeof(char)*SYM_LEN];
2941+
SYMBOL_INFO *sym = (SYMBOL_INFO *)buffer;
2942+
DWORD64 displacement = 0;
2943+
sym->SizeOfStruct = sizeof(SYMBOL_INFO);
2944+
sym->MaxNameLen = SYM_LEN;
2945+
if (SymFromAddr(GetCurrentProcess(), (DWORD64)cont->pc, &displacement, sym)) {
2946+
SgObject pc = SG_INTERN("pc");
2947+
SgObject name = Sg_Utf8sToUtf32s(sym->Name, sym->NameLen);
2948+
Sg_Printf(vm->logPort, UC(";; %p "),
2949+
(uintptr_t)cont + offsetof(SgContFrame, pc));
2950+
Sg_Format(vm->logPort, pfmt, SG_LIST2(pc, name), TRUE);
2951+
return TRUE;
2952+
}
2953+
return FALSE;
2954+
#undef SYM_LEN
2955+
}
29432956
#else
29442957
static int print_c_pc(SgVM *vm, SgObject pfmt, SgContFrame *cont)
29452958
{
@@ -2956,7 +2969,7 @@ static void print_pc(SgVM *vm, SgObject pfmt, SgContFrame *cont)
29562969
(uintptr_t)cont + offsetof(SgContFrame, pc));
29572970
Sg_Format(vm->logPort, pfmt,
29582971
SG_LIST2(pc, Sg_Cons(p->tag, p->handler)), TRUE);
2959-
} else if (!print_c_pc(vm, pfmt, cont)) {
2972+
} else if (cont->fp != C_CONT_MARK || !print_c_pc(vm, pfmt, cont)) {
29602973
Sg_Printf(vm->logPort, UC(";; %p + pc=%#38p +\n"),
29612974
(uintptr_t)cont + offsetof(SgContFrame, pc), cont->pc);
29622975
}
@@ -3221,6 +3234,10 @@ void Sg__InitVM()
32213234
Sg_AddCleanupHandler(show_inst_count, NULL);
32223235
#endif
32233236
sym_continuation = Sg_MakeSymbol(SG_MAKE_STRING("continuation"), FALSE);
3237+
3238+
#ifdef _WIN32
3239+
SymInitialize(GetCurrentProcess(), NULL, TRUE);
3240+
#endif
32243241
}
32253242

32263243
void Sg__PostInitVM()

0 commit comments

Comments
 (0)