Skip to content

Commit

Permalink
Fix colon command
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 2, 2023
1 parent bc8afc3 commit 8091028
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/core/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -303,6 +304,8 @@ macro_rules! define_stack_value {
fn $into(self: Box<Self>) -> Result<Box<$ty>> {
Ok(self)
}

$($($other)*)?
})*
};
}
Expand Down Expand Up @@ -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<Self>) -> Result<Box<Cont>> {
Ok(Box::new(self.finish()))
}
}
},
SharedBox(SharedBox) = {
eq(a, b) = {
Expand Down
18 changes: 10 additions & 8 deletions src/modules/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down

0 comments on commit 8091028

Please sign in to comment.