# Compiling programs

Compiling a BASIC program converts the source code into
a list of binary instructions called object code.

The TCL run command initiates a program
called an interpreter that reads these instructions one at a time
and executes the desired actions. Taking this interpretive approach
allows swift translation from the BASIC source, platform independence,
small object size, and reasonable performance.

If better performance
is desired, the BASIC compiler can produce FlashBASIC, or native assembly
code from a standard BASIC object. This FlashBASIC code can subsequently
be run in the D3 environment in the same manner as a regular BASIC
program with the exception that FlashBASIC code runs significantly
faster.

Using the o option with the TCL compile or basic commands invokes FlashBASIC.
When complete, the native code produced is appended to the standard
interpreted object code. Because FlashBASIC generates independent
code, the code does not need to be recompiled when moved to a different
platform.

## Producing FlashBASIC without source

FlashBASIC
can be used on an application lacking source code by using the w option when compiling. Therefore, an applications vendor
does not need to ship source code or a new version of the object code.
Customers equipped with FlashBASIC can compile their current applications
as is. However, it is suggested that future applications be shipped
with a BASIC program, Proc, or macro, that automatically produces
the FlashBASIC code at the customer’s site.

Shipping FlashBASIC
code is only recommended when a vendor wishes the code to run on a
single platform, and when media size is not an issue.

## Compiler options

For a description of the
various compiler options, see [compile command](https://d3codex.com/tcl/compile-command/).

## Performance tips

- To obtain the best possible compile-time and run-time performance, Rocket recommends breaking up applications into small modules. Pick BASIC removes the traditional run-time overhead of large numbers of calls and is able to create more efficient code when modules are smaller. Furthermore, an application broken into several small modules takes considerably less time to compile than the same application stored in a single item.

- Avoid user exits. Standard FlashBASIC routines compiled with FlashBASIC run as fast, and possibly faster, than the same routines coded in virtual assembly.

- Avoid disk I/O. If an application has read-only tables, it is best to read all of them into memory at the beginning of the program rather than reading them bit-by-bit throughout execution. When reading an item, perform a matread into a dimensioned array, rather than using several readv statements.

Note: Source code is compiled to a tokenized object code which
is then interpreted when run. **For UNIX:** Source code can be
compiled in the traditional way, or it can be optimized or *flashed*. **For Windows:** Source code can also be compiled in the traditional
way, or it can be optimized or *flashed*. In this sense, though,
the source code is compiled to an optimal tokenized object code which
is then interpreted when run. This object code runs considerably faster
than the original tokenized object code, but not as fast as the assembly
language code of the C compiler.

## See also

- [# command](https://d3codex.com/flashbasicdebugger/pound-command/)
- [Access Query Language overview](https://d3codex.com/access/access-query-language-overview/)
- [basic command](https://d3codex.com/tcl/basic-command/)
- [BASIC/FlashBASIC Debugger](https://d3codex.com/flashbasicdebugger/basic-flashbasic-debugger/)
- [C functions overview](https://d3codex.com/cfunctions/c-functions-overview/)
- [call statement](https://d3codex.com/pickbasic-flashbasic/call-statement/)
- [common statement](https://d3codex.com/pickbasic-flashbasic/common-statement/)
- [compile command](https://d3codex.com/tcl/compile-command/)
- [Creating user-defined C functions (D3 UNIX)](https://d3codex.com/pickbasic-flashbasic/creating-user-defined-c-functions-d3-unix/)
- [down command](https://d3codex.com/flashbasicdebugger/down-command/)
- [execute statement (UNIX)](https://d3codex.com/pickbasic-flashbasic/execute-statement-unix/)
- [run command](https://d3codex.com/tcl/run-command/)
- [term command](https://d3codex.com/tcl/term-command/)
- [up command](https://d3codex.com/flashbasicdebugger/up-command/)
- [\ command](https://d3codex.com/flashbasicdebugger/backslash-command/)

---
Source: https://d3codex.com/pickbasic-flashbasic/compiling-programs/ - part of the D3Codex reference.
