use _builtins

This module is contains the words necessary to implement the builtin functionality of Phoo, that must be defined in Javascript and not Phoo code for the ease of bootstrapping.

The rest of the built-in words, that are defined in Phoo code, can be found on the page for builtins (without the underscore).

/* ( → )

Block comment. Like C-style comments. Comments do not nest.

$ ( → sThe string (or regular expression) defined by the literal. )

String builder.

First non-whitespace character after the $ is the delimiter. The delimiter can be escaped by doubling it.

The characters immediately following the end delimiter are known as the “tag” and affect the resultant string. The first character is the code that determines the formatting applied.

There are two format codes implemented right now. The first is r, which turns the string into a regular expression. The characters after the r are the flags that would go at the end of it.

The second is e, which escapes characters in the same manner as \\ does in Javascript strings.

Example:


$ fixdafei
// puts the string "\xDA".

do ( → )

Starts of a new sub-array.

[ ( → )

Same as do.

end ( → )

End of a sub-array.

] ( → )

Same as end.

pick ( nDepth of item to pickiAdditional pointer to the item )

Same as the Forth word PICK. Takes a number n and copies the nth item to the top.

See Also: roll

roll ( nDepth of item to pickithe item )

Same as the Forth word ROLL. Takes a number n and moves the nth item to the top .

See Also: pick

drop ( n → )

Removes the top item from the stack.

1+ ( nn+1 )

Increments a number on the top of the stack.

1- ( nn-1 )

Decrements a number on the top of the stack.

+ ( a bb+a )

Adds two items together using Javascript + operator. Note the order of addition.

negate ( a-a )

Unary negation of top item.

* ( a bb*a )

Multiply top items.

** ( bbase eexponentb**e )

Power of top two items.

/mod ( xdividend ydivisorqquotient rremainder )

Euclidean division. Remainder and quotient.

/ ( adividend bdivisorqquotient )

Regular division (results in float).

= ( a bt )

Equals, using Javascript == operator.

> ( anumber on “larger” (left) side of expression. bnumber on “smaller” (right) side of expression.t )

Greater than.

nand ( a bt )

Boolean NAND of two arguments. True if both are false.

~ ( n~n )

Bitwise NOT of a number.

& ( a ba&b )

Bitwise AND of two numbers.

| ( a ba|b )

Bitwise OR of two numbers.

^ ( a ba^b )

Bitwise XOR of two numbers.

<< ( a ba<<b )

A bit-shifted left by B places. Negative B for shift right.

put ( iItem to push aArray to push onto → )

Pushes the item onto the end of the array.

See Also: take

take ( aArrayiLast item of the array )

Reverse of put, it takes the item out of the array. The array is mutated.

]done[ ( → )

Drops the top item of the return stack, effectively causing everything else outside of the current word to be skipped.

Example:


[ foo [ ]done[ bar ] baz ]
// foo and then bar are run, but baz is skipped.

]again[ ( → )

Sets the return pointer of the top return stack item to -1, effectively causing everything else outside of the current word to be repeated.

Example:


[ foo [ ]again[ bar ] baz ]
// runs foo bar foo bar foo bar foo bar ... infintely

]cjump[ ( ttruth value to test nhow far to jump if false → )

If the test value t is false, adds n to the top return stack entry’s return pointer, effectively skipping that many items.

Example:


[ 3 ]cjump[ ] foo bar baz bam
// if ToS is false, skips foo bar baz. bam will always run

]'[ ( → a )

Instead of running the next item on the top return stack entry, pushes it to the stack and crements the return stack pointer.

Example:


[ ]'[ drop ] foo bar
// foo will be pushed to the stack and then dropped, rendering it a noop. bar will run.

]run[ ( a → )

Pushes the item to the return stack, so that it will run when the current word finishes.

Example:


[ table a b c ] [ ]run[ ]
// if ToS is n, runs nth item of the table.

]this[ ( a → )

Pushes the top array on the return stack to the work stack, so that the word can reference its caller.

[] ( → a )

Pushes a new, empty array to the work stack.

concat ( a bab )

Concatenates two arrays. non-arrays are treated like one-element arrays.

peek ( a ia[i] )

Takes the i-th item out of the array a, without changing a.

poke ( titem to poke athe array to be poked iindex to poke atathe array to be poked )

Puts the item into the specified index of the array, and leaves the new, mutated array.

]sandbox[ ( ce )

Runs the code under a try statement, and pushes the error it threw, or undefined if no error.

die ( m → )

Throws a PhooError with the message, or re-throws the error if it was already one.

]getstack[ ( et )

With a PhooError on the top, gets its Phoo stack trace.

type ( ot )

Gets the type of the object.

compile ( sa )

Compiles the string, so that it can be run.

time ( → t )

Pushes the system time, in milliseconds.

await ( pv )

Awaits a Promise and pushes the resolve value.

get ( oobject kstring keyvo.k )

Object and key, looks up.

set ( vvalue to set oobject kstring key → )

Value, object, and key, sets the key.

call ( aarguments array ffunctionrreturn value )

Calls a function with the arguments.

See Also: new

new ( aarguments array fconstructor functionrnew object constructed )

Same sort as call, but uses Javascript new keyword to construct with a class.

word ( sstringwsymbol of that string )

Converts string to symbol.

name ( wsymbolsstring of that symbol )

Reverse of word, converts symbol to string.

resolve ( wsymbolddefinition )

Looks up the definition of the word symbol.

{} ( → a )

Pushes a new empty object.

self ( → t )

Pushes a reference to the current thread.

window ( → t )

Pushes a reference to the global Javascript object (globalThis). Called “window” because that is its name in the browser which is what Phoo was designed for.

]define[ ( nsymbol name ddefinition → )

Writes a new definition to the top scope using the name and definition on the stack.

]define-macro[ ( nsymbol name ddefinition → )

Like ]define[ but defines a macro.

]forget[ ( nsymbol name → )

Erases the definition of a word, reverting back to the old one if there was one.

to name def ( → )

Wrapper for ]define[.

macro name def ( → )

Wrapper for ]define-macro[.

forget name ( → )

Wrapper for ]forget[.

]import[ ( nname of the module rboolean, force-reload the module → )

Imports the module, force-reloading if the top is true (ignores cache).

promise ( → pthe promise xreject callback rresolve callback )

Pushes the pieces to a new promise.

functionize ( cf )

Turns the code into a function, that will run the code in a subthread.


back to index

docs@04547c7