6.0 KiB
ƿit (pit) Language Project
Building
Recompile after changes: make
Bootstrap from scratch (first time): make bootstrap
Run cell --help to see all CLI flags.
Code Style
All code uses 2 spaces for indentation. K&R style for C and Javascript.
ƿit Script Quick Reference
ƿit script files: .ce (actors) and .cm (modules). The syntax is similar to JavaScript with important differences listed below.
Key Differences from JavaScript
var(mutable) anddef(constant) — noletorconst==and!=are strict (no===or!==)- No
undefined— onlynull - No classes — only objects and prototypes (
meme(),proto(),isa()) - No
for...in,for...of, spread (...), rest params, or default params - No named function declarations — use
var fn = function() {}or arrow functions - Variables must be declared at function body level only (not in if/while/for/blocks)
- All variables must be initialized at declaration (
var xalone is an error; usevar x = null) - No
try/catch/throw— usedisrupt/disruption - No arraybuffers — only
blob(works with bits; muststone(blob)before reading) - Identifiers can contain
?and!(e.g.,nil?,set!,is?valid) - Prefer backticks for string interpolation; otherwise use
text()to convert non-strings - Everything should be lowercase
Intrinsic Functions (always available, no use() needed)
The creator functions are polymorphic — behavior depends on argument types:
-
array(number)— create array of size N filled with null -
array(number, value_or_fn)— create array with initial values -
array(array)— copy array -
array(array, fn)— map -
array(array, array)— concatenate -
array(array, from, to)— slice -
array(record)— get keys as array of text -
array(text)— split text into individual characters (e.g.,array("hello")→["h","e","l","l","o"]) -
array(text, separator)— split by separator -
array(text, length)— split into chunks of length -
text(array, separator)— join array into text -
text(number)ortext(number, radix)— number to text -
text(text, from, to)— substring -
number(text)ornumber(text, radix)— parse text to number -
number(logical)— boolean to number -
record(record)— copy -
record(record, another)— merge -
record(array_of_keys)— create record from keys
Other key intrinsics: length(), stone(), is_stone(), print(), filter(), find(), reduce(), sort(), reverse(), some(), every(), starts_with(), ends_with(), meme(), proto(), isa(), splat(), apply(), extract(), replace(), search(), format(), lower(), upper(), trim()
Sensory functions: is_array(), is_text(), is_number(), is_object(), is_function(), is_null(), is_logical(), is_integer(), is_stone(), etc.
Standard Library (loaded with use())
blob— binary data (bits, not bytes)time— time constants and conversionsmath— trig, logarithms, roots (math/radians,math/turns)json— JSON encoding/decodingrandom— random number generation
Actor Model
.cefiles are actors (independent execution units, don't return values).cmfiles are modules (return a value, cached and frozen)- Actors never share memory; communicate via
$send()message passing - Actor intrinsics start with
$:$me,$stop(),$send(),$start(),$delay(),$receiver(),$clock(),$portal(),$contact(),$couple(),$unneeded(),$connection(),$time_limit()
Requestors (async composition)
sequence(), parallel(), race(), fallback() — compose asynchronous operations. See docs/requestors.md.
Error Handling
var fn = function() {
disrupt // bare keyword, no value
} disruption {
// handle error; can re-raise with disrupt
}
Push/Pop Syntax
var a = [1, 2]
a[] = 3 // push: [1, 2, 3]
var v = a[] // pop: v is 3, a is [1, 2]
C Integration
- Declare everything
staticthat can be - Most files don't have headers; files in a package are not shared between packages
- No undefined in C API: use
JS_IsNullandJS_NULLonly - A C file with correct macros (
CELL_USE_FUNCSetc) is loaded as a module by its name (e.g.,png.cin a package →use('<package>/png')) - C symbol naming:
js_<pkg>_<file>_use(e.g.,js_core_math_radians_useforcore/math/radians) - Core is the
corepackage — its symbols follow the samejs_core_<name>_usepattern as all other packages - Package directories should contain only source files (no
.mach/.mcodealongside source) - Build cache files in
build/are bare hashes (no extensions) - Use
JS_FRAME/JS_ROOT/JS_RETURNmacros for any C function that allocates multiple heap objects. AnyJS_New*/JS_SetProperty*call can trigger GC.
Project Layout
source/— C source for the cell runtime and CLIdocs/— master documentation (Markdown), reflected on the websitewebsite/— Hugo site; theme atwebsite/themes/knr/internal/— internal ƿit scripts (engine.cm etc.)packages/— core packagesMakefile— build system (maketo rebuild,make bootstrapfor first build)
Testing
After any C runtime changes, run all three test suites before considering the work done:
make # rebuild
./cell --dev vm_suite # VM-level tests (641 tests)
./cell --dev test suite # language-level tests (493 tests)
./cell --dev fuzz # fuzzer (100 iterations)
All three must pass with 0 failures.
Documentation
The docs/ folder is the single source of truth. The website at website/ mounts it via Hugo. Key files:
docs/language.md— language syntax referencedocs/functions.md— all built-in intrinsic functionsdocs/actors.md— actor model and actor intrinsicsdocs/requestors.md— async requestor patterndocs/library/*.md— intrinsic type reference (text, number, array, object) and standard library modules