Close

Towards the bytecode

A project log for Terminal-BASIC

Language interpreter for uC-based systems

andrey-skvortsovAndrey Skvortsov 01/24/2020 at 00:160 Comments

One of the controversial features of Terminal-BASIC is the architecture of functional modules. The commands and functions defined in the modules, which are chained together in some order (except the very basic commands which are part of the language core). This simplifies language core, parser and lexer, also simplifies the creation of the new commands and functions, separates the functional groups from each other and so on. But the dark side drawback is that execution of the commands is slow and the more commands the slower it is. Moreover, the commands at the end of the chain are being executed slower then commands from the chain begin.

In order to solve the speed issue, I introduced the command parsing step in the tokenization of the source code process. The commands calls contains the platform address of the implementation C-function. The call runs faster and no matter how many commands and modules are defined. Tokenization of the source includes change of the keyword strings by the binary KW codes, replace the number constants strings by the parsed binary numbers and now it also contains bytecode-like feature of replacing commands calling strings by the call command and the implementation address. This is optional feature, enabled by default in TB 2.2-alpha1 version.

If the approach proves it's success, I will do the same for the functions from external modules.

Discussions