Skip to content

gokr/harding

Repository files navigation

Harding

Harding is a Smalltalk dialect written in Nim that preserves most of the distinguishing features of the Smalltalk language while fitting in with modern tooling and strong abilities to integrate with libraries from the Nim and C ecosystems. The language currently has a stackless AST based interpreter supporting green threads in classic Smalltalk style.

Quick Example

"Hello, World!" println

# Class with generated accessors
Person := Object derivePublic: #(name age)
p := Person new
p name: "Alice"
p age: 30
("Hello, " , p name) println

# Class with generated accessors and a manual method
Point := Object derivePublic: #(x y)
Point>>distanceFromOrigin [ ^ ((x * x) + (y * y)) sqrt ]

p := Point new
p x: 3; y: 4
p distanceFromOrigin println  # Prints: 5.0

Installation

Prerequisites

Install libraries gtk4 gtksourceview5

linux:

apt-get install gtk4 gtksourceview5 libvte-2.91-gtk4-dev

macos

brew install gtk4 gtksourceview5 pkg-config

Download and build Harding

git clone https://github.com/gokr/harding.git
cd harding
nimble harding  # Build harding REPL
nimble bona     # Build bona IDE (optional)

# Optional: build with MummyX HTTP server support
nimble harding_mummyx
nimble bona_mummyx

Binaries:

  • harding - REPL/interpreter
  • harding_debug - REPL with debugger support
  • harding-lsp - Language Server for IDE support
  • granite - Compiler to Nim
  • bona - GTK IDE

Optional MummyX-enabled builds expose HTTP server support through lib/mummyx/Bootstrap.hrd. See docs/MUMMYX.md.

IDE Desktop Integration (Ubuntu/GNOME)

For proper dock and Alt-Tab icons:

nimble install_bona  # Installs .desktop file and icon

Usage

REPL

harding                    # Interactive REPL
harding script.hrd         # Run a file
harding script.hrd -- a b  # Pass runtime args to System arguments
harding -e "3 + 4"         # Evaluate expression
harding --ast script.hrd   # Show AST, then execute
harding --loglevel DEBUG   # Verbose execution trace

GTK IDE (Bona)

Launch the graphical IDE:

bona                       # Start IDE with Launcher

IDE Tools:

  • Launcher - Main window with access to all tools
  • Workspace - Code editor with Do It (Ctrl+D), Print It (Ctrl+P), Inspect It (Ctrl+I)
  • Terminal - Embedded VTE terminal for shell and agent workflows
  • Transcript - Output console for logging and results
  • System Browser - Browse classes by library (Core, Collections, GUI, IDE)
  • Inspector - Examine object slots and values

On Linux, the embedded terminal requires the VTE development/runtime packages for your GTK version. Bona's default GTK4 build uses libvte-2.91-gtk4-dev. The terminal supports a right-click context menu plus shortcuts such as Ctrl+Shift+C, Ctrl+Shift+V, Ctrl+Shift+N, and Ctrl+Shift+O for copy, paste, new terminal, and a new OpenCode terminal.

Script Execution

Script files are automatically wrapped in a block, enabling Smalltalk-style temporary variable declarations:

# script.hrd
| counter total |
counter := 0
total := 0
1 to: 5 do: [:i |
  counter := counter + 1
  total := total + i
]
total  # Returns 15

Scripts execute with self = nil, following the Smalltalk workspace convention.

MummyX HTTP Server

Build with MummyX support when you want Harding-side HTTP routing:

nimble harding_mummyx
./harding examples/mummyx_hello.hrd

This optional integration is also available in Bona builds:

nimble bona_mummyx

See docs/MUMMYX.md for the API, build tasks, and concurrency model.

Environment Variables

  • HARDING_HOME - Default home directory for loading libraries

VSCode Extension

Full IDE support for .hrd files with syntax highlighting, completions, and debugging:

# Build the extension
nimble vsix

# Install
code --install-extension vscode-harding/vscode-harding-0.4.0.vsix

Features:

  • Syntax highlighting
  • Code completions (LSP)
  • Hover information (LSP)
  • Go to definition (LSP)
  • Breakpoints and stepping (DAP)
  • Variable inspection (DAP)

See VSCODE.md for full details.

For Smalltalkers

