TechLang is a minimalistic, stack-based programming language designed for learning and experimenting with command-based interpreters. This guide is for contributors who want to understand the codebase, follow code style, add new features, or run tests.
TechLang/
├─ cli.py # CLI interface for TechLang
├─ run_tests.py # Script to run all tests
├─ requirements.txt # Python dependencies
├─ README.md # Project overview
├─ DEV.md # This developer guide
├─ PLAYGROUND.MD # Playground guide
├─ techlang/ # Core interpreter and parser
│ ├─ __init__.py
│ ├─ interpreter.py
│ ├─ parser.py
│ ├─ database.py # SQLite3 database operations
│ ├─ core.py
│ ├─ basic_commands.py
│ ├─ variables.py
│ ├─ stack.py
│ ├─ control_flow.py
│ ├─ imports.py
│ ├─ aliases.py
│ └─ blocks.py
├─ techlang_web/ # Flask playground site
│ ├─ app.py
│ ├─ templates/
│ │ └─ index.html
│ ├─ static/
│ └─ uploads/
├─ tests/ # Unit tests
│ ├─ test_interpreter.py
│ └─ test_database.py
├─ examples/ # Sample TechLang programs
│ ├─ hello.tl
│ ├─ loop.tl
│ ├─ if.tl
│ ├─ database.tl # SQLite3 example
│ └─ ...
└─ playground/ # GUI-based local playground
- Stack-based: Operations manipulate a stack.
- Variables:
set,add,sub, etc. store values in a variable table. - Commands: Core commands include
boot,ping,print,upload,download,hack,debug, etc. - Loops:
loop ... endblocks are executed multiple times. - Functions: Defined with
def ... endand called usingcall. - Aliases:
aliasallows shorthand commands. - Database: SQLite3 integration with
db_create,db_insert,db_select,db_update,db_delete,db_execute, anddb_closecommands.
┌──────────────┐
│ Start │
│(Interpreter) │
└─────┬────────┘
│
▼
┌───────────────┐
│ Read Code Line│
└─────┬─────────┘
│
┌────────────┴─────────────┐
▼ ▼
Is it a command? Is it a variable/alias?
│ │
▼ ▼
Parse & Validate Resolve alias/var
│ │
▼ ▼
Execute Command Push/Update stack/vars
│
▼
┌─────────────┐
│ Increment PC│
└─────┬───────┘
│
▼
┌─────────────┐
│ Is it a loop│
│ block? │
└────┬────────┘
│ Yes
▼
┌─────────────┐
│ Evaluate │
│ Loop count │
└─────┬───────┘
│
▼
┌─────────────┐
│ Execute │
│ Inside Loop │
└─────┬───────┘
│
▼
┌─────────────┐
│ End loop → │
│ Check exit │
└─────┬───────┘
│
▼
┌─────────────┐
│ Function Def│
└─────┬───────┘
│
▼
┌─────────────┐
│ Store func │
│ in table │
└─────┬───────┘
│
▼
┌─────────────┐
│ Function │
│ Call │
└─────┬───────┘
│
▼
┌─────────────┐
│ Execute │
│ Function │
│ body │
└─────┬───────┘
│
▼
┌─────────────┐
│ Print / IO │
│ Commands │
└─────┬───────┘
│
▼
┌─────────────┐
│ Debug/Stack │
│ Display │
└─────┬───────┘
│
▼
┌─────────────┐
│ End of Code │
└─────────────┘
│
▼
┌──────────┐
│ Return │
│ Output │
└──────────┘
-
Python:
- Use PEP8 formatting.
- Keep functions ≤ 50 lines if possible.
- Docstrings required for public functions.
- Type hints preferred.
-
TechLang (.tl):
- Commands are lowercase.
- One command per line.
- Indent
loop,if,defblocks consistently (4 spaces per level). - Use the formatter to ensure consistent style (see below).
-
Fork the repository.
-
Create a feature branch:
git checkout -b feature/<your-feature>
-
Install dependencies in a virtual environment:
python -m venv .venv source .venv/bin/activate # Linux/macOS .venv\Scripts\Activate.ps1 # Windows PowerShell pip install -r requirements.txt
-
Run tests to ensure nothing breaks:
python run_tests.py
-
Commit changes with meaningful messages.
-
Open a pull request.
TechLang includes a built-in formatter and linter to ensure consistent code style across .tl files.
The formatter automatically reflows blocks with proper indentation (4 spaces per level):
# Check if files need formatting
python format_tl.py --check file.tl
python format_tl.py --check examples/
# Format files in place
python format_tl.py --fix file.tl
python format_tl.py --fix examples/
# Custom indent size
python format_tl.py --fix --indent 2 file.tlThe formatter:
- Tokenizes using
parser.parse()for consistency with the interpreter - Preserves quoted strings and comments
- Handles all block types:
def,if,loop,while,switch,match,try,macro,struct - Properly indents
caseandcatchkeywords
The linter detects common issues in TechLang code:
# Lint files for issues
python format_tl.py --lint file.tl
python format_tl.py --lint examples/
# Check formatting and lint together
python format_tl.py --check --lint file.tlLinting rules:
- E001: Unmatched
endkeyword - E002: Unclosed block (missing
end) - W001: Variable used before assignment
- W002: Function called before definition
- W003: Duplicate function definitions
- I001: Empty block
- I002: Line too long (>100 characters)
GitHub Actions automatically checks formatting on all PRs:
# .github/workflows/techlang-format.yml runs on every PR
- python format_tl.py --check examples/
- python format_tl.py --lint examples/Contributors should run python format_tl.py --fix --lint . before committing to ensure consistent style.
-
All tests reside in
tests/. -
Use
pytestorpython run_tests.py. -
Make sure to add tests for any new commands or features.
-
Database tests include cleanup functions to prevent conflicts.
-
Formatter/linter tests are in
tests/test_formatter.py. -
Example:
from techlang.interpreter import run def test_example(): assert run("boot ping print").strip() == "1" def test_database(): code = """ db_create users "id INTEGER, name TEXT" db_insert users "1, Alice" db_select "SELECT * FROM users" """ output = run(code) assert "Table 'users' created successfully" in output
-
debugcommand prints the current stack and variable states. -
Use verbose prints during development:
print("DEBUG:", stack, vars)
SQLite3 support includes CRUD, transactions, introspection, and connection management.
Core:
db_create table "columns"db_insert table "values"db_select "query"db_update "query"db_delete "query"db_execute "sql"db_close
Advanced:
- Transactions:
db_begin,db_commit,db_rollback - Introspection:
db_tables,db_schema table,db_indexes table - Connections:
db_connect "path",db_disconnect
- Connection Management: Singleton pattern ensures proper connection handling
- Error Handling: Graceful error messages for SQL syntax and constraint violations
- Quote Handling: Automatic removal of quotes from SQL strings
- Column Parsing: Supports complex column definitions like
"id INTEGER PRIMARY KEY" - Data Types: Full SQLite3 data type support (INTEGER, TEXT, REAL, BLOB, etc.)
- File Management: Database files created as
techlang.dbin current directory
# Create a table
db_create users "id INTEGER PRIMARY KEY, name TEXT, age INTEGER, email TEXT"
# Insert data
db_insert users "1, Alice, 25, alice@example.com"
# Query data
db_select "SELECT * FROM users WHERE age > 20"
# Update data
db_update "UPDATE users SET age = 26 WHERE name = 'Alice'"
# Delete data
db_delete "DELETE FROM users WHERE name = 'Charlie'"
# Close connections
db_closedata_types.py: arrays, strings, dictionariesfile_ops.py: file I/O commandsnet_ops.py: HTTP client and server stubsgraphics_ops.py: simple canvas drawing (Pillow)math_ops.py: math functions/constantshelp_ops.py: built-in help systemmemory_ops.py: memory allocator/read-write/dumpthread_ops.py: threading & async wrapperssystem_ops.py: system commands and subprocess management
Proposed commands:
mem_alloc sizemem_free addressmem_read addressmem_write address valuemem_dump
Implemented simple heap dictionary in InterpreterState mapping integer addresses to integer cells. Allocator returns sequential base addresses; mem_write/mem_read operate on single cells; mem_dump prints current contents.
Lightweight threading wrappers:
thread_create <func>: runscall <func>in background; outputs thread idthread_join <id>: waits and prints that thread’s outputthread_sleep <ms>: sleep utilityasync_start/async_wait: aliases of thread_create/join
Note: threads run independent run(code) calls and collect outputs in InterpreterState.thread_results.
tl <file.tl>to run a file (orpython cli.py <file.tl>)tl -istarts a REPL (multi-line blocks supported)tl -vverbose
To expose tl, install in editable mode: pip install -e . (entry point in setup.cfg).
System safe wrappers:
sys_exec "cmd"— runs without shell, captures stdout/stderr,_statussys_env NAME— prints environment variablesys_time/sys_date— epoch seconds / ISO timestampsys_exit code— stores desired exit code in_exit
Process management:
-
proc_spawn "cmd"— returns pid (internal id) -
proc_wait pid— waits up to 30s, prints output, storesproc_<pid>_status -
proc_kill pid— terminates process -
TechLang includes a Flask-based playground in
techlang_web/. -
Features:
- Input
.tlcode in browser. - Upload
.tlfiles. - Interactive output display.
- Input
-
Run locally:
cd techlang_web python app.py -
Navigate to
http://127.0.0.1:8080.
- Always run tests before merging.
- Document any new commands or syntax changes.
- Follow the ASCII flow diagram when implementing new features.