A number of small changes that help to improve the source code structure. In particular multi level exits, fwd jumps and colon-separated statements. I hope to illustrate these over the next few posts. The code below shows how contracts (essentially defining and testing a function's inputs and outputs) can be controlled - activated for testing then omitted when no longer needed in the final code. It also makes use of some of the new features.
Oxygen Update
http://community.thinbasic.com/index.php?topic=1845.0
from test_preproc.tbasic
[code=thinbasic]
uses "Oxygen"
uses "File"
dim vv as long
dim src as string
src="
; contract blocks
;
indexers esi offset 0 ascending : esi=dataspace 400 ' static space
def check1 ; skip ' remove the semicolon to skip all blocks headed 'check1'
proc myfunc 1 0 3 4 ' our test function
ret ' end of prog
;
myfunc:
(
push ebp : mov ebp,esp : sub esp,100 ' stack space for locals
indexers ebp offset 8 ascending var 4 a b c d ' parameters
indexers ebp offset 0 descending var 4 i j k m ' locals
check1 ' contract block
(
cmp a, 0 : jz fwd error ' fwd ensures forward jump to the next error label
cmp a, 10 : jg fwd error
cmp a,-10 : jl fwd error
cmp b, 0 : jz fwd error
cmp b, 10 : jg fwd error
cmp b,-10 : jl fwd error
)
;
;... main body of function
;
[#vv]=0 : jmp fwd finish ' no errors detected so go to next finish
;
error: [#vv]=666 ' error const
finish: mov esp,ebp : pop ebp ' release local stack space
ret 16 ' return releasing params from stack
)
"
'file_save("t.txt",o2_view (src))
'msgbox 0,"ZM26: "+o2_error+o2_view (src) : stop
o2_asmo src : if len(o2_error) then msgbox 0,"ZM26: "+o2_error+o2_view (src) : stop
o2_exec : msgbox 0,"0x"+str$(vv) : stop
[/code]
Bookmarks