Compatibility
tiko is compatible with FreeBASIC: it implements FreeBASIC's fb dialect,
and a great deal of existing FreeBASIC code compiles with it unchanged. This
section is for reading and bringing over that code. It shows the older forms
tiko still accepts, the ones it refuses, and what modern tiko code writes
instead. Everywhere else on this site the modern forms are used.
Older code usually lives in .bas files, with .bi headers. tiko compiles a
.bas file exactly as it compiles a .tiko one:
'' Older code that tiko still compiles: a .bas file, the legacy
'' string type, long and integer, while ... wend, + to join strings.
dim as string names(1 to 3)
names(1) = "ada" : names(2) = "grace" : names(3) = "alan"
dim as long i = 1
dim as integer total = 0
while i <= 3
print ucase(left(names(i), 1)) + mid(names(i), 2)
total = total + len(names(i))
i = i + 1
wend
print "letters:"; total
Output
Ada
Grace
Alan
letters: 12
The same program, written the way the rest of this site writes it:
'' The same program as modern tiko writes it.
dim names( 1 to 3 ) as ustring = { "ada", "grace", "alan" }
dim as int32 total = 0
for each n in names
print ucase( left( n, 1 ) ) & mid( n, 2 )
total += len( n )
next
print "letters:"; total
Output
Ada
Grace
Alan
letters: 12
| Older form | Modern tiko |
|---|---|
.bas sources, .bi headers | .tiko sources, .ti headers |
string | ustring, which holds text rather than bytes (next pages) |
long, integer | int32, int64; integer only where pointer size is the point |
while … wend | do while … loop |
+ to join strings | &, which also converts numbers |
| a counter and a loop | for each, and arrays with initialisers |
FreeBASIC has several dialects, chosen with #lang; tiko implements fb
only. Code that asks for another is refused:
'' Older code sometimes asks for an older dialect. tiko has one.
#lang "qb"
print "hello"
dialect.bas(2,1): error TKO0317: unsupported language mode 'qb'; tiko-lang implements "fb" only
|
2 | #lang "qb"
| ^
Code written for the qb or fblite dialects has to be brought across to
fb. The pages that follow cover the forms that matter most: inline
data, jumps and subroutines, and type suffixes and the
two string types.
Activities
- Rewrite
classic.baswithdo while … loopand&, keeping the.basextension, and check it still compiles. - Rename
classic.bastoclassic.tiko. Does anything change?