Files
catscript/Makefile
T
Minus 77ea433215 native x86-64 backend (pluggable, per-opcode lowering)
A second backend that lowers each bytecode instruction to a machine-code
call into a runtime helper, with control flow as real branches.

- cat/backend/x86_64_glue.c: one helper per opcode, mirroring cat/vm.c
  exactly (frame lifecycle, arith, cmp, attr/idx, call/callmethod, is,
  next/fornext, try/raise).  Helpers use the SysV convention (f in rdi,
  a/b/c in rsi/rdx/rcx) and return 0/1/-1.
- cat/backend/x86_64.c: emits AT&T assembly (one labelled block per
  instruction, one call per helper, real jumps for JUMP/JUMPIF/JUMPIFNOT/
  FORNEXT/RETURN, an .Lonerror block that resumes try handlers), plus a
  small generated _main.c that rebuilds the bytecode and boots the VM.
  Builds with as + cc linked against libcatscript.a.
- generators are not lowered: their prototype carries no nat_entry, so
  the VM runs them (their bytecode is rebuilt by the generated main), and
  the emitted code simply falls back to the interpreter.
- cat_vm_exec_closure dispatches to a prototype's nat_entry when present.
- tests: native-vs-interpreter equivalence check.  Suite 155 -> 156.

Verified: hello, control, classes, generators, arith, errors, text, oop,
slots, reflect, toml, files, ffi all match the interpreter natively.
2026-11-18 20:19:54 +00:00

99 lines
2.6 KiB
Makefile

# Makefile -- catscript
#
# Naming rule: every function/type name in the sources encodes its path
# from the project root with '/' -> '_'. A function in a/b/c.h is named
# a_b_c_funcao(); a type there is A_B_C_MeuTipo. (Headers keep the
# `include/` root and sources the `src/` root out of the name, so
# include/cat/types/int.h and src/cat/types/int.c are both module
# `cat_types_int`.)
#
# Targets (run `make help` for the list):
# help show this list (default goal)
# all build the catscript binary
# test build and run the automated test suite
# clean remove build artifacts
CC ?= cc
CFLAGS ?= -std=c11 -Wall -Wextra -O2 -Wno-unused-parameter -D_DEFAULT_SOURCE
CPPFLAGS += -Iinclude
LDFLAGS ?=
LDLIBS ?= -lm -lffi -ldl
BUILD := build/catscript
BIN := $(BUILD)/catscript
LIB := $(BUILD)/libcatscript.a
SRCS := \
src/main.c \
src/cat/error.c \
src/cat/value.c \
src/cat/bytecode.c \
src/cat/lexer.c \
src/cat/compiler.c \
src/cat/vm.c \
src/cat/module.c \
src/cat/backend/c.c \
src/cat/backend/x86_64.c \
src/cat/backend/x86_64_glue.c \
src/cat/backend/registry.c \
src/cat/types/empty.c \
src/cat/types/type.c \
src/cat/types/bool.c \
src/cat/types/number.c \
src/cat/types/int.c \
src/cat/types/float.c \
src/cat/types/byte.c \
src/cat/types/char.c \
src/cat/types/ascii_text.c \
src/cat/types/utf8_text.c \
src/cat/types/text.c \
src/cat/types/table.c \
src/cat/types/function.c \
src/cat/types/native.c \
src/cat/types/file.c \
src/cat/types/generator.c \
src/cat/types/selector.c \
src/cat/types/list.c \
src/cat/types/memory.c \
src/cat/types/ffi.c \
src/cat/stdlib/stdlib.c \
src/cat/stdlib/toml.c \
src/cat/stdlib/build.c
OBJS := $(patsubst src/%.c,$(BUILD)/%.o,$(SRCS))
# The runtime archive is every object EXCEPT the CLI entry point, so an
# ahead-of-time compiled program can link the runtime without clashing
# on `main`.
LIBOBJS := $(filter-out $(BUILD)/main.o,$(OBJS))
.PHONY: help all test clean examples
# Default goal: print the help.
help:
@echo "catscript build targets:"
@echo " make all - build the catscript binary ($(BIN))"
@echo " make test - build and run the automated test suite"
@echo " make clean - remove build artifacts"
@echo " make help - show this help (default goal)"
all: $(BIN) $(LIB)
$(BIN): $(OBJS)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
$(LIB): $(LIBOBJS)
@mkdir -p $(dir $@)
$(AR) rcs $@ $(LIBOBJS)
$(BUILD)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
test: $(BIN)
@sh tests/run_tests.sh
clean:
rm -rf build/catscript