Getting Started

Prerequisites

Installation

# Clone the repository
git clone https://gitea.pockle.world/john/cell
cd cell

# Bootstrap the build
make bootstrap

This compiles the ƿit runtime and installs the pit binary. The ƿit shop is created at ~/.pit/.

Verify your installation:

pit version

Hello World

Create a file called hello.ce:

// hello.ce
log.console("Hello, ƿit!")
$stop()

Run it:

pit hello

You should see Hello, ƿit! printed to the console.

Every .ce file is an actor — an independent unit of execution. The $stop() call tells the actor to shut down when it’s done.

A Counting Actor

Actors can schedule work over time. Create counter.ce:

// counter.ce
var count = 0

$clock(function(dt) {
  count = count + 1
  log.console(`tick ${count}`)
  if (count >= 5) {
    $stop()
  }
})
pit counter

The $clock intrinsic calls your function every tick. The actor runs until you stop it.

Two Actors Talking

The power of ƿit is in actors communicating through messages. Create two files:

// greeter.ce
$receiver(function(msg, reply) {
  reply({greeting: `Hello, ${msg.name}!`})
})
// main.ce
$start(function(greeter) {
  $send(greeter, {name: "world"}, function(response) {
    log.console(response.greeting)
    $stop()
  })
}, "greeter")
pit main

$start launches a new actor. $send sends a message and provides a callback for the reply. Messages are automatically serialized — actors never share memory.

Using Modules

Modules (.cm files) return a value that is cached and frozen. Create a module:

// math_helpers.cm
function square(x) {
  return x * x
}

function distance(x1, y1, x2, y2) {
  var math = use('math/radians')
  var dx = x2 - x1
  var dy = y2 - y1
  return math.sqrt(dx * dx + dy * dy)
}

return {
  square: square,
  distance: distance
}

Use it from an actor:

// calc.ce
var helpers = use('math_helpers')

log.console(helpers.square(5))          // 25
log.console(helpers.distance(0, 0, 3, 4))  // 5

$stop()

Creating a Package

To share code or manage dependencies, create a pit.toml:

package = "myproject"
version = "0.1.0"

[dependencies]

Your package can now use pit build, pit test, and install dependencies.

What’s Next