Global generation

This commit is contained in:
2026-01-18 03:11:17 -08:00
parent 94d5749d31
commit c0b18cda5a
16 changed files with 571 additions and 57 deletions

86
src/gen-init-globals.awk Normal file
View File

@@ -0,0 +1,86 @@
# This script is designed to be run from the root of the project
BEGIN {
# Special symbols registered manually
special_syms["t"] = 1
special_syms["nil"] = 1
special_syms["unbound"] = 1
special_syms["hash_string"] = 1
special_syms["strings_equal"] = 1
FS = "[,(]"
print "// This file was automatically generated by src/gen-init-globals.awk"
print "// DO NOT MODIFY THIS FILE MANUALLY!"
print ""
print "#include \"init_globals.h\""
print ""
for (i = 1; i < ARGC; i += 1) {
name = ARGV[i]
sub(/\.c$/, ".h", name)
sub(/^(.+\/)?src\//, "", name)
print "#include \"" name "\""
}
print ""
print "void register_globals() {"
first_header = 1
}
function maybe_print_file_header() {
if (!seen_files[FILENAME]) {
if (!first_header) {
print ""
}
first_header = 0
seen_files[FILENAME] = 1
name = FILENAME
sub(/^(.+\/)?src\//, "", name)
print " // " name
}
}
function get_next_symbol() {
out = ""
if (!$2) {
while (1) {
old_rs = RS
RS = FS
getline line
RS = old_rs
if (line ~ /\s/) {
out = line
break
}
}
} else {
out = $2
}
if (out && !special_syms[out]) {
gsub(/\s/, "", out)
return out
} else {
return ""
}
}
function maybe_emit_next_symbol(entity) {
name = get_next_symbol()
if (name) {
print " REGISTER_GLOBAL_" entity "(" get_next_symbol() ");";
}
}
/DEFUN\(/ {
maybe_print_file_header()
maybe_emit_next_symbol("FUNCTION")
}
/DEFINE_SYMBOL\(/ {
maybe_print_file_header()
maybe_emit_next_symbol("SYMBOL")
}
END {
print "}"
}