Arc namespace for BEAM integration.
Built-in architecture
Location:src/arc/vm/builtins/*.gleam
Each built-in object is implemented as a Gleam module that exports:
- Initialization: Create the constructor and prototype
- Methods: Native function implementations
- Properties: Standard properties (name, length, etc.)
Builtins registry
Standard built-ins
Object
File:src/arc/vm/builtins/object.gleam
Object constructor methods
Object constructor methods
Object.create(proto, [descriptors])— Create object with specified prototypeObject.defineProperty(obj, key, descriptor)— Define/modify propertyObject.defineProperties(obj, descriptors)— Define multiple propertiesObject.getPrototypeOf(obj)— Get object’s prototypeObject.setPrototypeOf(obj, proto)— Set object’s prototypeObject.keys(obj)— Array of enumerable own string keysObject.values(obj)— Array of enumerable own property valuesObject.entries(obj)— Array of [key, value] pairsObject.assign(target, ...sources)— Copy enumerable own propertiesObject.freeze(obj)— Make object immutableObject.seal(obj)— Prevent extensions, make properties non-configurableObject.preventExtensions(obj)— Prevent adding new propertiesObject.isFrozen(obj)— Check if frozenObject.isSealed(obj)— Check if sealedObject.isExtensible(obj)— Check if extensibleObject.getOwnPropertyNames(obj)— Array of all own string keysObject.getOwnPropertyDescriptor(obj, key)— Get property descriptorObject.getOwnPropertyDescriptors(obj)— Get all descriptorsObject.hasOwn(obj, key)— Check for own property (ES2022)
Object.prototype methods
Object.prototype methods
toString()— Convert to string ("[object Object]")valueOf()— Return primitive value (returns this)hasOwnProperty(key)— Check for own propertyisPrototypeOf(obj)— Check if this is in obj’s prototype chainpropertyIsEnumerable(key)— Check if property is enumerable
Array
File:src/arc/vm/builtins/array.gleam
Array constructor methods
Array constructor methods
Array.isArray(value)— Check if value is an arrayArray.from(arrayLike, [mapFn])— Create array from iterable/array-likeArray.of(...items)— Create array from arguments
Array.prototype methods
Array.prototype methods
Mutating:
push(...items)— Add to end, return new lengthpop()— Remove from end, return itemshift()— Remove from start, return itemunshift(...items)— Add to start, return new lengthsplice(start, deleteCount, ...items)— Remove/add elementsreverse()— Reverse in placesort([compareFn])— Sort in placefill(value, [start, end])— Fill with value
concat(...arrays)— Merge arraysslice([start, end])— Extract subarrayjoin([separator])— Join to stringindexOf(item, [start])— Find first indexlastIndexOf(item, [start])— Find last indexincludes(item, [start])— Check if contains (ES2016)
forEach(fn, [thisArg])— Execute fn for each elementmap(fn, [thisArg])— Transform elementsfilter(fn, [thisArg])— Select elementsreduce(fn, [initial])— Reduce to single valuereduceRight(fn, [initial])— Reduce right-to-leftfind(fn, [thisArg])— Find first matching element (ES2015)findIndex(fn, [thisArg])— Find first matching index (ES2015)every(fn, [thisArg])— Test if all matchsome(fn, [thisArg])— Test if any matchflat([depth])— Flatten nested arrays (ES2019)flatMap(fn, [thisArg])— Map then flatten (ES2019)
String
File:src/arc/vm/builtins/string.gleam
String constructor methods
String constructor methods
String.fromCharCode(...codes)— Create string from char codesString.fromCodePoint(...codePoints)— Create string from code points (ES2015)
String.prototype methods
String.prototype methods
charAt(index)— Character at indexcharCodeAt(index)— Char code at indexcodePointAt(index)— Code point at index (ES2015)concat(...strings)— Concatenate stringsindexOf(search, [start])— Find first occurrencelastIndexOf(search, [start])— Find last occurrenceslice(start, [end])— Extract substringsubstring(start, [end])— Extract substring (legacy)substr(start, [length])— Extract substring (deprecated)toLowerCase()— Convert to lowercasetoUpperCase()— Convert to uppercasetrim()— Remove whitespace from both endstrimStart()/trimLeft()— Remove leading whitespace (ES2019)trimEnd()/trimRight()— Remove trailing whitespace (ES2019)repeat(count)— Repeat string (ES2015)padStart(targetLength, [padString])— Pad start (ES2017)padEnd(targetLength, [padString])— Pad end (ES2017)startsWith(search, [start])— Check prefix (ES2015)endsWith(search, [end])— Check suffix (ES2015)includes(search, [start])— Check substring (ES2015)split(separator, [limit])— Split to arraymatch(regexp)— Match regexpreplace(search, replacement)— Replace first occurrencereplaceAll(search, replacement)— Replace all occurrences (ES2021)
Number
File:src/arc/vm/builtins/number.gleam
Number constructor properties
Number constructor properties
Number.EPSILON— Smallest interval between numbersNumber.MAX_VALUE— Largest finite numberNumber.MIN_VALUE— Smallest positive numberNumber.MAX_SAFE_INTEGER— 2^53 - 1Number.MIN_SAFE_INTEGER— -(2^53 - 1)Number.POSITIVE_INFINITY— InfinityNumber.NEGATIVE_INFINITY— -InfinityNumber.NaN— Not-a-Number
Number constructor methods
Number constructor methods
Number.isFinite(value)— Check if finite numberNumber.isInteger(value)— Check if integerNumber.isNaN(value)— Check if NaNNumber.isSafeInteger(value)— Check if safe integer (ES2015)Number.parseFloat(string)— Parse floatNumber.parseInt(string, [radix])— Parse integer
Number.prototype methods
Number.prototype methods
toFixed([digits])— Format with fixed decimalstoExponential([digits])— Format in exponential notationtoPrecision([precision])— Format to precisiontoString([radix])— Convert to string (with radix)valueOf()— Return primitive value
Function
File:src/arc/vm/builtins/function.gleam
Function.prototype methods
Function.prototype methods
call(thisArg, ...args)— Call with specified this and argumentsapply(thisArg, argsArray)— Call with specified this and array of argumentsbind(thisArg, ...args)— Create bound function (ES2015)toString()— Return function source (returns “[native code]” for builtins)
Promise
File:src/arc/vm/builtins/promise.gleam
Promise constructor methods
Promise constructor methods
Promise.resolve(value)— Create resolved promisePromise.reject(reason)— Create rejected promisePromise.all(promises)— Wait for all promises (ES2015)Promise.race(promises)— Wait for first promise (ES2015)Promise.allSettled(promises)— Wait for all to settle (ES2020)Promise.any(promises)— Wait for first fulfillment (ES2021)
Promise.prototype methods
Promise.prototype methods
then(onFulfilled, [onRejected])— Chain promisecatch(onRejected)— Handle rejectionfinally(onFinally)— Execute regardless of outcome (ES2018)
Map & Set
Files:src/arc/vm/builtins/map.gleam, src/arc/vm/builtins/set.gleam
Map.prototype methods
Map.prototype methods
set(key, value)— Add/update entryget(key)— Retrieve valuehas(key)— Check if key existsdelete(key)— Remove entryclear()— Remove all entriesforEach(fn, [thisArg])— Iterate over entrieskeys()— Iterator over keysvalues()— Iterator over valuesentries()— Iterator over [key, value] pairssize(property) — Number of entries
Set.prototype methods
Set.prototype methods
add(value)— Add valuehas(value)— Check if value existsdelete(value)— Remove valueclear()— Remove all valuesforEach(fn, [thisArg])— Iterate over valuesvalues()— Iterator over valueskeys()— Iterator over values (alias)entries()— Iterator over [value, value] pairssize(property) — Number of values
Error types
File:src/arc/vm/builtins/error.gleam
Error(message)— Base errorTypeError(message)— Type errorsRangeError(message)— Range/bounds errorsReferenceError(message)— Reference errors (undefined variables)SyntaxError(message)— Syntax errorsURIError(message)— URI encoding/decoding errors
new Error(message)— Create error with message.messageproperty — Error message.nameproperty — Error type name.toString()— Format as string
Math object
File:src/arc/vm/builtins/math.gleam
Math constants
Math constants
Math.E— Euler’s number (~2.718)Math.PI— π (~3.14159)Math.LN2— ln(2)Math.LN10— ln(10)Math.LOG2E— log₂(e)Math.LOG10E— log₁₀(e)Math.SQRT2— √2Math.SQRT1_2— √(1/2)
Math methods
Math methods
Math.abs(x)— Absolute valueMath.sign(x)— Sign (-1, 0, 1)Math.ceil(x)— CeilingMath.floor(x)— FloorMath.round(x)— Round to nearest integerMath.trunc(x)— Truncate to integer (ES2015)Math.min(...values)— Minimum valueMath.max(...values)— Maximum valueMath.pow(base, exponent)— ExponentiationMath.sqrt(x)— Square rootMath.cbrt(x)— Cube root (ES2015)Math.exp(x)— e^xMath.log(x)— Natural logarithmMath.log2(x)— Base-2 logarithm (ES2015)Math.log10(x)— Base-10 logarithm (ES2015)Math.sin(x)— SineMath.cos(x)— CosineMath.tan(x)— TangentMath.asin(x)— ArcsineMath.acos(x)— ArccosineMath.atan(x)— ArctangentMath.atan2(y, x)— Two-argument arctangentMath.random()— Random number in [0, 1)
JSON object
File:src/arc/vm/builtins/json.gleam
JSON.parse(text, [reviver])— Parse JSON string to JavaScript valueJSON.stringify(value, [replacer, space])— Serialize value to JSON string
Arc namespace (BEAM interop)
File:src/arc/vm/builtins/arc.gleam
The Arc namespace provides JavaScript access to BEAM VM features:
Process management
Utilities
Message serialization
Messages sent viaArc.send are serialized to a portable format:
Supported types:
- Primitives:
null,undefined,boolean,number,string,bigint,symbol - Arrays (shallow)
- Plain objects
{...}(shallow) - PIDs (first-class values)
- Functions
- Dates, RegExp
- Circular references
- Prototypes (objects become plain maps)
PID objects
PIDs are opaque JavaScript objects:Native function dispatch
Built-in methods are implemented as native Gleam functions:Adding new built-ins
To add a new built-in method:Performance notes
Built-in methods are native Gleam functions, not bytecode. They execute directly on the BEAM VM, making them significantly faster than JavaScript implementations.
- Use native methods when possible (
Array.prototype.mapis faster than a hand-rolled loop) - Minimize allocations (native methods can update heap efficiently)
- Arc-specific:
Arc.sendis very fast (direct BEAM message passing)
Array.prototype.push— ~1M ops/secArray.prototype.map— ~100K ops/sec (depends on callback)JSON.parse— ~50K ops/sec (small objects)Arc.send— ~500K msgs/sec
Further reading
VM
How native functions are invoked
Compiler
How user code is compiled
Builtins (source)
Complete builtin implementations