- Overview
- Core Interpreter Architecture
- Language Executors
- UI Architecture
- Graphics System
- Debugger System
- Data Flow
- Extension Points
- Threading Model
- Configuration & Persistence
Time Warp Studio is a desktop IDE built with:
- Backend: Python 3.10+ with PySide6 (Qt6)
- Architecture: Single-process, multi-threaded desktop application
- Core Pattern: Central interpreter with stateless language executors
- UI Framework: PySide6/Qt6 for cross-platform GUI
State Management:
- UI owns all state (editor content, canvas, variables)
- Language executors are stateless command processors
- Results returned as text strings with emoji prefixes
Safety:
- No use of
eval()for expression evaluation - Protected math expression evaluator
- Thread-safe queues for execution communication
Modularity:
- 24 independent language modules (easily extensible)
- Feature panels loaded dynamically
- Theme system completely separate from core logic
Location: Platforms/Python/time_warp/core/interpreter.py
Core dispatcher managing all 24 language executors:
class Interpreter:
def __init__(self):
# Language executors are functions, not class instances.
# Line-by-line executors (7 languages):
# execute_basic, execute_pilot, execute_logo,
# execute_c, execute_pascal, execute_prolog, execute_forth
#
# Whole-program executors (17 languages) registered in:
# _WHOLE_PROGRAM_EXECUTORS dict
# (Lua, Scheme, COBOL, Brainfuck, Assembly, JavaScript,
# Fortran, REXX, Smalltalk, HyperTalk, Haskell, APL,
# SQL, JCL, CICS, SQR, Python)
pass- Main entry point for code execution
- Routes to appropriate executor based on language
- Captures output and errors
- Returns structured result with emoji prefix
Output Prefixes:
❌Execution error✅Successℹ️Information message🐢Turtle graphics command🎨Theme change notification
User Code
↓
UI calls: interpreter.execute(code, language)
↓
Route to language executor
↓
Executor parses and executes
↓
Returns: "✅ Output\n" or "❌ Error\n"
↓
UI updates console and canvas
Each language follows a stateless function pattern:
def execute_basic(interpreter: Interpreter, command: str, turtle: TurtleState) -> str:
"""Execute a single BASIC command; return output text."""
# Parse and execute
return output_with_emoji_prefixLanguage executors MUST NOT:
- ❌ Store UI widget references
- ❌ Update canvas directly
- ❌ Modify main window
Language executors CAN:
- ✅ Read/write interpreter state (variables, turtle position)
- ✅ Return strings as output
- ✅ Access the interpreter and turtle state objects
Line-by-line executors (parsed per statement):
Features:
- Variables and arrays (DIM statement)
- Control flow (IF/ELSE, FOR, WHILE, DO...LOOP)
- Subroutines (GOSUB/RETURN)
- Turbo BASIC graphics
- SCREEN, COLOR, LINE, CIRCLE, PSET, PAINT
Features:
- Turtle graphics (FORWARD, BACKWARD, RIGHT, LEFT)
- Pen control (PENUP, PENDOWN)
- Shapes (CIRCLE, RECTANGLE, POLYGON)
- Procedures (TO/END definitions)
- Recursion support
Turtle State Tracking:
- Position:
x,y(-400 to 400 logical coords) - Heading:
angle(0-360 degrees) - Pen:
pen_down,pen_color,pen_width
Features:
- T-units: Text output
- A-units: Answer input validation
- J-units: Conditional jumps
- Used for CAI (Computer-Aided Instruction) lessons
Features:
- Basic C syntax (variables, functions)
- stdio (printf, scanf)
- Standard math library
- Limited to safe subset
Status: Experimental
Features:
- Structured programming
- Type declarations, procedures, functions
- Control structures (IF, FOR, WHILE, REPEAT)
Status: Experimental
Features:
- Facts and rules
- Unification and backtracking
- List operations
- Query processing
Status: Experimental
Features:
- Stack operations (DUP, SWAP, DROP)
- Word definitions (: WORD ... ;)
- Control structures (IF...THEN, DO...LOOP)
- Integer arithmetic
Status: Experimental
Whole-program executors (17 languages):
Python, Lua, Scheme, COBOL, Brainfuck, Assembly, JavaScript, Fortran, REXX, Smalltalk, HyperTalk, Haskell, APL, SQL, JCL, CICS, SQR.
Each receives the full source text and returns output. Registered in
_WHOLE_PROGRAM_EXECUTORS in core/interpreter.py.
MainWindow
├── MenuBar (File, Edit, Run, Debug, View, Help)
├── Central Widget
│ ├── CodeEditor
│ ├── TabbedPanels
│ │ ├── OutputPanel
│ │ ├── GraphicsCanvas
│ │ ├── VariablesInspector
│ │ └── ...
│ └── 14 Feature Panels
├── Toolbar
└── StatusBar
CodeEditor (ui/editor.py):
- Syntax highlighting per language
- Real-time validation
- Line numbers, code folding
- Find/Replace functionality
Canvas (ui/canvas.py):
- Qt-based graphics rendering
- Zoom (0.1x to 5.0x) and pan support
- Renders turtle graphics in real-time
- 800x600 logical coordinates
Specialized development tools accessible via tabs:
- Lesson Mode - Step-by-step guided instruction
- AI Assistant - Code suggestions
- Error Explainer - Understand errors
- Reference Search - Quick documentation
- Examples Browser - Browse code examples
- Turtle Inspector - Visualize turtle state
- Debugger - Step through execution
- Variables Inspector - View current variables
- Achievements - Progress gamification
- Project Runner - Multi-file management
- Classroom Mode - Teaching features
- Performance Monitor - Execution profiling
- Settings - IDE configuration
- Help - Integrated documentation
File: New, Open, Save, Export, Recent, Examples, Lessons Edit: Undo, Redo, Cut, Copy, Paste, Find, Replace Run: Execute, Continue, Stop, Clear output Debug: Step Into, Step Over, Breakpoints, Timeline View: Show/Hide panels, Themes, Zoom Help: Documentation, Shortcuts, About, Settings
Core drawing system with 50+ commands:
class TurtleState:
x: float # Position X
y: float # Position Y
angle: float # Heading 0-360
pen_down: bool # Drawing enabled
pen_color: tuple # RGB color
pen_width: int # Pixel width -400 0 400
300 ┌─────┬──────┐
│ │ │
0 ├─────•(0,0) ┤
│ │ │
-300 └─────┴──────┘
Canvas: 800x600 logical coordinates Turtle: Center at (0, 0) Angle: 0°=East, 90°=North, 180°=West, 270°=South
Movement:
- FORWARD, BACKWARD - Move and optionally draw
- RIGHT, LEFT - Rotate turtle
- SETPOSITION - Absolute move
Drawing:
- PENUP, PENDOWN - Control drawing
- LINE - Draw line
- CIRCLE - Draw circle
- POINT - Draw single pixel
Style:
- SETCOLOR - Change pen color
- SETWIDTH - Change pen width
- CLEAR - Erase canvas
- HOME - Reset to origin
- Breakpoints: Stop at specific lines
- Stepping: Step into/over statements
- Timeline: Full execution history
- Variables: Inspect values at each step
- Rewind: Navigate backwards through execution
Each execution step stored with:
- Step number
- Line number
- Command executed
- Variable snapshot
- Turtle state snapshot
- Output generated
- Any errors
- Step Into - Execute next, enter functions
- Step Over - Execute next, skip functions
- Continue - Run until next breakpoint
- Pause - Pause execution
- Stop - Halt program
- Toggle Breakpoint - Add/remove breakpoint
- View Timeline - Browse execution history
User Code in Editor
↓
[User clicks Run]
↓
MainWindow.on_run_clicked()
↓
Create ExecutionThread
↓
ExecutionThread.run()
↓
interpreter.execute(code, language)
↓
Language Executor processes code
↓
Emit signals with results
↓
Main thread receives signals
↓
Update UI (console, canvas, variables)
Qt signal/slot pattern for thread-safe communication:
# Signal definitions (PySide6)
from PySide6.QtCore import Signal, Slot
state_changed = Signal(dict) # Full state update
output_received = Signal(str)
error_received = Signal(str)
# Slots (received in main thread)
@Slot(dict)
def on_state_changed(self, state):
# Update all UI components
pass- Create
languages/newlang.py:
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..core.interpreter import Interpreter
from ..graphics.turtle_state import TurtleState
def execute_newlang(interpreter: Interpreter, source: str, turtle: TurtleState) -> str:
"""Execute NewLang source code."""
output_lines = []
try:
# Parse and execute source
output_lines.append("✅ Result")
except Exception as e:
output_lines.append(f"❌ {e}")
return "\n".join(output_lines) + "\n"- Register in
core/interpreter.py:
from ..languages.newlang import execute_newlang
# Add Language.NEWLANG enum member
# Add entry in _init_whole_program_executors()-
Add detection in
execute()method -
Create examples in
Examples/newlang/ -
Write tests in
tests/test_newlang.py
-
Create in
ui/feature_panels/new_panel.py -
Register in
ui/main_window.py:
self.new_panel = NewPanel()
self.tabs.addTab(self.new_panel, "New Panel")- Add menu toggle in View menu:
self.action_show_new = self.menu_view.addAction("New Panel")
self.action_show_new.setCheckable(True)
self.action_show_new.triggered.connect(self.new_panel.show)- Define in
ui/themes.pyby adding a newTheme(...)entry to the themes dict:
"My Custom": Theme(
bg="#1e1e2e",
fg="#cdd6f4",
accent="#89b4fa",
# ... colors for all UI elements
),- The theme is automatically available in the theme menu
Time Warp Studio employs a multi-threaded architecture to ensure responsive UI interactions while executing potentially long-running code. Below is an overview of the threading model:
-
Main Thread (UI):
- Handles all user interactions, including editor updates, canvas rendering, and menu actions.
- Ensures that the application remains responsive during execution.
-
Interpreter Thread:
- Executes user code in a separate thread to prevent blocking the UI.
- Communicates with the main thread via thread-safe queues.
-
Worker Threads:
- Used for auxiliary tasks such as file I/O, syntax highlighting, and background processing.
-
Thread-Safe Queues:
- The
queue.Queuemodule is used for passing messages between threads. - Ensures safe and efficient communication without race conditions.
- The
-
Signals and Slots:
- PySide6's signal-slot mechanism is used for notifying the UI of execution results or errors.
-
Deadlock Prevention:
- All long-running tasks are offloaded to worker threads.
- The main thread never waits indefinitely for a response.
-
Error Handling:
- Exceptions in worker threads are captured and reported back to the main thread.
Location: ~/.time_warp/config.json
Contains:
- Theme preference
- Editor settings (font, size)
- Canvas settings
- Recent files
- Feature panel visibility
- Color schemes
- Keyboard shortcuts
- Learning progress
- Config auto-saved on changes
- Windows geometry saved on close
- Recent files list maintained
- Theme choice persisted
28 built-in themes organized by category:
Dark (11): Dracula, Monokai, VS Code Dark, GitHub Dark, Nord, One Dark Pro, Solarized Dark, Ocean, Catppuccin Mocha, Gruvbox Dark, Tokyo Night
Light (6): Gruvbox Light, Catppuccin Latte, VS Code Light, GitHub Light, Solarized Light, Spring
Specialty (2): High Contrast Dark, High Contrast Light
Accessibility (2): Dyslexia Friendly, Accessible Dark Blue
Retro CRT (7): Amber Monochrome, Green Monochrome, IBM PC CGA, Commodore 64, Apple II, DOS Blue, ZX Spectrum
interpreter.py— Main dispatcher (~1,500 lines, 24 language executors)debugger.py— Step-through debugger with execution timeline and rewindsql_engine.py— SQLite-backed T-SQL compatibility layerorchestrator.py— System integration and component registryconfig.py— Canonical paths (~/.time_warp/) and settings
hardware_simulator.py— Simulation-first IoT hardware supportplugin_system.py— Plugin architecture (future extensibility)game_support.py— Game state, timers, and input handlingaccessibility.py— Accessibility features and screen reader supportai_assistant.py— AI-powered code suggestionsai_suggestions.py— Contextual suggestion enginecloud_storage.py— Cloud file storage (optional)hardware_integration.py— Physical hardware bridging (optional)- Lessons, autosave, achievements, classroom mode, examples browser, etc.
base.py— Executor protocol definition- Line-by-line executors (7):
basic.py,pilot.py,logo.py,c_lang_fixed.py,pascal.py,prolog.py,forth.py - Whole-program executors (17):
python.py,lua.py,scheme.py,cobol.py,brainfuck.py,assembly.py,javascript.py,fortran.py,rexx.py,smalltalk.py,hypertalk.py,haskell.py,apl.py,sql.py,jcl.py,cics.py,sqr.py lang_utils.py,parser_patterns.py— Shared parsing utilities
main_window.py— Main IDE window (6 mixins, 3,300+ lines)editor.py— Code editor with syntax highlighting and minimapcanvas.py— Turtle graphics canvas with zoom/panoutput.py— Console output with interpreter threadsthemes.py— 28-theme manager (dark, light, retro CRT, accessibility)debug_panel.py— Debugger controls, watch, and call-stackcommand_palette.py— Ctrl+Shift+P command palettefeature_panels.py— 14 dynamic feature panelsmixins/— Collaboration, classroom, debug, export, file ops, help
turtle_state.py— Turtle position, heading, pen state (~600 lines)art_toolkit.py— Drawing primitives and shapespixel_canvas.py— Pixel-level canvas operationsturtle_gallery.py— Pre-built turtle art examples
lesson_system.py— Step-by-step lessons with checkpointsexamples_browser.py— Searchable 93-program catalogturtle_preview.py— Live Logo code previewtheme_editor.py— Custom theme creationautosave_manager.py— Background autosave with versioningachievements.py— Gamified progress trackingclassroom_mode.py— Teaching and presentation toolsreference_search.py— Quick documentation lookup
expression_evaluator.py— Safe math eval (hand-written parser, noeval())string_evaluator.py— String expression evaluationerror_hints.py— Syntax error suggestionsvalidators.py— Input validation helperscode_formatter.py— Code formatting utilitieslogging_config.py— Structured logging setup
- 41+ test files covering all 24 language executors, graphics, GUI, and interpreter
conftest.py,conftest_lang.py— Shared fixtures and helperstest_runner.py— Orchestration with HTML coverage reports
Build, launch, deploy, and utility scripts — including deploy.sh, startup.py,
wasm.mk, build_native.sh, generate_icon.py, and IDE launchers.
- Cold start: 2-5 seconds
- Theme loading: 0.5 seconds
- Interpreter init: 1 second
- UI rendering: 0.5 seconds
- BASIC: ~1000 statements/second
- Logo: 100+ turtle commands/second
- Debugger overhead: ~10% slower
- Base: 200-300 MB
- Per file: +5-10 MB
- Large graphics: +50-100 MB per 1000 commands
- Python: PEP 8, 100 char line limit
- Formatter: black
- Linter: flake8, pylint
- Types: mypy strict mode
- Docstrings: All public functions
pytest tests/ -v # Run tests
python Platforms/Python/test_runner.py --comprehensive # Full suite with coverage reports
python Platforms/Python/test_runner.py --basic # Quick smoke tests
python Platforms/Python/test_runner.py --parallel # Parallel execution (pytest-xdist)
black --check . # Check formatting
ruff check time_warp # Fast linting
mypy time_warp --strict # Type check- Fork repository
- Create feature branch
- Make changes following style guide
- Write/update tests
- Run test suite (all pass)
- Submit PR with description
For more details:
- README.md — Project overview and quick start
- CONTRIBUTING.md — Contribution guidelines
- CHANGELOG.md — Version history
- ROADMAP.md — Development roadmap
- Source:
Platforms/Python/time_warp/