Adding Oofda & Poke, fix copyright notice.

Adding an experimental Object Sytem (Oofda).
Adding an experimental DI Framework (Poke).
This commit is contained in:
Brad Nelson
2023-05-24 21:00:40 -07:00
parent 8e46c227ac
commit 8c31cbd694
20 changed files with 796 additions and 10 deletions

View File

@ -0,0 +1,44 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test1.fs" cr
needs ../oofda.fs
class Foo
variable x
variable y
: .setX x ! ;
: .setY y ! ;
: .getX x @ ;
: .getY y @ ;
: .length2 this .getX dup * this .getY dup * + ;
: .construct 0 x ! 0 y ! ;
: .print ." x: " this .getX . ." y: " this .getY . cr ;
end-class
Foo .new .print
class Bar extends Foo
: .dude this .print this .print ;
end-class
Foo .new .print
Bar .new constant h
h .dude
123 h .setX 456 h .setY
h .dude
bye

View File

@ -0,0 +1,38 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test2.fs" cr
needs ../oofda.fs
class Foo
variable x
variable y
: .setX x ! ;
: .setY y ! ;
: .getX x @ ;
: .getY y @ ;
: .length2 this .getX dup * this .getY dup * + ;
: .print ." x: " this .getX . ." y: " this .getY . cr ;
end-class
class Bar extends Foo
: .dude this .print this .print ;
end-class
Bar .new constant h
123 h .setX 456 h .setY
h .dude
bye

View File

@ -0,0 +1,58 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test3.fs" cr
needs ../oofda.fs
class Pair
variable first
variable second
: .construct ( x y -- ) second ! first ! ;
: .unpair first @ second @ ;
end-class
class Coolness extends Pair
variable third
: .construct ( x y z -- ) super .construct third ! ;
: .unpair super .unpair third @ ;
end-class
123 456 Pair .new constant h
h .unpair . . cr
123 456 789 Coolness .new constant h2
h2 .unpair . . . cr
class Stack
variable sp
create start
100 cells this .grow
: .construct start sp ! ;
: .empty? ( -- f ) sp @ start @ = ;
: .push ( n -- ) sp @ ! cell sp +! ;
: .pop ( -- n ) this .empty? throw
cell negate sp +! sp @ @ ;
end-class
100 Stack .new constant s
123 s .push
234 s .push
345 s .push
s .pop . cr
s .pop . cr
s .pop . cr
bye

View File

@ -0,0 +1,39 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test4.fs" cr
needs ../lib/stack.fs
needs ../lib/queue.fs
100 Stack .new constant s
123 s .push
234 s .push
345 s .push
s .pop . cr
s .pop . cr
s .pop . cr
100 Queue .new constant q
123 q .push
234 q .push
q .pop . cr
345 q .push
q .pop . cr
456 q .push
q .pop . cr
q .pop . cr
bye

View File

@ -0,0 +1,39 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test5.fs" cr
needs ../lib/logging.fs
: @Inject ( "name" -- x )
bl parse
2dup s" Range" str= if 2drop 10 postpone literal exit then
2dup s" Logger" str= if 2drop postpone ConsoleLogger postpone .new exit then
-1 throw
; immediate
class Counter
value log
value range
: .construct @Inject Range to range
@Inject Logger to log ;
: .doit ( n -- ) s" Counter at: " log .logString log
.logNumber log .cr ;
: .run range 0 do i 1+ this .doit loop ;
end-class
Counter .new .run
bye

View File

@ -0,0 +1,28 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test6.fs" cr
needs ../lib/array.fs
10 Array .new constant a
1 a .append
2 a .append
3 a .append
1 a .get . cr
bye

View File

@ -0,0 +1,55 @@
#! /usr/bin/env ueforth
\ Copyright 2023 Bradley D. Nelson
\
\ Licensed under the Apache License, Version 2.0 (the "License");
\ you may not use this file except in compliance with the License.
\ You may obtain a copy of the License at
\
\ http://www.apache.org/licenses/LICENSE-2.0
\
\ Unless required by applicable law or agreed to in writing, software
\ distributed under the License is distributed on an "AS IS" BASIS,
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\ See the License for the specific language governing permissions and
\ limitations under the License.
." test7.fs" cr
needs ../poke.fs
needs ../lib/logging.fs
class Counter
value log
value range
m: .provideRange
m: .provideLogger
m: .logString
m: .logNumber
m: .cr
: .construct @Inject Range to range
@Inject Logger to log ;
: .doit ( n -- ) s" Counter at: " log .logString
log .logNumber log .cr ;
: .run range 0 do i 1+ this .doit loop ;
end-class
class CountingModule
: .provideCounter @Singleton Counter .new ;
: .provideRange 10 ;
end-class
class LoggingModule
\ : .provideLogFilename s" log.txt" ;
\ : .provideLogger @Singleton @Inject LogFilename FileLogger .new ;
: .provideLogger @Singleton ConsoleLogger .new ;
end-class
class ProgramComponent extends Component
: .construct super .construct
LoggingModule this .include
CountingModule this .include ;
end-class
ProgramComponent .new .provideCounter .run
bye