@stagas/mono v0.1.0
Install
$ npm i @stagas/mono
-- work in progress --
API
Table of Contents
todo
todo is a "not implemented" marker for ops
bin
constructs a binary op of least type type
Parameters
type
Typeop
string
Returns Op
typebin
constructs a binary op of exact type type
Parameters
type
Typeop
string
Returns Op
eq
constructs an equality op
Parameters
op
string
Returns Op
funcDef
defines a function
Parameters
ctx
Contextops
OpTablesym
(Token | string)args
Array[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)rhs
Node
Op
primary optable
Type: OpTable
OpArgs
arguments optable
Type: OpTable
build
builds a node
under context ctx
and optable ops
Parameters
node
Nodectx
Contextops
OpTable
Returns SExpr
map
builds an array of nodes
under context ctx
and optable ops
Parameters
nodes
Array[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)ctx
Contextops
OpTable
Returns Array\
typeOf
looks up and returns the type of x
, if found, otherwise returns type any
Parameters
Returns Type
typeAs
marks sexpr x
to be of type type
Parameters
type
Typex
SExpr
cast
creates a cast operation if the given value x
doesn't satisfy type
Parameters
type
Typex
SExpr
castAll
casts all values
to be of type type
Parameters
type
Typevalues
...SExpr
Returns SExpr
hi
returns the highest precision type of the given values
Parameters
values
...SExpr
Returns Type
max
returns at least the precision of the given type among the given types
Parameters
type
Typetypes
...Array\
Returns Type
top
types an operation with the correct prefix (f32 or i32) and type casts the values to satisfy the op
Parameters
type
Typeops
SExpr
Returns SExpr
infer
infers the type of a token literal string: bool for 0 or 1, i32 for integers and f32 for floats
Parameters
x
Token
Returns Type
flatten
flattens a node that is left hand side recursing on symbol sym
Parameters
Returns Array[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)
mush
Merges or pUSHes obj
to array arr
Parameters
arr
Array\obj
any
Contribute
All contributions are welcome!
License
MIT © 2022 stagas