|
36 | 36 | #include "sagittarius/private/core.h" |
37 | 37 | #include "sagittarius/private/closure.h" |
38 | 38 | #include "sagittarius/private/error.h" |
| 39 | +#include "sagittarius/private/exceptions.h" |
39 | 40 | #include "sagittarius/private/file.h" |
40 | 41 | #include "sagittarius/private/generic.h" |
41 | 42 | #include "sagittarius/private/hashtable.h" |
|
45 | 46 | #include "sagittarius/private/pair.h" |
46 | 47 | #include "sagittarius/private/port.h" |
47 | 48 | #include "sagittarius/private/transcoder.h" |
| 49 | +#include "sagittarius/private/record.h" |
48 | 50 | #include "sagittarius/private/reader.h" |
49 | 51 | #include "sagittarius/private/string.h" |
50 | 52 | #include "sagittarius/private/symbol.h" |
@@ -139,6 +141,46 @@ static void vm_print(SgObject obj, SgPort *port, SgWriteContext *ctx) |
139 | 141 |
|
140 | 142 | SG_DEFINE_BUILTIN_CLASS_SIMPLE(Sg_VMClass, vm_print); |
141 | 143 |
|
| 144 | +static SgClass *violation_cpl[] = { |
| 145 | + SG_VIOLATION_CPL, |
| 146 | + NULL |
| 147 | +}; |
| 148 | + |
| 149 | +static void cont_violation_printer(SgObject o, SgPort *p, SgWriteContext *ctx) |
| 150 | +{ |
| 151 | + Sg_Printf(p, UC("#<&continuation %S>"), |
| 152 | + SG_CONTINUATION_VIOLATION_PROMPT_TAG(o)); |
| 153 | +} |
| 154 | + |
| 155 | +static SgObject cont_violation_allocate(SgClass *klass, SgObject initargs) |
| 156 | +{ |
| 157 | + SgContinuationViolation *c = SG_ALLOCATE(SgContinuationViolation, klass); |
| 158 | + SG_SET_CLASS(c, klass); |
| 159 | + return SG_OBJ(c); |
| 160 | +} |
| 161 | + |
| 162 | +static void cont_violation_tag_set(SgContinuationViolation *c, SgObject tag) |
| 163 | +{ |
| 164 | + if (!SG_CONTINUATION_VIOLATIONP(c)) { |
| 165 | + Sg_Error(UC("&continuation required but got %S"), c); |
| 166 | + } |
| 167 | + SG_CONTINUATION_VIOLATION_PROMPT_TAG(c) = tag; |
| 168 | +} |
| 169 | + |
| 170 | +static SgObject cont_violation_tag(SgContinuationViolation *c) |
| 171 | +{ |
| 172 | + return SG_CONTINUATION_VIOLATION_PROMPT_TAG(c); |
| 173 | +} |
| 174 | + |
| 175 | +static SgSlotAccessor cont_violation_slot[] = { |
| 176 | + SG_CLASS_SLOT_SPEC("prompt-tag", 0, cont_violation_tag, cont_violation_tag_set), |
| 177 | + {{ NULL }} |
| 178 | +}; |
| 179 | + |
| 180 | +SG_DEFINE_BASE_CLASS(Sg_ContinuationViolationClass, SgContinuationViolation, |
| 181 | + cont_violation_printer, NULL, NULL, cont_violation_allocate, |
| 182 | + violation_cpl); |
| 183 | + |
142 | 184 | static SgObject copy_generics(SgObject lib) |
143 | 185 | { |
144 | 186 | SgObject h = SG_NIL, t = SG_NIL, gs; |
@@ -3409,6 +3451,14 @@ void Sg__PostInitVM() |
3409 | 3451 | if (SG_UNBOUNDP(b)) { |
3410 | 3452 | Sg_Panic("`raise` was not found."); |
3411 | 3453 | } |
| 3454 | + SG_INIT_CONDITION(SG_CLASS_CONTINUATION_VIOLATION, lib, "&continuation", |
| 3455 | + cont_violation_slot); |
| 3456 | + SG_INIT_CONDITION_PRED(SG_CLASS_CONTINUATION_VIOLATION, lib, |
| 3457 | + "continuation-violation?"); |
| 3458 | + SG_INIT_CONDITION_CTR(SG_CLASS_CONTINUATION_VIOLATION, lib, |
| 3459 | + "make-continuation-violation", 1); |
| 3460 | + SG_INIT_CONDITION_ACC(cont_violation_tag, lib, |
| 3461 | + "&continuation-violation-prompt-tag"); |
3412 | 3462 | raise_proc = SG_GLOC_GET(SG_GLOC(b)); |
3413 | 3463 | b = Sg_FindBinding(lib, SG_INTERN("raise-continuable"), SG_UNBOUND); |
3414 | 3464 | if (SG_UNBOUNDP(b)) { |
|
0 commit comments