Data types
rustack has following value types. It is dynamically typed language, so each stack element can have any type at any time.
- Int (i32)
- Num (f32)
- Symbol
- Block
- Native
Built-in functions
As an experimental language, it has only few Built-in functions.
- "puts" - Pop a value from the stack and print it to the console.
- "+" - addition
- "-" - subtraction
- "*" - multiplication
- "/" - division
- "<" - less-than (yields 1 if true, otherwise 0)
- "and" - logical AND (yields 1 if both of 2 operands are nonzero, otherwise 0)
- "or" - logical OR (yields 1 if both of 2 operands are nonzero, otherwise 0)
- "if" - conditional branching, taking 3 argument blocks
- "for" - Pop (start, end, block), loop from start through end, calling block with the iteration number pushed to the operand stack
- "def" - pop a symbol (name) and a value and define a variable (a scalar) or a function (a block)
- "pop" - pop the topmost value from the stack
- "dup" - duplicate the topmost value of the stack and push it
- "exch" - exchange the topmost 2 values
- "index" - pop a value from the stack, and extract a value at stack index specified by the popped value
- "load" - pop a value from the stack, get a value from dictionary stack with the popped value as the key and push it without executing it
Canvas rendering functions
- "rectangle" - Pop (x, y, width, height) values from the stack and render a filled rectangle in the canvas.
- "set_fill_style" - Pop (r, g, b) values from the stack and sets the color of following fill commands.
- "set_stroke_style" - Pop (r, g, b) values from the stack and sets the color of following stroke commands.
- "move_to" - Pop (x, y) values from the stack and call CanvasRenderingContext2D.moveTo
- "line_to" - Pop (x, y) values from the stack and call CanvasRenderingContext2D.lineTo
- "stroke" - Call CanvasRenderingContext2D.stroke
- "rotate" - Pop angle value from the stack and call CanvasRenderingContext2D.rotate
- "translate" - Pop (x, y) values from the stack and call CanvasRenderingContext2D.translate
- "save" - Call CanvasRenderingContext2D.save
- "restore" - Call CanvasRenderingContext2D.restore
Time measurement resolution
Due to security reasons, your browser may have reduced time resolution for measurement. It is typically 0.1ms or 1ms, but can be larger. Please be aware that the lower digits may be always 0 because of this rounding. See
this page for details.