1
0
mirror of https://github.com/KarolS/millfork.git synced 2026-04-21 09:16:34 +00:00

Function pointers – initial version

This commit is contained in:
Karol Stasiak
2019-07-27 00:58:10 +02:00
parent be9d27e2ee
commit 35ba36ce11
21 changed files with 399 additions and 26 deletions
+2
View File
@@ -6,6 +6,8 @@
* [Fizzbuzz](crossplatform/fizzbuzz.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC/MSX) everyone's favourite programming task
* [Fizzbuzz 2](crossplatform/fizzbuzz2.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC/MSX) an alternative, more extensible implemententation of fizzbuzz
* [Text encodings](crossplatform/text_encodings.mfk) (C64/ZX Spectrum) examples of text encoding features
* [Echo](crossplatform/echo.mfk) (C64/C16/ZX Spectrum/PC-88/MSX) simple text input and output
+38
View File
@@ -0,0 +1,38 @@
import stdio
bool divisible3(byte x) = x %% 3 == 0
bool divisible5(byte x) = x %% 5 == 0
struct stage {
function.byte.to.bool predicate
pointer text
}
// can't put text literals directly in struct constructors yet
array fizz = "fizz"z
array buzz = "buzz"z
array(stage) stages = [
stage(divisible3.pointer, fizz),
stage(divisible5.pointer, buzz)
]
void main() {
byte i, s
bool printed
for i,1,to,100 {
printed = false
for s,0,until,stages.length {
if call(stages[s].predicate, i) {
printed = true
putstrz(stages[js].text)
}
}
if not(printed) {
putword(i)
}
putchar(' ')
}
}