-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
44 lines (37 loc) · 2.06 KB
/
Copy pathMakefile
File metadata and controls
44 lines (37 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Makefile for building the Lisp interpreter to WebAssembly or native
WASM_CC ?= emcc
WASM_CFLAGS ?= -O2 -Iinclude -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=5242880 -s EXPORTED_FUNCTIONS='["_eval", "_gc_get_collections_count", "_gc_get_allocated_bytes", "_gc_get_freed_bytes", "_gc_get_current_bytes", "_gc_heap_snapshot", "_gc_heap_snapshot_flat", "_gc_get_stats_flat", "_gc_heap_snapshot_entry_size", "_gc_heap_snapshot_addr_offset", "_gc_heap_snapshot_size_offset", "_gc_heap_snapshot_generation_offset", "_gc_heap_snapshot_tag_offset", "_gc_set_backend_env", "_form_needs_more_input", "_malloc", "_free"]' -s EXPORTED_RUNTIME_METHODS='["cwrap"]'
NATIVE_CC ?= gcc
UNAME_S := $(shell uname -s)
NATIVE_CFLAGS ?= -Iinclude -lm
ifeq ($(UNAME_S),Darwin)
NATIVE_CFLAGS += -Wl,-stack_size,0x4000000
endif
SRC = src/interpreter.c src/gc/gc_runtime.c src/gc/mark_sweep.c src/gc/copying.c src/gc/generational.c
WASM_DIR = web
EM_CACHE ?= $(abspath .emscripten-cache)
WASM_TARGET = $(WASM_DIR)/interpreter.js
WASM_WASM = $(WASM_DIR)/interpreter.wasm
NATIVE_TARGET = interpreter
.PHONY: all native test-native clean
all: $(WASM_TARGET)
$(WASM_TARGET): $(SRC) standard-lib.lisp
mkdir -p $(WASM_DIR) $(EM_CACHE)
EM_CACHE=$(EM_CACHE) $(WASM_CC) $(WASM_CFLAGS) --embed-file standard-lib.lisp -o $@ $(SRC)
native: $(NATIVE_TARGET)
$(NATIVE_TARGET): $(SRC)
$(NATIVE_CC) -o $@ $^ $(NATIVE_CFLAGS)
test-native: native
./$(NATIVE_TARGET) "(+ 1 (* 2 3))" >/dev/null
printf '(+ 1 2)\n' | ./$(NATIVE_TARGET) >/dev/null
./$(NATIVE_TARGET) "(car (list 1 2 3))" >/dev/null
./$(NATIVE_TARGET) "(cdr (list 1 2 3))" >/dev/null
./$(NATIVE_TARGET) "'(1 2 (3 4))" >/dev/null
./$(NATIVE_TARGET) "(begin (define (double x) (+ x x)) (double 8))" >/dev/null
./$(NATIVE_TARGET) -f hanoi.lisp >/dev/null
./$(NATIVE_TARGET) "(gc)" >/dev/null
./$(NATIVE_TARGET) "(gc-threshold 2048)" >/dev/null
./$(NATIVE_TARGET) "(begin (define foo nil) (define foo (list 1 2 3)) foo)" >/dev/null
printf '(define (foo x)\n (+ x 1))\n(foo 4)\n' | ./$(NATIVE_TARGET) >/dev/null
clean:
rm -f $(WASM_TARGET) $(WASM_WASM) $(NATIVE_TARGET)