What feels familiar:

  • Message syntax: unary obj size, binary 3 + 4, keyword dict at: key put: value
  • Cascade messages
  • Classes and class methods
  • String concatenation with comma: "Hello" , " World"
  • Blocks are proper lexical closures with temporaries and can do early returns: [ | temp | temp := 1 ]
  • Everything is an object, everything happens via message sends
  • Live evaluation in the REPL with harding
  • Collection messages: do:, select:, collect:, etc.

What's different:

Smalltalk Harding
Required period end-of-statement Optional - newline or period both work
Double quotes for comments Hash # for comments
Single quotes for strings Double quotes for strings
Classes define structure via class definition Class construction using derive: Object derive: #(slots)
Manual accessor definition Generated accessors via derivePublic: or derive:read:write:
Image-based persistence Source files loaded on startup, git friendly source format, normal Unix workflow
VM execution Interprets AST directly, native compiler via Nim (in development)
FFI via C bindings Direct Nim interop: call Nim functions, use Nim types

Variable Naming Rule

Harding distinguishes globals from locals by capitalization and enforces this in parsing:

Type Convention Example
Globals (class names, global variables) Uppercase first Point, MyGlobal
Locals (slots, temporaries, parameters, block params) Lowercase first temp, index, value

Key Syntax Differences

Feature Harding Syntax
Comments # This is a comment
Strings "Double quotes only"
Create subclass Point := Object derive: #(x y)
Create with generated accessors Point := Object derivePublic: #(x y)
Create instance p := Point new
Define method Point>>move: dx [ ... ]
Batch methods Point extend: [ self >> foo [ ... ] ]

Current Status

Working:

  • Lexer, parser, stackless AST interpreter
  • Class-based object system with slots
  • REPL with file execution
  • Block closures with lexical scoping and support for early returns
  • Data structure literals
  • Method definition (>>), self and super support
  • Multi-character operators (==, //, <=, >=, ~=, ~~)
  • Standard library (Object, Boolean, Block, Number, Collections, String, Exception, TestCase)
  • Core I/O and process helpers (File, FileStream, System, Stdin/Stdout/Stderr)
  • Green threads: Processor fork:, Processor yield
  • Synchronization primitives: Monitor, SharedQueue, Semaphore
  • Optional MummyX HTTP server integration with HttpServer, Router, and green-process request handlers
  • Multiple inheritance with conflict detection and scoped super send
  • Dynamic message sending: perform:, perform:with:
  • Generated accessors via derivePublic:, derive:read:write:, and derive:read:write:superclasses:
  • Named slot and binding access via ::
  • Library/namespace system for modular code organization (Core, Collections, GUI, IDE libraries)
  • External Harding libraries via the harding lib workflow, including BitBarrel as an installable package
  • String concatenation with auto-conversion using ,
  • GTK-based IDE (bona) with Workspace (code editor with Do It/Print It/Inspect It), Transcript (output console), System Browser (class/method browser), and Inspector (object viewer)
  • Smalltalk-style Print It - insert results in editor with selection
  • Exception handling via on:do: with Smalltalk-style resumable exceptions (resume, resume:, retry, pass, return:)
  • Granite compiler pipeline for standalone .hrd scripts to native binaries via Nim
  • Granite support for inline control flow, block-heavy examples, and mixed interpreted/compiled runtime support
  • Version-based MIC/PIC caching for improved message send performance
  • Broad test coverage across interpreter, stdlib, compiler, exceptions, IDE tooling, and website examples
  • VSCode extension with LSP (completions, hover, symbols) and DAP (breakpoints, stepping, variables)
  • Harding Debug Protocol (HDP) for VM debugging

In progress:

  • Granite parity work for remaining inheritance and in-VM compilation edge cases
  • FFI to Nim
  • Standard library and external ecosystem expansion

Documentation

Examples

harding examples/hello.hrd
harding examples/classes.hrd
harding examples/blocks.hrd
harding examples/process_demo.hrd
harding examples/inheritance.hrd
harding examples/collections.hrd
harding examples/control_flow.hrd

# Launch the GTK IDE
bona

See the examples/ directory for more examples covering arithmetic, variables, objects, classes, methods, inheritance, collections, control flow, and blocks.

License

MIT


Smalltalk's semantics, modern implementation.

About

A beginning of a modern Smalltalk

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages