[uim-commit] r2076 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Mon Nov 7 13:25:49 PST 2005
Author: yamaken
Date: 2005-11-07 13:25:44 -0800 (Mon, 07 Nov 2005)
New Revision: 2076
Modified:
branches/r5rs/sigscheme/operations-srfi34.c
branches/r5rs/sigscheme/sigschemetype.h
branches/r5rs/sigscheme/storage-continuation.c
branches/r5rs/sigscheme/storage.c
Log:
* This commit changes the internal representation of continuation
object. It is suitable for SCM_OBJ_COMPACT. Please follow this in
sigschemetype-compact.h
* sigscheme/sigschemetype.h
- (struct ScmContinuation): Replace member 'opaque0' and 'opaque1'
with 'opaque' and 'tag'. This representation is suitable for
SCM_OBJ_COMPACT
- (SCM_CONTINUATION_OPAQUE0, SCM_CONTINUATION_SET_OPAQUE0,
SCM_CONTINUATION_OPAQUE1, SCM_CONTINUATION_SET_OPAQUE1): Removed
- (SCM_CONTINUATION_OPAQUE, SCM_CONTINUATION_SET_OPAQUE,
SCM_CONTINUATION_TAG, SCM_CONTINUATION_SET_TAG): New macro
* sigscheme/storage.c
- (Scm_NewContinuation): Follow the object representation change
- Fix a typo on a comment
* sigscheme/storage-continuation.c
- (CONTINUATION_FRAME, CONTINUATION_SET_FRAME): New macro
- (CONTINUATION_JMPENV, CONTINUATION_SET_JMPENV,
CONTINUATION_DYNEXT, CONTINUATION_SET_DYNEXT): Follow the object
representation change
- (struct continuation_frame): New type
- (continuation_stack_unwind, Scm_CallWithCurrentContinuation,
Scm_CallContinuation): Follow the object representation change
* sigscheme/operations-srfi34.c
- (CONTINUATION_FRAME, CONTINUATION_SET_FRAME, CONTINUATION_JMPENV,
CONTINUATION_SET_JMPENV, CONTINUATION_DYNEXT,
CONTINUATION_SET_DYNEXT, struct continuation_frame): Duplicate
from storage-continuation.c as temporary solution
- (ScmOp_SRFI34_with_exception_handler, ScmExp_SRFI34_guard): Follow
the object representation change
Modified: branches/r5rs/sigscheme/operations-srfi34.c
===================================================================
--- branches/r5rs/sigscheme/operations-srfi34.c 2005-11-07 20:46:35 UTC (rev 2075)
+++ branches/r5rs/sigscheme/operations-srfi34.c 2005-11-07 21:25:44 UTC (rev 2076)
@@ -44,17 +44,26 @@
#include "sigschemeinternal.h"
/*=======================================
- File Local Struct Declarations
+ File Local Macro Declarations
=======================================*/
+/* FIXME: make internal representation hidden */
+#define CONTINUATION_FRAME(cont) \
+ ((struct continuation_frame *)SCM_CONTINUATION_OPAQUE(cont))
+#define CONTINUATION_SET_FRAME SCM_CONTINUATION_SET_OPAQUE
+#define CONTINUATION_JMPENV(cont) (CONTINUATION_FRAME(cont)->env)
+#define CONTINUATION_SET_JMPENV(cont, env) (CONTINUATION_JMPENV(cont) = (env))
+#define CONTINUATION_DYNEXT(cont) (CONTINUATION_FRAME(cont)->dyn_ext)
+#define CONTINUATION_SET_DYNEXT(cont, dyn_ext) \
+ ((CONTINUATION_DYNEXT(cont)) = (dyn_ext))
/*=======================================
- File Local Macro Declarations
+ File Local Type Definitions
=======================================*/
/* FIXME: make internal representation hidden */
-#define CONTINUATION_JMPENV SCM_CONTINUATION_OPAQUE0
-#define CONTINUATION_SET_JMPENV SCM_CONTINUATION_SET_OPAQUE0
-#define CONTINUATION_DYNEXT SCM_CONTINUATION_OPAQUE1
-#define CONTINUATION_SET_DYNEXT SCM_CONTINUATION_SET_OPAQUE1
+struct continuation_frame {
+ jmp_buf *env;
+ ScmObj dyn_ext;
+};
/*=======================================
Variable Declarations
@@ -103,11 +112,13 @@
jmp_buf jmpenv;
ScmObj ret = SCM_FALSE;
ScmObj cont = Scm_NewContinuation();
+ struct continuation_frame cont_frame;
DECLARE_FUNCTION("with-exception-handler", ProcedureFixed2);
ASSERT_PROCEDUREP(handler);
ASSERT_PROCEDUREP(thunk);
+ CONTINUATION_SET_FRAME(cont, &cont_frame);
CONTINUATION_SET_JMPENV(cont, &jmpenv);
CONTINUATION_SET_DYNEXT(cont, scm_current_dynamic_extent);
if (setjmp(jmpenv)) {
@@ -140,6 +151,7 @@
ScmObj clauses = SCM_FALSE;
ScmObj expr = SCM_FALSE;
ScmObj cont = Scm_NewContinuation();
+ struct continuation_frame cont_frame;
DECLARE_FUNCTION("guard", SyntaxVariadic1);
ASSERT_CONSP(var_and_clauses);
@@ -150,6 +162,7 @@
ASSERT_SYMBOLP(var);
/* check if return from "raise" */
+ CONTINUATION_SET_FRAME(cont, &cont_frame);
CONTINUATION_SET_JMPENV(cont, &jmpenv);
CONTINUATION_SET_DYNEXT(cont, scm_current_dynamic_extent);
if (setjmp(jmpenv)) {
Modified: branches/r5rs/sigscheme/sigschemetype.h
===================================================================
--- branches/r5rs/sigscheme/sigschemetype.h 2005-11-07 20:46:35 UTC (rev 2075)
+++ branches/r5rs/sigscheme/sigschemetype.h 2005-11-07 21:25:44 UTC (rev 2076)
@@ -212,8 +212,8 @@
} port;
struct ScmContinuation {
- void *opaque0;
- void *opaque1;
+ void *opaque;
+ int tag;
} continuation;
#if !SCM_USE_VALUECONS
@@ -337,10 +337,10 @@
#define SCM_CONTINUATIONP(a) (SCM_TYPE(a) == ScmContinuation)
#define SCM_ENTYPE_CONTINUATION(a) (SCM_ENTYPE((a), ScmContinuation))
-#define SCM_CONTINUATION_OPAQUE0(a) (SCM_AS_CONTINUATION(a)->obj.continuation.opaque0)
-#define SCM_CONTINUATION_SET_OPAQUE0(a, val) (SCM_CONTINUATION_OPAQUE0(a) = (val))
-#define SCM_CONTINUATION_OPAQUE1(a) (SCM_AS_CONTINUATION(a)->obj.continuation.opaque1)
-#define SCM_CONTINUATION_SET_OPAQUE1(a, val) (SCM_CONTINUATION_OPAQUE1(a) = (val))
+#define SCM_CONTINUATION_OPAQUE(a) (SCM_AS_CONTINUATION(a)->obj.continuation.opaque)
+#define SCM_CONTINUATION_SET_OPAQUE(a, val) (SCM_CONTINUATION_OPAQUE(a) = (val))
+#define SCM_CONTINUATION_TAG(a) (SCM_AS_CONTINUATION(a)->obj.continuation.tag)
+#define SCM_CONTINUATION_SET_TAG(a, val) (SCM_CONTINUATION_TAG(a) = (val))
#if SCM_USE_VALUECONS
/* to modify a VALUECONS, rewrite its type to cons by SCM_ENTYPE_CONS(vcons) */
Modified: branches/r5rs/sigscheme/storage-continuation.c
===================================================================
--- branches/r5rs/sigscheme/storage-continuation.c 2005-11-07 20:46:35 UTC (rev 2075)
+++ branches/r5rs/sigscheme/storage-continuation.c 2005-11-07 21:25:44 UTC (rev 2076)
@@ -46,10 +46,6 @@
#include "sigschemeinternal.h"
/*=======================================
- File Local Struct Declarations
-=======================================*/
-
-/*=======================================
File Local Macro Declarations
=======================================*/
/* specifies whether the storage abstraction layer can only handle nested
@@ -58,12 +54,24 @@
*/
#define SCM_NESTED_CONTINUATION_ONLY 1
-#define CONTINUATION_JMPENV SCM_CONTINUATION_OPAQUE0
-#define CONTINUATION_SET_JMPENV SCM_CONTINUATION_SET_OPAQUE0
-#define CONTINUATION_DYNEXT SCM_CONTINUATION_OPAQUE1
-#define CONTINUATION_SET_DYNEXT SCM_CONTINUATION_SET_OPAQUE1
+#define CONTINUATION_FRAME(cont) \
+ ((struct continuation_frame *)SCM_CONTINUATION_OPAQUE(cont))
+#define CONTINUATION_SET_FRAME SCM_CONTINUATION_SET_OPAQUE
+#define CONTINUATION_JMPENV(cont) (CONTINUATION_FRAME(cont)->env)
+#define CONTINUATION_SET_JMPENV(cont, env) (CONTINUATION_JMPENV(cont) = (env))
+#define CONTINUATION_DYNEXT(cont) (CONTINUATION_FRAME(cont)->dyn_ext)
+#define CONTINUATION_SET_DYNEXT(cont, dyn_ext) \
+ ((CONTINUATION_DYNEXT(cont)) = (dyn_ext))
/*=======================================
+ File Local Type Definitions
+=======================================*/
+struct continuation_frame {
+ jmp_buf *env;
+ ScmObj dyn_ext;
+};
+
+/*=======================================
Variable Declarations
=======================================*/
/* dynamic extent */
@@ -233,7 +241,7 @@
cont = continuation_stack_pop();
if (FALSEP(cont))
return SCM_FALSE;
- CONTINUATION_SET_JMPENV(cont, INVALID_CONTINUATION_OPAQUE);
+ CONTINUATION_SET_FRAME(cont, INVALID_CONTINUATION_OPAQUE);
} while (!EQ(dest_cont, cont));
return dest_cont;
@@ -244,9 +252,11 @@
jmp_buf env;
ScmObj cont = SCM_FALSE;
ScmObj ret = SCM_FALSE;
+ struct continuation_frame cont_frame;
struct trace_frame *saved_trace_stack;
cont = Scm_NewContinuation();
+ CONTINUATION_SET_FRAME(cont, &cont_frame);
CONTINUATION_SET_JMPENV(cont, &env);
CONTINUATION_SET_DYNEXT(cont, scm_current_dynamic_extent);
#if SCM_NESTED_CONTINUATION_ONLY
@@ -255,11 +265,15 @@
if (setjmp(env)) {
/* returned from longjmp */
+ /*
+ * Don't refer cont because it may already be invalidated by
+ * continuation_stack_unwind().
+ */
ret = continuation_thrown_obj;
continuation_thrown_obj = SCM_FALSE; /* make ret sweepable */
trace_stack = saved_trace_stack;
- enter_dynamic_extent(CONTINUATION_DYNEXT(cont));
+ enter_dynamic_extent(cont_frame.dyn_ext);
eval_state->ret_type = SCM_RETTYPE_AS_IS;
return ret;
@@ -290,20 +304,24 @@
void Scm_CallContinuation(ScmObj cont, ScmObj ret)
{
- jmp_buf *env;
+ struct continuation_frame *frame;
- env = CONTINUATION_JMPENV(cont);
+ frame = CONTINUATION_FRAME(cont);
- if (env != INVALID_CONTINUATION_OPAQUE
+ if (frame != INVALID_CONTINUATION_OPAQUE
#if SCM_NESTED_CONTINUATION_ONLY
&& CONTINUATIONP(continuation_stack_unwind(cont))
#endif
)
{
- exit_dynamic_extent(CONTINUATION_DYNEXT(cont));
+ /*
+ * Don't refer cont because it may already be invalidated by
+ * continuation_stack_unwind().
+ */
+ exit_dynamic_extent(frame->dyn_ext);
continuation_thrown_obj = ret;
- longjmp(*env, 1);
+ longjmp(*frame->env, 1);
/* NOTREACHED */
} else {
ERR("Scm_CallContinuation: called expired continuation");
Modified: branches/r5rs/sigscheme/storage.c
===================================================================
--- branches/r5rs/sigscheme/storage.c 2005-11-07 20:46:35 UTC (rev 2075)
+++ branches/r5rs/sigscheme/storage.c 2005-11-07 21:25:44 UTC (rev 2076)
@@ -77,7 +77,7 @@
#endif
#if !SCM_OBJ_COMPACT
-/* SCM_OBJ_COMPACT MUST NOT refer these variables. Use SCM_NULL and so on.
+/* SCM_OBJ_COMPACT MUST NOT refer these variables. Use SCM_NULL and so on. */
/* constants */
ScmObj SigScm_null, SigScm_true, SigScm_false, SigScm_eof;
@@ -292,8 +292,8 @@
ScmObj obj = SigScm_NewObjFromHeap();
SCM_ENTYPE_CONTINUATION(obj);
- SCM_CONTINUATION_SET_OPAQUE0(obj, INVALID_CONTINUATION_OPAQUE);
- SCM_CONTINUATION_SET_OPAQUE1(obj, INVALID_CONTINUATION_OPAQUE);
+ SCM_CONTINUATION_SET_OPAQUE(obj, INVALID_CONTINUATION_OPAQUE);
+ SCM_CONTINUATION_SET_TAG(obj, 0);
return obj;
}
More information about the uim-commit
mailing list