Reference

Compiled numbers

A top-level function that only does arithmetic on ints, floats and bools is compiled to machine code (with Cranelift) the second time it is called, or the first if it has a loop of its own, for the types of the arguments it gets: let, assignment, if, &&, ||, return, for over range(...) or a..b, while, and calls of other such functions, itself included. So is a lambda of that kind given a number, as map and filter give one: xs | filter((x) => x % 3 == 0). It then runs as it would have, only faster: fib(32) takes 11 ms (Node 11, Bun 21), and a loop of ten million steps 29 ms (Node and Bun take about 280 ms for the same loop, on doubles).

A loop goes to machine code by itself, wherever it is: in a function that does other things too, or at a script's top. Its first 256 rounds run in the interpreter; a loop that has gone that far is compiled for the types its variables have then, and goes on from the round it is at. Its body may use ints, floats and bools, lists of them and lists of such lists held in variables: xs[i], g[y][x], len(xs), and xs = xs | set(i, v), g = set(g, y, set(g[y], x, v)) and xs = xs | push(v) in any of their forms; texts: s[i] (a character, as the interpreter gives it), let c = s[i], len(s), a character compared with a quoted text, another character or null, and s += x or s = s + x; counting into a map by an int key, m = m | set(k, get(m, k, d) + e) (also -, * and set(m, ...), with a number for d); let, assignment, if, for over a range and while. A list read in a loop costs about 4 ns a round, written about 5, where the interpreter takes 45 (FEEDBACK29.md); a text read by index about 1. A loop that appends to a text and reads it by index in the same loop is not compiled.

Thread
10Useful? Like it, or add to its thread below.

Thread 0 posts

On Compiled numbers: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · made from the user guide · questions on Discord or r/quillo