Download EMOJISCRIPT.md from Snapkitty/snapkitty-clojure-lisp-bridge: direct link, hf CLI and curl.
- Browser
- Download file 7.76 kB
-
https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/EMOJISCRIPT.md
- Command line
-
hf download hf://Snapkitty/snapkitty-clojure-lisp-bridge/EMOJISCRIPT.md
-
curl -L -o EMOJISCRIPT.md https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/EMOJISCRIPT.md
Ahmad's EmojiScript β Bytecode Dialect
High-performance emoji-based programming language compiled to bytecode and executed on a stack-based VM. Part of the SNAP OS sovereign runtime and now integrated into the Clojure Lisp MCP.
Overview
EmojiScript is Ahmad's low-level bytecode language where each instruction is a single emoji (potentially multi-codepoint). Programs compile to SigilOp bytecode and execute on the SoulVM with cryptographic sealing to the WORM chain.
EmojiScript source β lex() β bytecode β execute() β result + WORM seal
The 15 Instructions
Stack Operations
| Emoji | Name | Description | Example |
|---|---|---|---|
π’<digits> |
Push | Push number literal (i64) | π’42 |
Binary Operators (pop 2, push result)
| Emoji | Name | Description |
|---|---|---|
β |
Add | Integer addition |
β |
Sub | Integer subtraction |
βοΈ (or β or β) |
Mul | Integer multiplication |
β |
Div | Integer division (raises on /0) |
π€ (or π) |
And | Bitwise AND |
π (or π) |
Or | Bitwise OR |
π (or β) |
Xor | Bitwise XOR |
Control Flow
| Emoji | Name | Args | Description |
|---|---|---|---|
β‘οΈ |
Jump | target (i64) | Unconditional jump to PC |
β |
JumpIf | target (i64) | Jump if top-of-stack β 0, pop predicate |
β©οΈ (or π or π) |
Ret | β | Return & halt execution |
Capability & Memory
| Emoji | Name | Args | Description |
|---|---|---|---|
π |
CapGate | slot (i64), rights (i64) | Capability proof check (pops 2 args) |
β‘ |
Call | func_idx (i64) | Indirect function call (future) |
ποΈ |
Alloc | size (i64), type_tag (i64) | Allocate memory (pops 2 args) |
π€ |
Load | offset (i64) | Load from memory (pops 1 arg) |
π¦ |
Store | offset (i64) | Store to memory (pops 1 arg) |
Future Semantic Passes (Sprint 2)
| Emoji | Name | Routes To | Purpose |
|---|---|---|---|
π |
Stream | telemetry-bus | Emit telemetry event (reserved) |
π§ |
PolicyCheck | policy-immune | Check policy constraint (reserved) |
π |
Seal | bifrost | Explicit WORM seal hint (reserved) |
π |
ReadOnly | bifrost-policy | Downgrade rights hint (reserved) |
Syntax
Programs are whitespace-separated emoji tokens. Numbers follow π’:
π’40 π’2 β β©οΈ
Parsing rules:
- Each emoji is a single grapheme cluster (handles multi-codepoint emoji)
- Whitespace (space, tab, newline) is ignored
- Numbers:
π’followed immediately by ASCII digits (no separator) - Arguments are written before their opcode
- Example:
π’3 π’5 πmeans "push 3, push 5, then execute CapGate(3, 5)" - Args are popped in reverse order (last arg pushed = first arg consumed)
- Example:
Examples
Arithmetic
π’40 π’2 β β©οΈ β 42
π’100 π’40 β β©οΈ β 60
π’6 π’7 βοΈ β©οΈ β 42
π’84 π’2 β β©οΈ β 42
Bitwise
π’15 π’7 π€ β©οΈ β 7 (AND: 1111 & 0111 = 0111)
π’12 π’5 π β©οΈ β 13 (OR: 1100 | 0101 = 1101)
π’12 π’5 π β©οΈ β 9 (XOR: 1100 ^ 0101 = 1001)
Capability Gate
π’3 π’5 π β©οΈ β CapGate check (slot=3, rights=5)
Control Flow
π’1 β β©οΈ β Jump if predicate β 0
π’10 β‘οΈ β©οΈ β Unconditional jump to PC 10
MCP Tools
Three new MCP tools expose EmojiScript:
1. compile_emojiscript
Compile source to bytecode.
Input:
{
"source": "π’40 π’2 β β©οΈ"
}
Output:
{
"content": [
{
"type": "text",
"text": "β
Compiled: 4 instructions\nHash: abc123def456...\nBytecode: [{:op :Push, :value 40}, ...]"
}
]
}
2. execute_emojiscript
Execute compiled bytecode.
Input:
{
"source": "π’40 π’2 β β©οΈ",
"max-steps": 10000
}
Output:
{
"content": [
{
"type": "text",
"text": "β
Result: 42\nStack: [42]\nSteps: 4 / 10000"
}
]
}
Runtime Implementation
File: src/snapkitty/lisp/emojiscript.cljs
Compilation
(emoji/compile-emojiscript "π’6 π’7 βοΈ β©οΈ")
; => {:source "...", :bytecode [...], :hash "...", :instructions-count 4, :valid? true}
Execution
(let [compiled (emoji/compile-emojiscript "π’40 π’2 β β©οΈ")]
(emoji/execute-emojiscript (:bytecode compiled) :max-steps 10000))
; => {:result 42, :stack [42], :steps 4, :halted? true}
Stack-Based Interpreter
- Stack: Mutable vector, push/pop operations
- PC (Program Counter): Jump targets are bytecode indices
- Registers: None (pure stack machine)
- Memory: Stubs (future implementation)
- Step Limit: Prevents infinite loops (default 10,000)
Error Handling
- Parse errors: Unknown emoji, missing arguments, invalid numbers
- Runtime errors: Division by zero, unknown instructions, step limit exceeded
- Graceful degradation: Future semantic tokens (π, π§ , π, π) skip execution
Bytecode Format
Each instruction is a ClojureScript map:
{:op :Push :value 42}
{:op :Add}
{:op :CapGate :slot 3 :rights 5}
{:op :Jump :target 10}
{:op :Load :offset 0}
{:op :Store :offset 8}
{:op :Ret}
Instruction fields:
:opβ Instruction type (keyword):valueβ For:Push, the i64 literal:slot,:rightsβ For:CapGate:funcβ For:Call, function table index:size,:type-tagβ For:Alloc:offsetβ For:Load,:Store:targetβ For:Jump,:JumpIf, bytecode index
Testing
Run integration tests:
npm test
Tests cover:
- Compilation of all 15 opcodes
- Execution of arithmetic, bitwise, control flow
- Error cases: empty program, unknown emoji, division by zero
- Step limit enforcement
- MCP tool integration
Performance Notes
- Compilation: O(n) in source length, single pass
- Execution: O(instructions), typical 1-10Β΅s per instruction
- Memory: Minimal (stack + bytecode vector)
- Future: Link to SoulVM JIT (Cranelift) for native code generation
Design Principles
- Emoji as first-class syntax: Every instruction is a single grapheme cluster
- Argument-before-opcode: Enables post-fix compilation and clarity
- Stack machine: No registers, minimal state, deterministic
- Stateless lexer: Grapheme-by-grapheme parsing, Unicode-aware
- Extensible: Semantic-pass tokens allow future subsystems without breaking existing code
Future Work (Sprint 2+)
- Memory ops: Implement
:Load,:Store,:Alloc - Function calls: Implement
:Callwith function tables - Semantic passes: Route π, π§ , π, π to subsystems
- JIT compilation: Link to SoulVM Cranelift backend
- WORM sealing: Bifrost signing of execution results
- ScratchBlocks visual editor: Drag-drop blocks β sync emoji text
References
- Ahmad's EmojiScript (Rust): https://github.com/SNAPKITTYWEST/snap-os/blob/main/craft-crypto/src/emoji.rs
- SNAP OS: https://github.com/SNAPKITTYWEST/snap-os
- SoulVM: https://github.com/SNAPKITTYWEST/snap-os/blob/main/soulvm
- Unicode Graphemes: https://unicode.org/reports/tr29/