Crate sbrain [] [src]

SBrain, or Semantic Brain, is a set of extensions to the famous language by Urban Müller designed to make it more amenable to genetic programming. Additions include a stack, a general- purpose register, and single-instruction arithmetic.

This crate provides an implementation of the SBrain specification designed to be used for genetic programming. See the specification pseudomodule for the complete specification.

Here's a quick example:

let result = evaluate("[.>]@@Test Data to Echo", None);
assert_eq!("Test Data to Echo", &tape_to_string(result.output));
// This program terminates after 52 cycles
assert_eq!(52, result.cycles);

// In this case, the program is interruped before completion.
let result = evaluate("[.>]@@Test Data to Echo", Some(32));
// The program doesn't finish, because it would take more than 32 cycles.
assert_eq!("Test Data t", &tape_to_string(result.output));
assert_eq!(false, result.halted);

Modules

specification

Structs

EvalResult

Represents the outcome of an evaluation by the SBrain VM.

SBrainVM

A virtual machine modelling the SBrain Turing machine. This machine implements the specification relatively strictly, providing exactly 216 (65536) data and instruction cells. Thus, all pointers are 16 bits and all data is 32 bits. The main deviation from the minimum specification is the jump stack, which is indefinitely expandable.

Enums

FlowAction

FlowAction allows the VM's execution engine to implement flow control. Because evaluation can only see a single instruction, it must use this struct to instruct the flow controller to perform flow control actions.

Functions

evaluate

Run the program represented by the given source on a new Semantic Brain VM. If Limit is None, this may never return; if it is Some(n), the machine will run for at most n cycles, then stop.

source_to_tapes

Given source code, create data and instruction tapes.

tape_to_string

Convert a tape of MData cells into Unicode chars. Invalid chars are excluded, which could have some unintended side effects for genesis based on string comparisons.

Type Definitions

MAddr

The type of a pointer to a cell.

MData

The type of a data cell