NEGATE/MAX/MIN implemented in forth, not builtins

This commit is contained in:
David 2021-02-20 18:15:09 -05:00
parent a75db93581
commit 7251f1ba60

View File

@ -43,7 +43,10 @@ func main() {
dict.AddWord("/MOD", Word{Name: "/MOD", Impl: b.DivMod(&stack)})
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 DUP DUP - SWAP - THEN"}})
dict.AddWord("ABS", Word{Name: "ABS", Source: []string{"DUP", "0<", "IF", "NEGATE", "THEN"}})
dict.AddWord("NEGATE", Word{Name: "NEGATE", Source: []string{"DUP", "DUP", "-", "SWAP", "-"}})
dict.AddWord("MAX", Word{Name: "MAX", Source: []string{"OVER", "OVER", "<", "IF", "SWAP", "THEN", "DROP"}})
dict.AddWord("MIN", Word{Name: "MIN", Source: []string{"OVER", "OVER", ">", "IF", "SWAP", "THEN", "DROP"}})
// output
dict.AddWord(".", Word{Name: ".", Impl: b.Print(os.Stdout, &stack)})
dict.AddWord("EMIT", Word{Name: "EMIT", Impl: b.Emit(os.Stdout, &stack)})