EightBall/sieve4.8b
Bobbi Webber-Manners 92164c3274
v0.60: Array pass by reference works in compiler
- Evaluating 'naked' array name `A` gives pointer to payload (same as `&A` or even `&A[0]`)
- Improved loading message in VM
- Got array pass-by-reference to work in compiler
- Fixed eval stack leak in array initialization code generated by compiler
2018-05-03 19:53:40 -04:00

48 lines
715 B
Plaintext

' Sieve of Eratosthenes
byte A[20*20] = 1
call doall(20, A)
end
sub doall(word nr, byte array[])
word n = nr * nr
pr.msg "Sieve of Eratosthenes ..."
pr.msg "nr is "; pr.dec nr; pr.nl
call sieve(n, nr, array)
call printresults(n, array)
return 0
endsub
sub sieve(word n, word nr, byte AA[])
pr.msg "Sieve"
word i = 0; word j = 0
for i = 2 : (nr - 1)
if AA[i]
j = i * i
while (j < n)
AA[j] = 0
j = j + i
endwhile
endif
endfor
return 0
endsub
sub printresults(word n, byte AA[])
word i = 0
for i = 2 : (n - 1)
if AA[i]
if i > 2
pr.msg ", "
endif
pr.dec i
endif
endfor
pr.msg "."
pr.nl
return 0
endsub