fix silly word collision with -1 built-in
This commit is contained in:
parent
6c5df444da
commit
953764004d
4
eval.go
4
eval.go
@ -72,13 +72,13 @@ func (c *Context) Exec(w Word) error {
|
||||
// we have an implementation for that word. Run it.
|
||||
err := w.Impl()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("error during built-in: %w", err)
|
||||
}
|
||||
} else if len(w.Source) != 0 {
|
||||
// user-defined word; let's descend...
|
||||
err := c.Eval(strings.Join(w.Source, " ") + " ")
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("error during nested evaluation of word %+v: %w", w, err)
|
||||
}
|
||||
} else {
|
||||
it, err := strconv.Atoi(w.Name)
|
||||
|
4
main.go
4
main.go
@ -41,8 +41,8 @@ func main() {
|
||||
dict.AddWord("/", Word{Name: "/", Impl: b.Div(&stack)})
|
||||
dict.AddWord("MOD", Word{Name: "MOD", Impl: b.Mod(&stack)})
|
||||
dict.AddWord("/MOD", Word{Name: "/MOD", Source: []string{"2DUP", "MOD", "ROT", "ROT", "/"}})
|
||||
dict.AddWord("+1", Word{Name: "+1", Source: []string{"1", "+"}})
|
||||
dict.AddWord("-1", Word{Name: "-1", Source: []string{"1", "-"}})
|
||||
dict.AddWord("1+", Word{Name: "1+", Source: []string{"1", "+"}})
|
||||
dict.AddWord("1-", Word{Name: "1-", Source: []string{"1", "-"}})
|
||||
dict.AddWord("ABS", Word{Name: "ABS", Source: []string{"DUP", "0<", "IF", "NEGATE", "THEN"}})
|
||||
dict.AddWord("NEGATE", Word{Name: "NEGATE", Source: []string{"-1", "*"}})
|
||||
dict.AddWord("MAX", Word{Name: "MAX", Source: []string{"2DUP", "<", "IF", "SWAP", "THEN", "DROP"}})
|
||||
|
Loading…
Reference in New Issue
Block a user