FreeBASIC - A 32-bit BASIC Compiler for DOS, Windows and Linux
Copyright (C) 2004-2005 Andre Victor T. Vicentini


Contents


License
:

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program;
if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA.


Most Important Features:

o BASIC Compatibility:

- FreeBASIC is not a "new" BASIC language. It is not required of you to learn
anything new if you are familiar with any Microsoft-BASIC variant.

- FreeBASIC is case-insensitive; scalar variables don't need to be dimensioned and
suffix can be used; line numbers are supported; MAIN function is no required;
most of the graphic and console statements and functions found in MS-QuickBASIC were
implemented, et cetera.

o Clean Syntax:

- Only a small number of keywords have been added. All functions are implemented
as libraries, so for the most part, there are no new intrinsic routines, and
therefore there is a low chance of having name duplication with old code. If you
want to show up a message box in Windows, simply do:

'$include: 'win\user32.bi'
MessageBox NULL, "Title", "Text", MB_ICONASTERISK

(note: MessageBox is case-insensitive, it can be MESSAGEBOX if you want)

o A large number of variable types available, like BYTE/SHORT/INTEGER, SINGLE/DOUBLE and STRING:

- All integer types have unsigned versions (UBYTE/USHORT/UINTEGER).

- Strings can be fixed or variable-length (up to 2GB long).

