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

134
build.cm
View File

@@ -65,7 +65,7 @@ function replace_sigils(str, pkg_dir) {
function replace_sigils_array(flags, pkg_dir) {
var result = []
arrfor(flags, function(flag) {
push(result, replace_sigils(flag, pkg_dir))
result[] = replace_sigils(flag, pkg_dir)
})
return result
}
@@ -179,7 +179,7 @@ function bmfst_save(cmd_str, src_path, deps, obj_path) {
arrfor(deps, function(dep_path) {
var st = memo_stat(dep_path)
if (st)
push(entries, {p: dep_path, m: st.m, s: st.s})
entries[] = {p: dep_path, m: st.m, s: st.s}
})
var mf = {o: obj_path, d: entries}
var mf_path = bmfst_path(cmd_str, src_path)
@@ -191,16 +191,16 @@ function bmfst_save(cmd_str, src_path, deps, obj_path) {
function bmfst_dl_key(setup, link_info) {
var parts = [setup.cmd_str, setup.src_path]
push(parts, 'target:' + text(link_info.target))
push(parts, 'cc:' + text(link_info.cc))
parts[] = 'target:' + text(link_info.target)
parts[] = 'cc:' + text(link_info.cc)
arrfor(link_info.extra_objects, function(obj) {
if (obj != null) push(parts, 'extra:' + text(obj))
if (obj != null) parts[] = 'extra:' + text(obj)
})
arrfor(link_info.ldflags, function(flag) {
push(parts, 'ldflag:' + text(flag))
parts[] = 'ldflag:' + text(flag)
})
arrfor(link_info.target_ldflags, function(flag) {
push(parts, 'target_ldflag:' + text(flag))
parts[] = 'target_ldflag:' + text(flag)
})
return text(parts, '\n')
}
@@ -227,7 +227,7 @@ function bmfst_dl_save(setup, link_info, deps, dylib_path) {
arrfor(deps, function(dep_path) {
var st = memo_stat(dep_path)
if (st)
push(entries, {p: dep_path, m: st.m, s: st.s})
entries[] = {p: dep_path, m: st.m, s: st.s}
})
var mf = {dylib: dylib_path, d: entries}
var mf_path = cache_path(bmfst_dl_key(setup, link_info), SALT_BMFST_DL)
@@ -259,7 +259,7 @@ function get_c_deps(cc, flags, src_path) {
var dep_file = '/tmp/cell_deps_' + content_hash(src_path) + '.d'
var dep_cmd = [cc, '-MM', '-MG', '-MF', '"' + dep_file + '"']
dep_cmd = array(dep_cmd, flags)
push(dep_cmd, '"' + src_path + '"')
dep_cmd[] = '"' + src_path + '"'
var ret = os.system(text(dep_cmd, ' ') + ' 2>/dev/null')
if (ret != 0) return [src_path]
if (!fd.is_file(dep_file)) return [src_path]
@@ -274,9 +274,9 @@ function hash_all_deps(cmd_str, deps) {
arrfor(deps, function(dep_path) {
var content = memo_read(dep_path)
if (content != null)
push(parts, dep_path + '\n' + content)
parts[] = dep_path + '\n' + content
else
push(parts, dep_path + '\n<missing>')
parts[] = dep_path + '\n<missing>'
})
return text(parts, '\n')
}
@@ -310,16 +310,16 @@ function compile_setup(pkg, file, target, opts) {
common_flags = array(common_flags, ['-Os', '-DNDEBUG'])
}
push(common_flags, '-DCELL_USE_NAME=' + sym_name)
push(common_flags, '-I"' + pkg_dir + '"')
common_flags[] = '-DCELL_USE_NAME=' + sym_name
common_flags[] = '-I"' + pkg_dir + '"'
if (fd.is_dir(pkg_dir + '/include')) {
push(common_flags, '-I"' + pkg_dir + '/include"')
common_flags[] = '-I"' + pkg_dir + '/include"'
}
if (pkg != 'core') {
core_dir = shop.get_package_dir('core')
push(common_flags, '-I"' + core_dir + '/source"')
common_flags[] = '-I"' + core_dir + '/source"'
}
arrfor(cflags, function(flag) {
@@ -331,16 +331,16 @@ function compile_setup(pkg, file, target, opts) {
f = '-I"' + pkg_dir + '/' + ipath + '"'
}
}
push(common_flags, f)
common_flags[] = f
})
arrfor(target_cflags, function(flag) {
push(common_flags, flag)
common_flags[] = flag
})
var cmd_parts = [cc, '-c', '-fPIC']
cmd_parts = array(cmd_parts, common_flags)
push(cmd_parts, '"' + src_path + '"')
cmd_parts[] = '"' + src_path + '"'
return {
cmd_str: text(cmd_parts, ' '),
@@ -513,7 +513,7 @@ Build.build_package = function(pkg, target, exclude_main, buildtype) {
arrfor(c_files, function(file) {
var obj = Build.compile_file(pkg, file, _target, {buildtype: _buildtype, cflags: cached_cflags})
push(objects, obj)
objects[] = obj
})
return objects
@@ -527,16 +527,16 @@ Build.build_package = function(pkg, target, exclude_main, buildtype) {
// link_opts: {extra_objects, ldflags, target_ldflags, target, cc}
function compute_dylib_content(full_content, link_opts) {
var parts = [full_content]
push(parts, 'target:' + text(link_opts.target))
push(parts, 'cc:' + text(link_opts.cc))
parts[] = 'target:' + text(link_opts.target)
parts[] = 'cc:' + text(link_opts.cc)
arrfor(link_opts.extra_objects, function(obj) {
if (obj != null) push(parts, 'extra:' + text(obj))
if (obj != null) parts[] = 'extra:' + text(obj)
})
arrfor(link_opts.ldflags, function(flag) {
push(parts, 'ldflag:' + text(flag))
parts[] = 'ldflag:' + text(flag)
})
arrfor(link_opts.target_ldflags, function(flag) {
push(parts, 'target_ldflag:' + text(flag))
parts[] = 'target_ldflag:' + text(flag)
})
return text(parts, '\n')
}
@@ -570,7 +570,7 @@ Build.build_module_dylib = function(pkg, file, target, opts) {
f = '-L"' + setup.pkg_dir + '/' + lpath + '"'
}
}
push(resolved_ldflags, f)
resolved_ldflags[] = f
})
var build_dir = get_build_dir()
@@ -683,18 +683,18 @@ Build.build_module_dylib = function(pkg, file, target, opts) {
'-Wl,-rpath,' + local_dir
])
} else if (tc.system == 'windows') {
push(cmd_parts, '-Wl,--allow-shlib-undefined')
cmd_parts[] = '-Wl,--allow-shlib-undefined'
}
push(cmd_parts, '-L"' + local_dir + '"')
push(cmd_parts, '"' + text(obj) + '"')
cmd_parts[] = '-L"' + local_dir + '"'
cmd_parts[] = '"' + text(obj) + '"'
arrfor(_extra, function(extra_obj) {
if (extra_obj != null) push(cmd_parts, '"' + text(extra_obj) + '"')
if (extra_obj != null) cmd_parts[] = '"' + text(extra_obj) + '"'
})
cmd_parts = array(cmd_parts, resolved_ldflags)
cmd_parts = array(cmd_parts, target_ldflags)
push(cmd_parts, '-o')
push(cmd_parts, '"' + dylib_path + '"')
cmd_parts[] = '-o'
cmd_parts[] = '"' + dylib_path + '"'
cmd_str = text(cmd_parts, ' ')
if (_opts.verbose) log.build('[verbose] link: ' + cmd_str)
@@ -737,7 +737,7 @@ Build.compile_c_module = function(pkg, file, target, opts) {
if (pkg != 'core') {
arrfor(sources, function(src_file) {
var obj = Build.compile_file(pkg, src_file, _target, {buildtype: _buildtype, cflags: cached_cflags})
if (obj != null) push(support_objects, obj)
if (obj != null) support_objects[] = obj
})
}
@@ -767,7 +767,7 @@ Build.build_dynamic = function(pkg, target, buildtype, opts) {
if (pkg != 'core') {
arrfor(sources, function(src_file) {
var obj = Build.compile_file(pkg, src_file, _target, {buildtype: _buildtype, cflags: cached_cflags, verbose: _opts.verbose, force: _opts.force})
if (obj != null) push(support_objects, obj)
if (obj != null) support_objects[] = obj
})
}
@@ -775,7 +775,7 @@ Build.build_dynamic = function(pkg, target, buildtype, opts) {
var sym_name = shop.c_symbol_for_file(pkg, file)
var dylib = Build.build_module_dylib(pkg, file, _target, {buildtype: _buildtype, extra_objects: support_objects, cflags: cached_cflags, verbose: _opts.verbose, force: _opts.force})
if (dylib) {
push(results, {file: file, symbol: sym_name, dylib: dylib})
results[] = {file: file, symbol: sym_name, dylib: dylib}
} else {
failed = failed + 1
}
@@ -814,7 +814,7 @@ Build.build_static = function(packages, target, output, buildtype) {
var objects = Build.build_package(pkg, _target, !is_core, _buildtype)
arrfor(objects, function(obj) {
push(all_objects, obj)
all_objects[] = obj
})
// Collect LDFLAGS (with sigil replacement)
@@ -834,7 +834,7 @@ Build.build_static = function(packages, target, output, buildtype) {
f = '-L"' + pkg_dir + '/' + lpath + '"'
}
}
push(all_ldflags, f)
all_ldflags[] = f
})
}
})
@@ -856,18 +856,18 @@ Build.build_static = function(packages, target, output, buildtype) {
var cmd_parts = [cc]
arrfor(all_objects, function(obj) {
push(cmd_parts, '"' + obj + '"')
cmd_parts[] = '"' + obj + '"'
})
arrfor(all_ldflags, function(flag) {
push(cmd_parts, flag)
cmd_parts[] = flag
})
arrfor(target_ldflags, function(flag) {
push(cmd_parts, flag)
cmd_parts[] = flag
})
push(cmd_parts, '-o', '"' + out_path + '"')
cmd_parts[] = '-o', '"' + out_path + '"'
var cmd_str = text(cmd_parts, ' ')
@@ -921,7 +921,7 @@ function qbe_insert_dead_labels(il_text) {
line = lines[i]
trimmed = trim(line)
if (need_label && !starts_with(trimmed, '@') && !starts_with(trimmed, '}') && length(trimmed) > 0) {
push(result, "@_dead_" + text(dead_id))
result[] = "@_dead_" + text(dead_id)
dead_id = dead_id + 1
need_label = false
}
@@ -931,7 +931,7 @@ function qbe_insert_dead_labels(il_text) {
if (starts_with(trimmed, 'ret ') || starts_with(trimmed, 'jmp ')) {
need_label = true
}
push(result, line)
result[] = line
i = i + 1
}
return text(result, "\n")
@@ -1122,16 +1122,16 @@ Build.compile_cm_to_mach = function(src_path) {
// output: path to write the generated .c file
Build.generate_module_table = function(modules, output) {
var lines = []
push(lines, '/* Generated module table — do not edit */')
push(lines, '#include <stddef.h>')
push(lines, '#include <string.h>')
push(lines, '')
push(lines, 'struct cell_embedded_entry {')
push(lines, ' const char *name;')
push(lines, ' const unsigned char *data;')
push(lines, ' size_t size;')
push(lines, '};')
push(lines, '')
lines[] = '/* Generated module table — do not edit */'
lines[] = '#include <stddef.h>'
lines[] = '#include <string.h>'
lines[] = ''
lines[] = 'struct cell_embedded_entry {'
lines[] = ' const char *name;'
lines[] = ' const unsigned char *data;'
lines[] = ' size_t size;'
lines[] = '};'
lines[] = ''
var entries = []
arrfor(modules, function(mod) {
@@ -1140,27 +1140,27 @@ Build.generate_module_table = function(modules, output) {
var bytes = array(mach)
var hex = []
arrfor(bytes, function(b) {
push(hex, '0x' + text(b, 'h2'))
hex[] = '0x' + text(b, 'h2')
})
push(lines, 'static const unsigned char mod_' + safe + '_data[] = {')
push(lines, ' ' + text(hex, ', '))
push(lines, '};')
push(lines, '')
push(entries, safe)
lines[] = 'static const unsigned char mod_' + safe + '_data[] = {'
lines[] = ' ' + text(hex, ', ')
lines[] = '};'
lines[] = ''
entries[] = safe
log.console('Embedded: ' + mod.name + ' (' + text(length(bytes)) + ' bytes)')
})
// Lookup function
push(lines, 'const struct cell_embedded_entry *cell_embedded_module_lookup(const char *name) {')
lines[] = 'const struct cell_embedded_entry *cell_embedded_module_lookup(const char *name) {'
arrfor(modules, function(mod, i) {
var safe = entries[i]
push(lines, ' if (strcmp(name, "' + mod.name + '") == 0) {')
push(lines, ' static const struct cell_embedded_entry e = {"' + mod.name + '", mod_' + safe + '_data, sizeof(mod_' + safe + '_data)};')
push(lines, ' return &e;')
push(lines, ' }')
lines[] = ' if (strcmp(name, "' + mod.name + '") == 0) {'
lines[] = ' static const struct cell_embedded_entry e = {"' + mod.name + '", mod_' + safe + '_data, sizeof(mod_' + safe + '_data)};'
lines[] = ' return &e;'
lines[] = ' }'
})
push(lines, ' return (void *)0;')
push(lines, '}')
lines[] = ' return (void *)0;'
lines[] = '}'
var c_text = text(lines, '\n')
fd.slurpwrite(output, stone(blob(c_text)))
@@ -1188,14 +1188,14 @@ Build.build_all_dynamic = function(target, buildtype, opts) {
// Build core first
if (find(packages, function(p) { return p == 'core' }) != null) {
core_mods = Build.build_dynamic('core', _target, _buildtype, _opts)
push(results, {package: 'core', modules: core_mods})
results[] = {package: 'core', modules: core_mods}
}
// Build other packages
arrfor(packages, function(pkg) {
if (pkg == 'core') return
var pkg_mods = Build.build_dynamic(pkg, _target, _buildtype, _opts)
push(results, {package: pkg, modules: pkg_mods})
results[] = {package: pkg, modules: pkg_mods}
})
// Print build report