Leonardus
README

Leonardus is licensed under the GNU General Public License v3.0.
See the LICENSE file for more details.

Project Goal

Leonardus is a minimalist, stack-based programming system designed as
a flexible framework for implementing and exploring algorithms. The syntax
and semantics of its scripting language, LeoScript, are inspired by
PostScript and Forth. It is extended with a prototype-based, object-oriented
paradigm and provides a concise and expressive environment for learning and
experimentation.

The project name is a nod to Leonardus Pisanus, who was named and
became known as Fibonacci.

Quick

For the documentation open the GitLab Pages of the project.
There you can find the latest user and developer information including the
parts generated from the source code files.

Alternatively look for it in the Docker image under
/usr/local/share/doc/leonardus/.

Type lc -h and lb -h to get command line help.

Docker Quick

The GitLab pipelines generate a Docker image on Docker hub. Pull the image
hagenbund2/leonardus and run it with:

‍docker run -it --rm hagenbund2/leonardus:latest

The CLI applications lc and lb will be available in the opening shell.

Or even execute the calculator within the docker image in one line with e.g.:

‍docker run --rm hagenbund2/leonardus lc 41 1 add

Quick Build

Install, if not already on your system:

  • the GNU C++ compiler,
  • git,
  • make,
  • flex,
  • the quadmath library,
  • the Boost library and
  • the GMP library

To build the artifacts and run all end2end tests:

‍make e2e

Optionally install Doxygen and LaTeX to generate the HTML documentation
and the man pages in ./public/ with:

‍make public

Quick Runs

To run an example:

‍make leon; make parser; ./lb Examples/Factorial.leo

To run all end2end tests:

‍make e2e

To run all examples:

‍make runxtest

Use it as a calculator:

‍lc 25346 95095 gcd
lc 1 2 1 33 { mul } for

Manifesto

Leonardus is an open-source project.

To use Leonardus, you can use the published Docker image or compile
the programs yourself.

The following interests could be addressed by the project:

  • A minimalist implementation of a stack-oriented programming language
  • The implementation of mathematical algorithms with a focus on cryptography
  • The execution of pre-built algorithms
  • The coding of the interaction between pre-built algorithms

The project and the code are written in English.
For mathematical operators, whose creation is a primary goal of the project,
multilingualism is enabled.

Readability and clarity of the program code take precedence over optimization
in the implementation.

All artifacts can be built with a minimal toolset. Currently, these are
the GNU C++ compiler, make, flex, Bash, Boost and git. The project is hosted
on GitLab, and the environment's features like CI/CD are used. However, a
build of all artifacts and tests must always be possible without GitLab.

Documentation is preferably embedded in the code and should be cleanly
extractable with Doxygen. All documentation is included in the git repository.

The main branch of the code must always allow a build of the artifacts
at the turn of the day, and these must pass the automated tests.

There is a constant refactoring of the code and documentation.

There is an extensive catalog of automated tests. When making design
decisions, the testability of a possible solution is given high priority.

No technical debt should be accumulated. Corresponding tickets always
have high priority.

Technologies

This project leverages the following core technologies:

  • GNU C++ 20: utilizing modern C++
  • git: for version control
  • GitLab with features: issues, pipelines, pages, releases, etc.
  • make: automating the build process for the command-line and for CI/CD
  • flex: generating the lexical analyzer
  • Bash: scripting for automating tasks
  • Doxygen: generating documentation for both the project's code and LeoScript
  • Markdown: a lightweight format for documentation.
  • quadmath: supporting 128-bit integers and 128-bit floating point numbers
  • LaTeX: enhancing the visual quality of Doxygen-generated documentation
  • Boost C++ library 1.83: for various extensions, e.g. asserts, unit testing
  • GNU Multiple Precision Arithmetic Library: as implementation of rational numbers

Optional tools:

  • cppcheck and clang-tidy: static analysis for code quality and
    bug prevention
  • KDevelop and/or Visual Studio Code: IDEs for efficient development
  • cloc: to get simple code metrics
  • lcov and gcov: do get and visualize test coverage data
  • Docker: we are building our own images to speed up GitLab CI/CD and we deploy a Leonardus image.
  • Docker Hub: to host our Docker images
  • draw.io: for diagrams
  • man pages: traditional console help texts

Recommendations:

  • Ghostscript: as reference implemenation of the PostScript language
    Hint: To invoke gs without rendering, you can set the environment
    variable export GS_DEVICE=nullpage.

Tools from the GitLab pipeline:

  • shellcheck: a Unix shell lint integrated in the GitLab pipeline
  • markdownlint-cli2: a markdown lint integrated in the GitLab pipeline
  • GitLab SAST: a GitLab-maintained security scanner for the pipeline

Glossary

Build Type

There are three build types for different software processes
and environments: DEVELOP PRODUCTION PROFILE

Core Code

If a LeoScript operator is coded directly in C++, it is referred to as core code.

leon

The second interpreter pass reads and interprets its leon-format input.

Leon-Format

