Skip to content

Latest commit

 

History

History
1710 lines (1042 loc) · 19.2 KB

File metadata and controls

1710 lines (1042 loc) · 19.2 KB

API Reference

Generated by nulang --doc. Do not edit by hand.

compile_arith

Functions

is_digit

fn is_digit(c: Int) -> Bool

is_alpha

fn is_alpha(c: Int) -> Bool

is_alphanum

fn is_alphanum(c: Int) -> Bool

is_space

fn is_space(c: Int) -> Bool

skip_ws

fn skip_ws(src: String, pos: Int, len: Int) -> Int

read_int

fn read_int(src: String, pos: Int, len: Int, acc: Int) -> Int

read_ident

fn read_ident(src: String, pos: Int, len: Int, h: Int) -> Int

env_lookup

fn env_lookup(e0: Int, e1: Int, e2: Int, e3: Int, elen: Int, h: Int) -> Int

prec_of

fn prec_of(c: Int) -> Int

opcode_of

fn opcode_of(c: Int) -> Int

op_name

fn op_name(op: Int) -> String

parse_cmp

fn parse_cmp(src: String, p: Int, len: Int) -> Int

cmp_name

fn cmp_name(op: Int) -> String

emit_const

fn emit_const(num: Int, reg: Int)

emit_binop

fn emit_binop(opcode: Int, lr: Int, rr: Int, dr: Int)

emit_copy

fn emit_copy(src_reg: Int, dst_reg: Int)

comp

fn comp(src: String, pos: Int, len: Int, left: Int, min_prec: Int, nr: Int, e0: Int, e1: Int, e2: Int, e3: Int, elen: Int)

compile

fn compile(src: String)

main

fn main()

compile_hex

Functions

is_digit

fn is_digit(c: Int) -> Bool

is_alpha

fn is_alpha(c: Int) -> Bool

is_alphanum

fn is_alphanum(c: Int) -> Bool

is_space

fn is_space(c: Int) -> Bool

skip_ws

fn skip_ws(src: String, pos: Int, len: Int) -> Int

read_int

fn read_int(src: String, pos: Int, len: Int, acc: Int) -> Int

read_ident

fn read_ident(src: String, pos: Int, len: Int, h: Int) -> Int

env_lookup

fn env_lookup(e0: Int, e1: Int, e2: Int, e3: Int, elen: Int, h: Int) -> Int

prec_of

fn prec_of(c: Int) -> Int

parse_cmp

fn parse_cmp(src: String, p: Int, len: Int) -> Int

hex_digit

fn hex_digit(n: Int) -> String

remark

fn remark(msg: String)

emit_hex

fn emit_hex(w: Int)

instr

fn instr(opcode: Int, op1: Int, op2: Int, op3: Int) -> Int

comp

fn comp(src: String, pos: Int, len: Int, left: Int, min_prec: Int, nr: Int, e0: Int, e1: Int, e2: Int, e3: Int, elen: Int) -> Int

compile

fn compile(src: String)

main

fn main()

compiler_core

Functions

is_digit

fn is_digit(c: Int) -> Bool

is_alpha

fn is_alpha(c: Int) -> Bool

is_alphanum

fn is_alphanum(c: Int) -> Bool

is_space

fn is_space(c: Int) -> Bool

skip_ws

fn skip_ws(src: String, pos: Int, len: Int) -> Int

read_int

fn read_int(src: String, pos: Int, len: Int, acc: Int) -> Int

read_ident

fn read_ident(src: String, pos: Int, len: Int, h: Int) -> Int

env_lookup

fn env_lookup(e0: Int, e1: Int, e2: Int, e3: Int, elen: Int, h: Int) -> Int

prec_of

fn prec_of(c: Int) -> Int

parse_cmp

fn parse_cmp(src: String, p: Int, len: Int) -> Int

cmp_op

fn cmp_op(op: Int, a: Int, b: Int) -> Int

parse_pratt

fn parse_pratt(src: String, pos: Int, len: Int, left: Int, min_prec: Int, e0: Int, e1: Int, e2: Int, e3: Int, elen: Int) -> Int

parse

fn parse(src: String) -> Int

main

fn main()

host

Functions

main

fn main()

self_test

Functions

fib

fn fib(n: Int) -> Int

main

fn main()

spill_bug_repro

Functions

is_digit

fn is_digit(c: Int) -> Bool

is_space