o User-defined Types (UDT's):

- Unlimited nesting.

- BASIC's TYPE statement is supported, along with the new UNION statement (including
nameless nested UNION's).

TYPE MyType
A AS SHORT
B AS INTEGER
C AS LONG
D AS OtherUDT
UNION
E AS DOUBLE
F AS SINGLE
G AS OtherUDT
END UNION
H AS BYTE
END TYPE

Or,

UNION MyUnion
A AS INTEGER
B AS INTEGER
C AS DOUBLE
END UNION

- Array fields utilizing up to four dimensions can be used. For example,

TYPE MyList
ListData(0 TO MAXITEMS - 1) AS MyItem
END TYPE

- Function field types:

TYPE MyType
MyFunction AS FUNCTION (BYVAL ArgumentA AS INTEGER) AS INTEGER
END TYPE

o Enumerations (ENUM's):

ENUM MyEnum
A
B = 3
C
END ENUM

DIM E AS MyEnum

E = C

o Arrays:

- Dynamic and static arrays are supported, up to 2 GB in size.

- Unlimited number of array dimensions.

- Any lower and upper boundaries.

- REDIM PRESERVE statement is supported to resize any dynamic array and keep its
contents intact.

o Pointers:

- Pointers to any of the data types listed above, including UDT's and arrays.

- Uses the same syntax as C/C++. For example,

TYPE Node
PreviousNode AS Node POINTER
NextNode AS Node POINTER
END TYPE

DIM CurrentNode AS Node POINTER
CurrentNode->NextNode->PreviousNode = NULL

DIM A AS SHORT POINTER, B AS SHORT POINTER, C AS SHORT POINTER POINTER
*A = *B \ **C

- Unlimited indirection levels (e.g., pointer to pointer to ...)

- Function pointers:

DIM MyPointer AS SUB(BYVAL ArgumentA AS INTEGER, BYVAL ArgumentB AS DOUBLE)
DIM OtherPointer AS FUNCTION(BYVAL ArgumentA AS INTEGER)

MyPointer = PROCPTR(RealSub)
MyPointer (1, 2)

SUB RealSub(BYVAL ArgumentA AS INTEGER, BYVAL ArgumentB AS DOUBLE)
Result = ArgumentA * ArgumentB
END SUB

o Optional function arguments (numeric only):

DECLARE SUB Test(A AS DOUBLE = 12.345, BYVAL B AS BYTE = 255)

Test
Test , 128
Test ,
Test 44,
Test 44
Test ( )

et cetera.

o Inline Assembly:

- Intel syntax.

- Reference variables directly by name; no "trick code" needed.

o Preprocessor:

- Same syntax as in C (including #DEFINE's with arguments):

#DEFINE SOMEDEF 1234
#DEFINE OTHERDEF 5678
#IFDEF SOMEDEF
# IF NOT DEFINED(OTHERDEF)
# DEFINE OTHERDEF SOMEDEF
# ELSE
# IF OTHERDEF <> SOMEDEF
# UNDEF OTHERDEF
# DEFINE OTHERDEF SOMEDEF
# ENDIF
# ENDIF
#ELSE
# DEFINE OTHERDEF 5678
#ENDIF
#PRINT OTHERDEF

#DEFINE bar(x,y) ((x) * (y))
#DEFINE foo(x,y) bar(x-y,y-x)
a = foo(b, c)

o Escape characters inside literal strings:

- Same as in C (except numbers are interpreted as decimal numbers).
Use the OPTION ESCAPE statement to turn this behavior on or off.

OPTION ESCPAPE
PRINT "\"Hello from FreeBASIC!\""

o Create OBJ's, LIB's, DLL's, and console or GUI EXE's:

- You are in no way locked to an IDE or editor of any kind.

- You can create static and dynamic libraries adding just one command-line
option (-lib or -dll).

o As a 32-bit application:

- FreeBASIC can compile source code files up to 2 GB long.

- The number of symbols (variables, constants, et cetera) is only limited by the
total memory available during compile time. (You can, for example, include
OpenGL, SDL, BASS, and Windows 32-bit API simultaneously in your source code.)

o Optimized code generation:

- While FreeBASIC is not an optimizing compiler, it does many kinds of general
optimizations to generate the fastest possible code on x86 CPU's, not losing
to other BASIC alternatives, including many commercial ones.

o Completely free:

- All third-party tools are also free. No piece of abandoned of copyrighted
software is used (but GoRC on Win32). The assembler, linker, archiver, and
other command-line applications come from the GNU binutil programming tools.

o Portability:

- The run-time library is being written with portability in mind. Operating
system-dependent functions are separated to make porting the compiler
easy.

- The compiler is written in 100% FreeBASIC code (FreeBASIC compiles itself.)
As all modules are independent, porting to other operating systems on the
x86 platform won't be too difficult.

- All tools used in the creation of FreeBASIC exist on most operating systems
already as they are from the GNU binutils.

- FreeBASIC currently runs on 32-bit Windows, Linux, and MS-DOS.


What FreeBASIC Isn't:

o FreeBASIC is not a QuickBASIC clone, neither an emulator.

- DEF SEG, PEEK and POKE to absolute 16-bit memory locations and many
old and deprecated statements, that are seldom used today, were not
implemented, read the docs/keywords.txt file for a list of differences.

- While FB is certainly the BASIC compiler that most reassembles the Microsoft
BASIC compilers for DOS, don't expect to compile old source-codes filled with
unsupported statements or external libraries, they won't be compiled.

o FreeBASIC is not a Visual Basic alternative.

- There are no events, or any GUI wrapper of any kind. (You can create them
easily with UDT's and function pointers.)

o FreeBASIC is most certainly not bug free, as with any other program.

- The FreeBASIC project was started in September 2004, and was not/is not tested
enough.


Possible Additions to Later Versions:

o Full debug support using GDB/Insight

o TYPEDEF's

o Variable initializers:

DIM MyVariable AS SomeType = { InitialValue, ... }

o CLASS data structure (for object-oriented programming):

- GUI code would be much easier to write.

o More optimizations:

- Common sub-expression elimination: QB 4.5 and later had this type
of optimization 16 years ago. Today, you can't find any BASIC compiler that
utilizes this type of optimization - not even PowerBASIC, known as the BASIC
compiler that generates the fastest code.

- Direct Acyclic Graph (DAG) module has already been coded. All that remains is
getting it to work with the Intermediate Representation (IR) module.
'-----------------------------------------------------------------------------------------------------------------------