Commit c3fbdcd9
c3fbdcd95446Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 11 files · ~1 modified · -10 deleted
Description
chore: v2 is now master, remove C version files
Branch reorganization: master ← spinel-v2 (self-hosting Ruby AOT compiler) c-version ← old master (C implementation, 18K lines) ruby-v1 ← ruby-rewrite (first Ruby implementation)
Removed: src/, vendor/, Makefile (C build system), PLAN.md
Spinel is now a self-hosting Ruby compiler: 14,074 lines of Ruby that compiles itself to native code. 58/59 tests, 39/39 benchmarks, bootstrap loop closed.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- c3fbdcd95446
- Parent
- 275b16152569
Makefiledeleted
1-
# Spinel AOT Compiler - Makefile2-
#3-
# Usage:4-
# make deps # Fetch and build dependencies (prism)5-
# make # Build the spinel compiler6-
# make test # Quick test (mandelbrot)7-
# make test-all # Run all 47 examples8-
9-
# Configuration10-
PRISM_VERSION ?= 1.4.011-
CC ?= cc12-
CFLAGS = -Wall -Wextra -O2 -std=c9913-
CFLAGS += -Ivendor/prism/include -Isrc14-
15-
# Prism library16-
PRISM_DIR = vendor/prism17-
PRISM_LIB = $(PRISM_DIR)/build/libprism.a18-
PRISM_CFLAGS = -I$(PRISM_DIR)/include19-
20-
# Sources21-
SRCS = src/main.c src/codegen.c src/type.c src/expr.c src/stmt.c src/emit.c src/methods.c22-
OBJS = $(SRCS:.c=.o)23-
24-
# Default target25-
all: spinel26-
27-
spinel: $(OBJS) $(PRISM_LIB)28-
$(CC) $(OBJS) $(PRISM_LIB) -o $@29-
30-
src/%.o: src/%.c src/codegen.h $(PRISM_LIB)31-
$(CC) $(CFLAGS) $(PRISM_CFLAGS) -c $< -o $@32-
33-
# Dependencies34-
deps: $(PRISM_LIB)35-
36-
$(PRISM_LIB):37-
@if [ ! -d "$(PRISM_DIR)" ]; then \38-
echo "Fetching prism v$(PRISM_VERSION)..."; \39-
mkdir -p lib; \40-
git clone --depth 1 --branch v$(PRISM_VERSION) \41-
https://github.com/ruby/prism $(PRISM_DIR); \42-
fi43-
@echo "Building prism..."44-
cd $(PRISM_DIR) && make45-
46-
# Quick test: mandelbrot only47-
test: spinel48-
@./spinel --source=benchmark/bm_so_mandelbrot.rb --output=/tmp/sp_mandelbrot.c 2>/dev/null49-
@$(CC) -O2 /tmp/sp_mandelbrot.c -lm -o /tmp/sp_mandelbrot 2>/dev/null50-
@/tmp/sp_mandelbrot > /tmp/sp_m1.pbm51-
@ruby benchmark/bm_so_mandelbrot.rb > /tmp/sp_m2.pbm52-
@diff /tmp/sp_m1.pbm /tmp/sp_m2.pbm > /dev/null && echo "test: OK (mandelbrot)" || echo "test: FAIL"53-
54-
# Full test suite: all single-file examples55-
EXAMPLES_SIMPLE = $(filter-out test/bm_regexp.rb test/bm_ao_render.rb test/bm_mandel_term.rb, $(wildcard test/bm_*.rb))56-
57-
test-all: spinel58-
@pass=0; fail=0; skip=0; total=0; \59-
echo "=== Spinel Test Suite ==="; \60-
echo ""; \61-
for f in $(EXAMPLES_SIMPLE); do \62-
name=$$(basename $$f .rb); \63-
total=$$((total + 1)); \64-
if ./spinel --source=$$f --output=/tmp/sp_$${name}.c 2>/dev/null && \65-
$(CC) -O2 -Wno-format -Wno-discarded-qualifiers -Wno-unused-value \66-
/tmp/sp_$${name}.c -lm -o /tmp/sp_$${name} 2>/dev/null; then \67-
if timeout 10 /tmp/sp_$${name} > /tmp/sp_$${name}_out 2>/dev/null; \68-
ruby $$f > /tmp/sp_$${name}_ref 2>/dev/null; \69-
diff /tmp/sp_$${name}_out /tmp/sp_$${name}_ref > /dev/null 2>&1; then \70-
echo " OK $$name"; \71-
pass=$$((pass + 1)); \72-
else \73-
echo " FAIL $$name (output differs)"; \74-
fail=$$((fail + 1)); \75-
fi; \76-
else \77-
echo " FAIL $$name (compile error)"; \78-
fail=$$((fail + 1)); \79-
fi; \80-
done; \81-
echo ""; \82-
echo "--- Special tests ---"; \83-
total=$$((total + 1)); \84-
if ./spinel --source=benchmark/bm_so_mandelbrot.rb --output=/tmp/sp_mandelbrot.c 2>/dev/null && \85-
$(CC) -O2 /tmp/sp_mandelbrot.c -lm -o /tmp/sp_mandelbrot 2>/dev/null && \86-
/tmp/sp_mandelbrot > /tmp/sp_m1.pbm && ruby benchmark/bm_so_mandelbrot.rb > /tmp/sp_m2.pbm && \87-
diff /tmp/sp_m1.pbm /tmp/sp_m2.pbm > /dev/null 2>&1; then \88-
echo " OK bm_so_mandelbrot (binary output)"; \89-
pass=$$((pass + 1)); \90-
else \91-
echo " FAIL bm_so_mandelbrot"; \92-
fail=$$((fail + 1)); \93-
fi; \94-
total=$$((total + 1)); \95-
if ./spinel --source=test/bm_regexp.rb --output=/tmp/sp_regexp.c 2>/dev/null && \96-
$(CC) -O2 /tmp/sp_regexp.c /usr/lib/x86_64-linux-gnu/libonig.so.5 -lm -o /tmp/sp_regexp 2>/dev/null && \97-
/tmp/sp_regexp > /tmp/sp_regexp_out 2>/dev/null && \98-
ruby test/bm_regexp.rb > /tmp/sp_regexp_ref 2>/dev/null && \99-
diff /tmp/sp_regexp_out /tmp/sp_regexp_ref > /dev/null 2>&1; then \100-
echo " OK bm_regexp (oniguruma)"; \101-
pass=$$((pass + 1)); \102-
else \103-
echo " SKIP bm_regexp (requires libonig)"; \104-
skip=$$((skip + 1)); \105-
fi; \106-
total=$$((total + 1)); \107-
if ./spinel --source=test/bm_require/main.rb --output=/tmp/sp_require.c 2>/dev/null && \108-
$(CC) -O2 /tmp/sp_require.c -lm -o /tmp/sp_require 2>/dev/null && \109-
/tmp/sp_require > /tmp/sp_require_out 2>/dev/null && \110-
ruby test/bm_require/main.rb > /tmp/sp_require_ref 2>/dev/null && \111-
diff /tmp/sp_require_out /tmp/sp_require_ref > /dev/null 2>&1; then \112-
echo " OK bm_require (multi-file)"; \113-
pass=$$((pass + 1)); \114-
else \115-
echo " FAIL bm_require"; \116-
fail=$$((fail + 1)); \117-
fi; \118-
echo ""; \119-
echo "=== $$pass passed, $$fail failed, $$skip skipped / $$total total ==="120-
121-
# Verify benchmarks compile and run correctly122-
bench-verify: spinel123-
@pass=0; fail=0; total=0; \124-
echo "=== Benchmark Verification ==="; \125-
for f in benchmark/*.rb; do \126-
name=$$(basename $$f .rb); \127-
total=$$((total + 1)); \128-
if ./spinel --source=$$f --output=/tmp/sp_$${name}.c 2>/dev/null && \129-
$(CC) -O2 -Wno-format -Wno-discarded-qualifiers -Wno-unused-value \130-
/tmp/sp_$${name}.c -lm -o /tmp/sp_$${name} 2>/dev/null; then \131-
if timeout 30 /tmp/sp_$${name} > /tmp/sp_$${name}_out 2>/dev/null; \132-
ruby $$f > /tmp/sp_$${name}_ref 2>/dev/null; \133-
diff /tmp/sp_$${name}_out /tmp/sp_$${name}_ref > /dev/null 2>&1; then \134-
echo " OK $$name"; \135-
pass=$$((pass + 1)); \136-
else \137-
echo " FAIL $$name (output differs)"; \138-
fail=$$((fail + 1)); \139-
fi; \140-
else \141-
echo " FAIL $$name (compile error)"; \142-
fail=$$((fail + 1)); \143-
fi; \144-
done; \145-
echo ""; \146-
echo "=== $$pass passed, $$fail failed / $$total total ==="147-
148-
# Generate C code only149-
gen: spinel150-
./spinel --source=benchmark/bm_so_mandelbrot.rb --output=mandelbrot_aot.c151-
@echo "Generated mandelbrot_aot.c"152-
153-
clean:154-
rm -f $(OBJS) spinel155-
rm -f mandelbrot_aot.c mandelbrot156-
rm -f mandelbrot_aot.pbm mandelbrot_ruby.pbm157-
158-
distclean: clean159-
rm -rf vendor/prism160-
161-
.PHONY: all deps test test-all gen clean distcleanPLAN.mddeleted
Loading diff…
README.mdmodifiedView file
Loading diff…
src/codegen.cdeleted
Loading diff…
src/codegen.hdeleted
Loading diff…
src/emit.cdeleted
Loading diff…
src/expr.cdeleted
Loading diff…
src/main.cdeleted
Loading diff…
src/methods.cdeleted
Loading diff…
src/stmt.cdeleted
Loading diff…
src/type.cdeleted
Loading diff…