fn is_space(c: Int) -> Bool

skip_ws

fn skip_ws(src: String, pos: Int, len: Int) -> Int

read_int

fn read_int(src: String, pos: Int, len: Int, acc: Int) -> Int

prec_of

fn prec_of(c: Int) -> Int

parse_pratt

fn parse_pratt(src: String, pos: Int, len: Int, left: Int, min_prec: Int) -> Int

parse

fn parse(src: String) -> Int

main

fn main()

actor_spawn

Functions

main

fn main()

Actors

Counter

actor Counter

bool

Functions

main

fn main()

core_math

Functions

main

fn main()

enum_match

Functions

name

fn name(c: Color) -> String

Types

Color

type Color = Red | Green | Blue

error_syntax

Functions

main

fn main()

error_type

Functions

main

fn main()

error_undefined

Functions

main

fn main()

fib

Functions

fib

fn fib(n: Int) -> Int

main

fn main()

higher_order

Functions

map

fn map(arr: [Int], f: fn(Int) -> Int) -> [Int]

lambda

Functions

main

fn main()

let_bind

Functions

main

fn main()

match_wildcard

Functions

main

fn main()

parse_error

Functions

main

fn main(

record

Functions

main

fn main()

result_type

Functions

unwrap

fn unwrap(r: Result) -> Int

Types

Result

type Result = Ok(Int) | Err(String)

string

Functions

main

fn main()

variant

Functions

main

fn main()

Types

Option

type Option[T] = Some(T) | None

variant_payload

Functions

area

fn area(s: Shape) -> Float

Types

Shape

type Shape = Circle(Float)

negative_core

Functions

main

fn main()

positive_core

Functions

main

fn main()

ai_chat

Functions

main

fn main()

Actors

ChatAgent

actor ChatAgent

chat

Functions

main

fn main()

Actors

ChatRoom

actor ChatRoom

ChatClient

actor ChatClient

counter

Actors

Counter

actor Counter

chat_room

Functions

main

fn main()

Actors

ChatRoom

actor ChatRoom

ChatClient

actor ChatClient

counter_actor

Actors

Counter

actor Counter

http_server

Functions

main

fn main()

Actors

TcpConnection

actor TcpConnection

link_monitor

Functions

main

fn main()

Actors

Watcher

actor Watcher

Victim

actor Victim

pattern_match

Functions

describe_int

fn describe_int(n: Int) -> String

unwrap_or

fn unwrap_or(opt: Option[Int], default: Int) -> Int

classify

fn classify(n: Int) -> String

describe

fn describe(opt: Option[Option[Int]]) -> String

area

fn area(rect:

color_code

fn color_code(c: Color) -> Int

main

fn main()

Types

Option

type Option[T] = Some(T) | None

Color

type Color = Red | Green | Blue

pipe_filter

Functions

double

fn double(n: Int) -> Int

add_ten

fn add_ten(n: Int) -> Int

is_even

fn is_even(n: Int) -> Bool

shout

fn shout(s: String) -> String

greet

fn greet(name: String) -> String

main

fn main()

pipeline

Functions

main

fn main()

receive

Functions

main

fn main()

Actors

Echo

actor Echo

MainActor

actor MainActor

shared_counter

Functions

main

fn main()

Actors

Counter

actor Counter

Worker

actor Worker

supervisor_tree

Functions

main

fn main()

Actors

Worker

actor Worker

variant_option

Functions

unwrap_or

fn unwrap_or(o: Option[Int], default: Int) -> Int

Types

Option

type Option[T] = Some(T) | None

worker_pool

Functions

main

fn main()

Actors

PoolWorker

actor PoolWorker

prelude

Types

Option

type Option[T] = Some(T) | None

Result

type Result[Ok, Err] = Ok(Ok) | Error(Err)

core

Functions

map

pub fn map[T, U](opt: Option[T], f: fn(T) -> U) -> Option[U]

Map a function over an Option.

and_then

pub fn and_then[T, U](opt: Option[T], f: fn(T) -> Option[U]) -> Option[U]

Chain an Option-returning function.

unwrap_or

pub fn unwrap_or[T](opt: Option[T], default: T) -> T

Extract the value or return a default.

is_some

pub fn is_some[T](opt: Option[T]) -> Bool

Returns true if the Option is Some.

is_none

pub fn is_none[T](opt: Option[T]) -> Bool

Returns true if the Option is None.

map_result

pub fn map_result[T, U, E](r: Result[T, E], f: fn(T) -> U) -> Result[U, E]

Map a function over a successful Result.

map_error

pub fn map_error[T, E, F](r: Result[T, E], f: fn(E) -> F) -> Result[T, F]

Map a function over the error case.

and_then_result

pub fn and_then_result[T, U, E](r: Result[T, E], f: fn(T) -> Result[U, E]) -> Result[U, E]

Chain a Result-returning function.

unwrap_or_result

pub fn unwrap_or_result[T, E](r: Result[T, E], default: T) -> T

Extract the value or return a default.

is_ok

pub fn is_ok[T, E](r: Result[T, E]) -> Bool

Returns true if the Result is Ok.

is_error

pub fn is_error[T, E](r: Result[T, E]) -> Bool

Returns true if the Result is Error.

id

pub fn id[T](x: T) -> T

Identity function. Returns its argument unchanged.

compose

pub fn compose[A, B, C](f: fn(B) -> C, g: fn(A) -> B) -> fn(A) -> C

Function composition: (f ∘ g)(x) = f(g(x)).

const_fn

pub fn const_fn[T, U](x: T, _y: U) -> T

Constant function: always returns the same value.

expect

pub fn expect[T, E](r: Result[T, E], msg: String, default: T) -> T

Unwrap a Result, panicking with the given message on Error. Unwrap a Result, printing an error message on Error and returning a default.

or_else

pub fn or_else[T, E](r: Result[T, E], fallback: fn(E) -> T) -> T

ok_or

pub fn ok_or[T, E](opt: Option[T], err: E) -> Result[T, E]

Convert an Option to a Result, using a default error on None.

flat_map

pub fn flat_map[T, U, E](r: Result[T, E], f: fn(T) -> Result[U, E]) -> Result[U, E]

Apply a fallible function if the Result is Ok, otherwise propagate the error. Shorter alias for and_then_result.

Types

Option

pub type Option[T] = Some(T) | None

Optional value: either Some(value) or None.

Result

pub type Result[T, E] = Ok(T) | Error(E)

Result of a fallible operation: either Ok(value) or Error(reason).

http

Functions

get

pub fn get(url: String) -> String !

Perform an HTTP GET request. Returns the response body as a String. Requires the runtime host (not available in standalone VM).

post

pub fn post(url: String, body: String) -> String !

Perform an HTTP POST request with a body. Returns the response body as a String. Requires the runtime host (not available in standalone VM).

Types

HttpError

pub type HttpError = Timeout | ConnectionRefused | BadStatus(Int) | Other(String)

Error type for HTTP operations.

json

Functions

parse

pub fn parse(json: String) -> JsonValue

Parse a JSON string into a JsonValue. Uses the built-in JSON.parse operation.

stringify

pub fn stringify(value: JsonValue) -> String

Convert a JsonValue back to a JSON string. Uses the built-in JSON.stringify operation.

get_string

pub fn get_string(obj: JsonValue, key: String, default: String) -> String

Get a string field from a JSON object, or return a default.

get_number

pub fn get_number(obj: JsonValue, key: String, default: Float) -> Float

Get a number field from a JSON object, or return a default.

get_bool

pub fn get_bool(obj: JsonValue, key: String, default: Bool) -> Bool

Get a bool field from a JSON object, or return a default.

Types

JsonValue

pub type JsonValue =

Represents a parsed JSON value.

list

Functions

map

pub fn map[T, U](arr: [T], f: fn(T) -> U) -> [U]

Map a function over every element, returning a new array.

filter

pub fn filter[T](arr: [T], pred: fn(T) -> Bool) -> [T]

Keep elements that satisfy a predicate.

fold

pub fn fold[T, U](arr: [T], init: U, f: fn(U, T) -> U) -> U

Reduce from the left: fold([a,b,c], init, f) = f(f(f(init,a),b),c).

append

pub fn append[T](left: [T], right: [T]) -> [T]

Append two arrays into a new array.

reverse

pub fn reverse[T](arr: [T]) -> [T]

Reverse an array.

nth

pub fn nth[T](arr: [T], n: Int, default: T) -> T

Get the nth element (0-indexed), or return default if out of bounds.

take

pub fn take[T](arr: [T], n: Int) -> [T]

Take the first n elements.

drop

pub fn drop[T](arr: [T], n: Int) -> [T]

Drop the first n elements.

any

pub fn any[T](arr: [T], pred: fn(T) -> Bool) -> Bool

Check if any element satisfies a predicate.

all

pub fn all[T](arr: [T], pred: fn(T) -> Bool) -> Bool

Check if all elements satisfy a predicate.

sort

pub fn sort[T](arr: [T]) -> [T]

Sort an array using insertion sort (stable, O(n²)).

zip

pub fn zip[T, U](left: [T], right: [U]) -> [(T, U)]

Zip two arrays into an array of pairs. Stops at the shorter length.

enumerate

pub fn enumerate[T](arr: [T]) -> [(Int, T)]

Pair each element with its index: [(0, arr[0]), (1, arr[1]), ...].

range

pub fn range(start: Int, end: Int) -> [Int]

Generate an array of integers from start (inclusive) to end (exclusive).

group_by

pub fn group_by[T, K](arr: [T], key_fn: fn(T) -> K) -> [(K, [T])]

Group elements by a key function. Returns an array of (key, group) pairs.

map

Functions

empty

pub fn empty() -> [(Int, Int)]

An empty map.

insert

pub fn insert(map: [(Int, Int)], key: Int, v: Int) -> [(Int, Int)]

Insert a key-value pair.

get

pub fn get(map: [(Int, Int)], key: Int) -> Option[Int]

Look up a key.

remove

pub fn remove(map: [(Int, Int)], key: Int) -> [(Int, Int)]

Remove a key.

contains

pub fn contains(map: [(Int, Int)], key: Int) -> Bool

Check whether a key is present.

size

pub fn size(map: [(Int, Int)]) -> Int

Number of key-value pairs.

math

Functions

abs

pub fn abs(x: Int) -> Int

Absolute value.

min

pub fn min(a: Int, b: Int) -> Int

Minimum of two integers.

max

pub fn max(a: Int, b: Int) -> Int

Maximum of two integers.

clamp

pub fn clamp(x: Int, lo: Int, hi: Int) -> Int

Clamp x to the range [lo, hi].

pow

pub fn pow(base: Int, exp: Int) -> Int

Integer exponentiation (x^y) for non-negative y.

factorial

pub fn factorial(n: Int) -> Int

Factorial. Returns 1 for n <= 1.

gcd

pub fn gcd(a: Int, b: Int) -> Int

Greatest common divisor (Euclidean algorithm).

set

Functions

empty

pub fn empty() -> [Int]

An empty set.

contains

pub fn contains(set: [Int], value: Int) -> Bool

Check whether a value is in the set.

insert

pub fn insert(set: [Int], value: Int) -> [Int]

Insert a value into the set.

remove

pub fn remove(set: [Int], value: Int) -> [Int]

Remove a value from the set.

size

pub fn size(set: [Int]) -> Int

Number of elements in the set.

string

Functions

trim

pub fn trim(s: String) -> String

Remove leading and trailing whitespace from a string.

length

pub fn length(s: String) -> Int

Get the length of a string in bytes.

is_empty

pub fn is_empty(s: String) -> Bool

Check if the string is empty.

split

pub fn split(s: String, delim: Int) -> [String]

Split a string by a delimiter character. Returns an array of substrings.

join

pub fn join(parts: [String], sep: String) -> String

Join an array of strings with a separator.

replace

pub fn replace(s: String, from: String, to: String) -> String

Replace all occurrences of from with to in a string.

to_upper

pub fn to_upper(s: String) -> String

Convert a string to uppercase (ASCII letters only).

to_lower

pub fn to_lower(s: String) -> String

Convert a string to lowercase (ASCII letters only).

contains

pub fn contains(s: String, sub: String) -> Bool

Check whether s contains the substring sub.

starts_with

pub fn starts_with(s: String, prefix: String) -> Bool

Check whether s starts with prefix.

ends_with

pub fn ends_with(s: String, suffix: String) -> Bool

Check whether s ends with suffix.

test

Functions

assert_eq

pub fn assert_eq[T](actual: T, expected: T)

Assert that two values are equal. Prints a message and exits with an error if they differ.

assert_true

pub fn assert_true(condition: Bool)

Assert that a boolean condition is true.

assert_false

pub fn assert_false(condition: Bool)

Assert that a boolean condition is false.

fail

pub fn fail(message: String)

Fail unconditionally with a message.