Last active
February 7, 2021 22:55
-
-
Save righ1113/e4649d026c7b3b288ad5ea94d4acfc9b to your computer and use it in GitHub Desktop.
Forth でオブジェクト指向
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \ s" oop.f" included | |
| require /snap/gforth/15/share/gforth/0.7.9_20201105/objects.fs | |
| object class \ "object" is the parent class | |
| selector hoge | |
| selector hoge2 | |
| selector foo | |
| selector setCr | |
| end-class myCls' | |
| myCls' class \ "myCls'" is the parent class | |
| cell% field cr | |
| :noname | |
| cr ! ; | |
| overrides construct | |
| :noname ( x myCls -- x+cr ) | |
| cr @ + ; | |
| overrides hoge | |
| :noname ( x myCls -- x cr ) | |
| cr @ ; ( @ がスタック上の myCls も消す ) | |
| overrides hoge2 | |
| :noname ( x myCls -- x+1 ) | |
| drop 1 + ; | |
| overrides foo | |
| :noname ( x myCls -- ) | |
| cr ! ; ( ! がスタック上の myCls も消す ) | |
| overrides setCr | |
| end-class myCls | |
| ( 7 myCls heap-new constant myObj ) | |
| ( 100 myObj hoge ) | |
| ( 17 myObj setCr ) | |
| \ おまけ | |
| : fib ( cnt -- cnt .. ) | |
| dup 0 +do | |
| i 2 < if 1 else 2dup + then | |
| 1 +loop ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment