rm push/pop

This commit is contained in:
2026-02-26 08:13:18 -06:00
parent eb19b18594
commit a1b41d5ecf
59 changed files with 19546 additions and 19265 deletions

View File

@@ -27,13 +27,13 @@ function send(mailbox, msg) {
function receive(mailbox) {
if (length(mailbox.queue) == 0) return null
mailbox.delivered++
return pop(mailbox.queue)
return mailbox.queue[]
}
function drain(mailbox) {
var count = 0
while (length(mailbox.queue) > 0) {
pop(mailbox.queue)
mailbox.queue[]
count++
}
return count

View File

@@ -13,13 +13,13 @@ function generate_records(n) {
var dept_vals = ["eng", "sales", "ops", "hr", "marketing"]
for (i = 0; i < n; i++) {
x = ((x * 1103515245 + 12345) & 0x7FFFFFFF) | 0
push(records, {
records[] = {
id: i + 1,
name: `user_${i}`,
score: (x % 1000) / 10,
status: status_vals[i % 4],
department: dept_vals[i % 5]
})
}
}
return records
}
@@ -30,7 +30,7 @@ function filter_records(records, field, value) {
var i = 0
for (i = 0; i < length(records); i++) {
if (records[i][field] == value) {
push(result, records[i])
result[] = records[i]
}
}
return result
@@ -45,7 +45,7 @@ function group_by(records, field) {
key = records[i][field]
if (!key) key = "unknown"
if (!groups[key]) groups[key] = []
push(groups[key], records[i])
groups[key][] = records[i]
}
return groups
}
@@ -70,13 +70,13 @@ function aggregate(groups) {
if (grp[j].score < mn) mn = grp[j].score
if (grp[j].score > mx) mx = grp[j].score
}
push(result, {
result[] = {
group: keys[i],
count: length(grp),
average: total / length(grp),
low: mn,
high: mx
})
}
}
return result
}

View File

@@ -57,7 +57,7 @@ function build_chain(n) {
var constraints = []
var i = 0
for (i = 0; i < n; i++) {
push(vars, make_variable(`v${i}`, 0))
vars[] = make_variable(`v${i}`, 0)
}
// Set first variable
@@ -69,8 +69,8 @@ function build_chain(n) {
self.variables[1].value = self.variables[0].value + 1
self.output = self.variables[1]
})
push(constraints, c)
push(vars[i].constraints, c)
constraints[] = c
vars[i].constraints[] = c
}
return {vars: vars, constraints: constraints}
@@ -83,8 +83,8 @@ function build_projection(n) {
var constraints = []
var i = 0
for (i = 0; i < n; i++) {
push(src, make_variable(`src${i}`, i * 10))
push(dst, make_variable(`dst${i}`, 0))
src[] = make_variable(`src${i}`, i * 10)
dst[] = make_variable(`dst${i}`, 0)
}
var scale_c = null
@@ -93,8 +93,8 @@ function build_projection(n) {
self.variables[1].value = self.variables[0].value * 2 + 1
self.output = self.variables[1]
})
push(constraints, scale_c)
push(dst[i].constraints, scale_c)
constraints[] = scale_c
dst[i].constraints[] = scale_c
}
return {src: src, dst: dst, constraints: constraints}

View File

@@ -12,7 +12,7 @@ function make_words(count) {
var words = []
var i = 0
for (i = 0; i < count; i++) {
push(words, base_words[i % length(base_words)])
words[] = base_words[i % length(base_words)]
}
return words
}
@@ -39,7 +39,7 @@ function top_n(freq, n) {
var pairs = []
var i = 0
for (i = 0; i < length(keys); i++) {
push(pairs, {word: keys[i], count: freq[keys[i]]})
pairs[] = {word: keys[i], count: freq[keys[i]]}
}
var sorted = sort(pairs, "count")
// Return last N (highest counts)
@@ -47,7 +47,7 @@ function top_n(freq, n) {
var start = length(sorted) - n
if (start < 0) start = 0
for (i = start; i < length(sorted); i++) {
push(result, sorted[i])
result[] = sorted[i]
}
return result
}
@@ -62,7 +62,7 @@ function group_by_length(words) {
w = words[i]
k = text(length(w))
if (!groups[k]) groups[k] = []
push(groups[k], w)
groups[k][] = w
}
return groups
}

View File

@@ -27,13 +27,13 @@ function make_array_data(size) {
var arr = []
var i = 0
for (i = 0; i < size; i++) {
push(arr, {
arr[] = {
id: i,
name: `item_${i}`,
active: i % 2 == 0,
score: i * 1.5,
tags: [`tag_${i % 5}`, `tag_${(i + 1) % 5}`]
})
}
}
return arr
}

View File

