NEGATE/MAX/MIN implemented in forth, not builtins
This commit is contained in:
parent
a75db93581
commit
7251f1ba60
5
main.go
5
main.go
@ -43,7 +43,10 @@ func main() {
|
|||||||
dict.AddWord("/MOD", Word{Name: "/MOD", Impl: b.DivMod(&stack)})
|
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("-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
|
// output
|
||||||
dict.AddWord(".", Word{Name: ".", Impl: b.Print(os.Stdout, &stack)})
|
dict.AddWord(".", Word{Name: ".", Impl: b.Print(os.Stdout, &stack)})
|
||||||
dict.AddWord("EMIT", Word{Name: "EMIT", Impl: b.Emit(os.Stdout, &stack)})
|
dict.AddWord("EMIT", Word{Name: "EMIT", Impl: b.Emit(os.Stdout, &stack)})
|
||||||
|
Loading…
Reference in New Issue
Block a user