diff --git a/src/core/stack.rs b/src/core/stack.rs index e3aab6f..6b596f1 100644 --- a/src/core/stack.rs +++ b/src/core/stack.rs @@ -243,6 +243,7 @@ macro_rules! define_stack_value { fmt_dump($dump_self:pat, $f:pat) = $fmt_dump_body:expr, $cast:ident($cast_self:pat): $cast_res:ty = $cast_body:expr, $into:ident$(,)? + $({ $($other:tt)* })? } ),*$(,)?}) => { #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] @@ -303,6 +304,8 @@ macro_rules! define_stack_value { fn $into(self: Box) -> Result> { Ok(self) } + + $($($other)*)? })* }; } @@ -395,6 +398,11 @@ define_stack_value! { fmt_dump(v, f) = write!(f, "WordList{{{:?}}}", &v as *const _), as_word_list(v): WordList = Ok(v), into_word_list, + { + fn into_cont(self: Box) -> Result> { + Ok(Box::new(self.finish())) + } + } }, SharedBox(SharedBox) = { eq(a, b) = { diff --git a/src/modules/control.rs b/src/modules/control.rs index 54945b3..4ea6b59 100644 --- a/src/modules/control.rs +++ b/src/modules/control.rs @@ -230,17 +230,19 @@ impl Control { #[cmd(name = ":_", active, args(active = false, prefix = true))] #[cmd(name = "::_", active, args(active = true, prefix = true))] fn interpret_colon(ctx: &mut Context, active: bool, prefix: bool) -> Result<()> { - let cont = ctx.stack.pop_cont()?; + thread_local! { + static CREATE_AUX: Cont = Rc::new((|ctx| interpret_create_aux(ctx, None)) as cont::ContextWordFunc); + }; + let name = ctx.input.scan_word()?.ok_or(UnexpectedEof)?; + let mode = (active as u8) | (prefix as u8) << 1; - define_word( - &mut ctx.dictionary, - name.data.to_owned(), - *cont, - DefMode { active, prefix }, - )?; + let cont = CREATE_AUX.with(|cont| cont.clone()); - ctx.stack.push_argcount(0, ctx.dictionary.make_nop()) + ctx.stack.push(name.data.to_owned())?; + ctx.stack.push_int(mode)?; + ctx.stack.push_int(2)?; + ctx.stack.push(cont) } #[cmd(name = "forget", args(word_from_stack = false))]