@@ -16,7 +16,7 @@ function make_obj_yx(x, y) {
function make_packed_array(n) {
var a = []
var i = 0
for (i = 0; i < n; i++) push(a, i)
for (i = 0; i < n; i++) a[] = i
return a
}
@@ -144,7 +144,7 @@ return {
var a = null
for (j = 0; j < n; j++) {
a = []
for (i = 0; i < 256; i++) push(a, i)
for (i = 0; i < 256; i++) a[] = i
x = (x + length(a)) | 0
}
return blackhole(sink, x)

View File

@@ -272,7 +272,7 @@ return {
for (i = 0; i < n; i++) {
push(a, i)
if (length(a) > 64) {
v = pop(a)
v = a[]
x = (x + v) | 0
}
}

View File

@@ -16,21 +16,21 @@ function tokenize(src) {
ch = chars[i]
if (ch == " " || ch == "\n" || ch == "\t") {
if (length(buf) > 0) {
push(tokens, buf)
tokens[] = buf
buf = ""
}
} else if (ch == "(" || ch == ")" || ch == "+" || ch == "-"
|| ch == "*" || ch == "=" || ch == ";" || ch == ",") {
if (length(buf) > 0) {
push(tokens, buf)
tokens[] = buf
buf = ""
}
push(tokens, ch)
tokens[] = ch
} else {
buf = buf + ch
}
}
if (length(buf) > 0) push(tokens, buf)
if (length(buf) > 0) tokens[] = buf
return tokens
}
@@ -49,21 +49,21 @@ function parse_tokens(tokens) {
i++ // skip =
i++
if (i < length(tokens)) node.value = tokens[i]
push(ast, node)
ast[] = node
} else if (tok == "return") {
node = {type: "return", value: null}
i++
if (i < length(tokens)) node.value = tokens[i]
push(ast, node)
ast[] = node
} else if (tok == "function") {
node = {type: "func", name: null, body: []}
i++
if (i < length(tokens)) node.name = tokens[i]
// Skip to matching )
while (i < length(tokens) && tokens[i] != ")") i++
push(ast, node)
ast[] = node
} else {
push(ast, {type: "expr", value: tok})
ast[] = {type: "expr", value: tok}
}
}
return ast
@@ -121,7 +121,7 @@ function simulate_build(n_modules, deps_per_module) {
// Generate all module sources
for (i = 0; i < n_modules; i++) {
src = generate_module(i, deps_per_module)
push(modules, src)
modules[] = src
}
// "Load" each module: tokenize → parse → evaluate
@@ -173,7 +173,7 @@ function topo_sort(n_modules, deps_per_module) {
for (j = 0; j < deps_per_module; j++) {
if (j < i) {
dep = "mod_" + text(j)
push(adj[dep], name)
adj[dep][] = name
in_degree[name] = in_degree[name] + 1
}
}
@@ -183,7 +183,7 @@ function topo_sort(n_modules, deps_per_module) {
var queue = []
var keys = array(in_degree)
for (i = 0; i < length(keys); i++) {
if (in_degree[keys[i]] == 0) push(queue, keys[i])
if (in_degree[keys[i]] == 0) queue[] = keys[i]
}
var order = []
@@ -193,12 +193,12 @@ function topo_sort(n_modules, deps_per_module) {
while (qi < length(queue)) {
current = queue[qi]
qi++
push(order, current)
order[] = current
neighbors = adj[current]
if (neighbors) {
for (i = 0; i < length(neighbors); i++) {
in_degree[neighbors[i]] = in_degree[neighbors[i]] - 1
if (in_degree[neighbors[i]] == 0) push(queue, neighbors[i])
if (in_degree[neighbors[i]] == 0) queue[] = neighbors[i]
}
}
}

View File

@@ -7,7 +7,7 @@ function make_random_array(n, seed) {
var i = 0
for (i = 0; i < n; i++) {
x = ((x * 1103515245 + 12345) & 0x7FFFFFFF) | 0
push(a, x % 10000)
a[] = x % 10000
}
return a
}
@@ -15,7 +15,7 @@ function make_random_array(n, seed) {
function make_descending(n) {
var a = []
var i = 0
for (i = n - 1; i >= 0; i--) push(a, i)
for (i = n - 1; i >= 0; i--) a[] = i
return a
}
@@ -58,19 +58,19 @@ function merge(a, b) {
var j = 0
while (i < length(a) && j < length(b)) {
if (a[i] <= b[j]) {
push(result, a[i])
result[] = a[i]
i++
} else {
push(result, b[j])
result[] = b[j]
j++
}
}
while (i < length(a)) {
push(result, a[i])
result[] = a[i]
i++
}
while (j < length(b)) {
push(result, b[j])
result[] = b[j]
j++
}
return result
@@ -97,7 +97,7 @@ function sort_records(n) {
var i = 0
for (i = 0; i < n; i++) {
x = ((x * 1103515245 + 12345) & 0x7FFFFFFF) | 0
push(records, {id: i, score: x % 10000, name: `item_${i}`})
records[] = {id: i, score: x % 10000, name: `item_${i}`}
}
return sort(records, "score")
}

View File

@@ -23,7 +23,7 @@ function build_index(txt) {
if (!index[w]) {
index[w] = []
}
push(index[w], i)
index[w][] = i
}
return index
}

View File

@@ -48,7 +48,7 @@ function tree_map(node, fn) {
function tree_flatten(node, result) {
if (!node) return null
tree_flatten(node.left, result)
push(result, node.val)
result[] = node.val
tree_flatten(node.right, result)
return null
}
@@ -126,7 +126,7 @@ return {
// Build a balanced BST of 1024 elements
var data = []
var i = 0
for (i = 0; i < 1024; i++) push(data, i)
for (i = 0; i < 1024; i++) data[] = i
var bst = build_balanced(data, 0, 1023)
var found = 0
for (i = 0; i < n; i++) {