Files
glisp/src/gen-init-globals.awk

96 lines
2.0 KiB
Awk

# 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
special_syms["and_rest"] = 1
special_syms["and_key"] = 1
special_syms["and_optional"] = 1
special_syms["and_allow_other_keys"] = 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")
}
/DEFSPECIAL\(/ {
maybe_print_file_header()
maybe_emit_next_symbol("SPECIAL")
}
/DEFINE_SYMBOL\(/ {
maybe_print_file_header()
maybe_emit_next_symbol("SYMBOL")
}
END {
print "}"
}