Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Classes/Forth/classes-1.fth
Normal file
14
Task/Classes/Forth/classes-1.fth
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
:class MyClass <super Object
|
||||
|
||||
int memvar
|
||||
|
||||
:m ClassInit: ( -- )
|
||||
ClassInit: super
|
||||
1 to memvar ;m
|
||||
|
||||
:m ~: ( -- ) ." Final " show: [ Self ] ;m
|
||||
|
||||
:m set: ( n -- ) to memvar ;m
|
||||
:m show: ( -- ) ." Memvar = " memvar . ;m
|
||||
|
||||
;class
|
||||
1
Task/Classes/Forth/classes-2.fth
Normal file
1
Task/Classes/Forth/classes-2.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
MyClass newInstance
|
||||
1
Task/Classes/Forth/classes-3.fth
Normal file
1
Task/Classes/Forth/classes-3.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
New> MyClass value newInstance
|
||||
2
Task/Classes/Forth/classes-4.fth
Normal file
2
Task/Classes/Forth/classes-4.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10 set: newInstance
|
||||
show: newInstance
|
||||
2
Task/Classes/Forth/classes-5.fth
Normal file
2
Task/Classes/Forth/classes-5.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
newInstance dispose
|
||||
0 to newInstance \ no dangling pointers!
|
||||
5
Task/Classes/Forth/classes-6.fth
Normal file
5
Task/Classes/Forth/classes-6.fth
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
: test { \ obj -- }
|
||||
New> MyClass to obj
|
||||
show: obj
|
||||
1000 set: obj
|
||||
obj dispose ;
|
||||
31
Task/Classes/Forth/classes-7.fth
Normal file
31
Task/Classes/Forth/classes-7.fth
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
include FMS-SI.f
|
||||
|
||||
:class foo \ begin class foo definition
|
||||
ivar x \ declare an instance variable named x
|
||||
:m put ( n -- ) x ! ;m \ a method/message definition
|
||||
:m init: 10 self put ;m \ the constructor method
|
||||
:m print x ? ;m \ a print method for x
|
||||
;class \ end class foo definition
|
||||
|
||||
foo f1 \ instantiate a foo object, in the dictionary, named f1
|
||||
f1 print \ 10 send the print message to object f1
|
||||
20 f1 put \ send a message with one parameter to the object
|
||||
f1 print \ 20
|
||||
|
||||
|
||||
: bar \ bar is a normal Forth function definition
|
||||
heap> foo \ instantiate a nameless object in the heap
|
||||
dup print
|
||||
30 over put
|
||||
dup print
|
||||
<free ; \ destroy the heap object
|
||||
|
||||
: bar' \ bar' is an alternative to bar that uses a local variable
|
||||
heap> foo {: f :}
|
||||
f print
|
||||
30 f put
|
||||
f print
|
||||
f <free ;
|
||||
|
||||
bar \ 10 30
|
||||
bar' \ 10 30
|
||||
Loading…
Add table
Add a link
Reference in a new issue