Files
catscript/Makefile
T
Minus 48b1b84ea6 type checker, phase 1: hints are checked where concrete
First slice of the static-typing foundation (traits/generics/Sized()
will build on it).  Typing stays structural and permissive: an unknown
or opaque name is never a rejection, so existing programs keep working.

- new module cat/types/type.{h,c}: compile-time-only descriptors
  (int/float/bool/text/empty/object/function/list/memory/any + interned
  named/opaque types), with equal/assignable/join and int->float widening.
- compiler: skip_type_hint -> parse_type_hint, which returns the type of
  the first identifier in a hint (the rest of a balanced hint is still
  consumed and ignored, so `cbyte[sentinel_sized<0>]` parses).
- `local NAME : T = <literal>` is checked: assigning a known concrete
  literal of the wrong kind to a known concrete type raises at compile
  time ("line N: cannot assign text to int").  Unknown/opaque names and
  non-literal expressions stay permissive.
- FuncCtx tracks a declared/inferred type per local slot.
- tests/types.cat + suite block: ok hints, int->float widening, opaque
  names accepted, and a wrong assignment rejected.  Suite 136 -> 140.
2026-11-18 16:56:40 +00:00

85 lines
2.2 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
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/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))
.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)
$(BIN): $(OBJS)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
$(BUILD)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
test: $(BIN)
@sh tests/run_tests.sh
clean:
rm -rf build/catscript