FlagVM/flagpole/fvmstd.fp

99 lines
1.3 KiB
GLSL

proc putchar
0xCFFFFFFFFFFFFFFD st8
endproc
proc getchar
0xCFFFFFFFFFFFFFFE ld8
endproc
proc getuint
0 @val
0 @char
while 1 do
:getchar @char
if &char 0x30 u< then
&val return
endif
if &char 0x39 u> then
&val return
endif
&val
10 u*
&char 0x30 u- u+
@val
endwhile
&val
endproc
proc getint
0 @val
0 @char
0 @isNegative
0 @hasNumber
while 1 do
0 @skip
:getchar @char
if &char 0x2D == &hasNumber not band then
1 @isNegative
1 @skip
endif
if &char 0x30 i< &char 0x39 i> bor &skip not band then
if &isNegative then
0 &val i- return
endif
&val return
endif
if &skip not then
1 @hasNumber
&val
10 i*
&char 0x30 i- i+
@val
endif
endwhile
endproc
proc putuint
@val
if &val 0 == then
48 :putchar return
endif
1 @divisor
while &val &divisor u/ 9 u> do
&divisor 10 u* @divisor
endwhile
while &divisor 0 u> do
&val &divisor u/ 10 u%
48 u+ :putchar
&divisor 10 u/ @divisor
endwhile
endproc
proc putint
@val
if &val 0 i< then
0x2D :putchar
0 &val i- @val
endif
&val :putuint
endproc
proc puts
while dup ld8 0 == not do
dup ld8 :putchar
1 u+
endwhile
drop
endproc
proc newline
10 :putchar
endproc