The exchange format between the first interpreter pass called "parser"
und the second interpreter pass called "leon". Stored leon-format files
use the file name extension .leon

LeoScript

The stack-based scripting language and its file format of project Leonardus.
Each line of code can contain commands, which are short, case-sensitive
keywords, and operands, which are pushed onto a data stack and
manipulated by operators. The language supports various data types,
including integers, real numbers, booleans, strings, arrays, stacks and
dictionaries, and follows a reverse Polish notation (RPN) syntax, where
operators follow their operands.

Registered and Unregistered Core Code Operators

Most of the core code operators are referenced as values in the dictionaries
at start up time. They are called registered.
There are other core code operators for internal use. These are called
unregistered.

Operator

A subspecies of semantic objects, that operates on other semantic
objects, the stacks or the interpreter itself. Some of the operators are
LeoScript procedures and the others are core code.

Object Type Code -or- OTCode

A one character code for each SO class. The virtual ot() member function
of all SO classes return this code and allows explicit type-based decisions
beside the C++ language poylmorphisms.
See: object types

On Demand Optimizer -or- ODO

Optimzes LeoScript procedures as part of the bind operator.

parser

The first interpreter pass checks the syntax and converts the program
into leon-format.

Procedure Level

The procedure level counts the nesting level of curly braces in the
program code.

Property

For the classes Interpreter and Context there are attributes, together with
setters and getters, which change the behaviour. These properties can be set
with LeoScript operators.

Prototype-based Object -or- PTBO

To distinguish them from semantic objects (SOs), the objects at the LeoScript
level are referred to as prototype-based objects (PTBOs). They provide the
features of inheritance and encapsulation.

Red Book

The PostScript Red Book, officially titled "PostScript Language Reference,"
is the authoritative manual for the PostScript programming language,
detailing its syntax, semantics, and graphics operators.

We use it as a reference for the LeoScript operators, for which we have
explicitly established full compatibility in behavior.

Semantic Object -or- SO

Forth calls them words.

Task Tag

We use IDEA:, TODO: and FIXME: as Task Tags

Verbose Mode

All tools support a -v option to generate more run time information.

Vocabulary

A subdirectory as container of LeoScript files which creates one or more
functional related dictionaries if executed.

Files and Directories

File Types

Extension Description
cloc CLOC configuration
cpp, h C++ source
Dockerfile Docker configuration
drawio draw.io XML diagram
gcda profiling run data
gcno profiling structure information
html, css mostly generated HTML page
js, map, md5 generated HTML page helper
png, svg more generated HTML page helper
info lcov data
json JSON configuration for development tools
kdev4 Kdevelop configuration
leo LeoScript source
leon leon-format, the parser output
l, c flex source and generated C code
md Markdown documentation
out end-2-end test reference output
sh, inc Bash script
tpl Bash template
yml, yaml YAML data for CI/CD
none executables and some Bash scripts
Single Files Description
.gitignore git ignore
formual.repository generated HTML page helper
compile_flags.txt clang configuration
Doxyfile Doxygen configuration
LICENSE License ASCII text
makefile central build configuration
post-commit git configuration proposal

Directories of the git Repository

./Coverage
Test coverage data.

./Docker
Dockerfiles to build the images used in GitLab CI/CD.

./Examples
Example programs.

./Index
Source for the documentation main page.

./.git
That's the git Repository.

./.kdev4
Is a living propsal for a KDevelop configuration.

./man
The Doxygen-generated man pages.

./public
Location for GitLab Pages web server files.
The Doxygen-generated HTML documentation can be found in ./public/doxygen/

./Suite*
Each 'Suite' directory contains a collection of test cases.

./tmp
Exists for temporary files e.g. for testing purposes.

./Tools
Contains TOOLS for the development, e.g. git hooks.

./vocabularies
Is only a container for its subdirectories.
These subdirecories are called vocabularies and the names of the
subdirectories are used to identify the vocabularies.

./.vscode
Is a living propsal for a Visual Studio Code configuration.

Directories of the Docker image

/usr/local/bin
Contain the user programs: parser leon lb lc

/usr/local/lib/leonardus/
System files: boot.leo dry.inc

/usr/local/lib/leonardus/vocabularies/
The location for the vocabularies.

/usr/local/lib/leonardus/Examples/
Example *.leo LeoScripts

Examples

There is an Examples direcory. A content overview will be generated by
the build process as EXAMPLES.md.

Programming Language

See LANGUAGE

man pages

Leonardus integrates the traditional UNIX man page subsystem.
Generated man pages are categorized under section 7 (Miscellaneous
Information Manual).
Doxygen generates man pages for the operators in systemdict, leodict
and userdict.
lb -C manpage generates man pages for the operators from vocabularies.
The tool mandb must be accessible in the PATH to update the database for apropos

Usage Examples

man RAD
lb -C manpage
man 7 __odo
man nip
man Forth::over
man -- -rot
whatis atan
whatis nip
apropos odo
apropos Forth
apropos "Vocabulary Forth"
apropos LeoScript
apropos -s 7 ]

References