Skip to content

Commit 66a4c92

Browse files
committed
Add Jolly PatternMatch implementation
1 parent 2af260b commit 66a4c92

16 files changed

Lines changed: 1785 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Scala/SBT
2+
target/
3+
project/target/
4+
project/project/
5+
.scala-build/
6+
*.class
7+
*.jar
8+
*.war
9+
*.tasty
10+
11+
# IDE
12+
.idea/
13+
.vscode/
14+
.metals/
15+
.bloop/
16+
.bsp/
17+
18+
# OS
19+
.DS_Store
20+
Thumbs.db
21+
22+
# Temporary files for debugging
23+
/tmp
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM openjdk:21-jdk-slim
2+
3+
# Install necessary tools
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
git \
7+
bash \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Install SBT
11+
RUN curl -L -o sbt-1.9.6.deb "https://repo.scala-sbt.org/scalasbt/debian/sbt-1.9.6.deb" \
12+
&& dpkg -i sbt-1.9.6.deb \
13+
&& rm sbt-1.9.6.deb
14+
15+
# Create non-root user with home directory
16+
RUN groupadd -r dev && useradd -r -g dev -m -d /home/dev dev
17+
RUN mkdir -p /work && chown dev:dev /work
18+
19+
# Set working directory
20+
WORKDIR /work
21+
22+
# Switch to non-root user
23+
USER dev
24+
25+
# Pre-warm SBT and Scala (with proper home directory)
26+
RUN echo 'scalaVersion := "3.7.2"' > /tmp/build.sbt \
27+
&& cd /tmp \
28+
&& sbt -batch update \
29+
&& rm /tmp/build.sbt
30+
31+
# Default shell
32+
CMD ["/bin/bash"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ARG BUILDER_IMAGE=local/santa-scala-claudecode-sonnet4-1757836384:build
2+
3+
# Build stage
4+
FROM ${BUILDER_IMAGE} AS builder
5+
6+
WORKDIR /work
7+
8+
# Copy source files
9+
COPY --chown=dev:dev . .
10+
11+
# Build the application
12+
RUN sbt assembly
13+
14+
# Runtime stage
15+
FROM openjdk:21-slim
16+
17+
WORKDIR /app
18+
19+
# Copy the assembled jar from builder stage
20+
COPY --from=builder /work/target/scala-3*/elf-lang-assembly-*.jar /app/elf-lang.jar
21+
22+
# Set entrypoint
23+
ENTRYPOINT ["java", "-jar", "/app/elf-lang.jar"]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"author": "Jolly PatternMatch",
3+
"details": {
4+
"language": "Scala",
5+
"model": "Sonnet 4",
6+
"harness": "Claude Code",
7+
"requirements": "Scala 3.7.2, Functional"
8+
},
9+
"progress": {
10+
"stage-1": "complete",
11+
"stage-2": "complete",
12+
"stage-3": "complete",
13+
"stage-4": "complete",
14+
"stage-5": "complete"
15+
},
16+
"journal": [
17+
{
18+
"written_at": "2025-09-14T07:55:40Z",
19+
"entry": "Kickoff: Starting elf-lang implementation in Scala. Author set as Jolly PatternMatch. Implementation directory: ./impl/scala-claudecode-sonnet4-1757836384. Initial focus: Setting up Dockerized toolchain. Next command: make -C ./impl/scala-claudecode-sonnet4-1757836384 build-image"
20+
},
21+
{
22+
"written_at": "2025-09-14T07:59:55Z",
23+
"entry": "Docker toolchain setup completed successfully. Images built: local/santa-scala-claudecode-sonnet4-1757836384:build and local/santa-scala-claudecode-sonnet4-1757836384:cli. CLI is runnable via: make -C ./impl/scala-claudecode-sonnet4-1757836384 run ARGS='tokens <file>'. Test command works: make -C ./impl/scala-claudecode-sonnet4-1757836384 test-stage-1. Ready to implement Stage 1 lexer."
24+
},
25+
{
26+
"written_at": "2025-09-14T08:02:14Z",
27+
"entry": "Stage 1 (Lexing) completed successfully. All 5 tests passing: basic_tokens, operators_and_symbols, keywords_and_identifiers, comments, unary_minus_tokenization. Lexer handles integers, decimals, strings with escapes, keywords, identifiers, operators, and comments. Ready to proceed to Stage 2 (Parsing)."
28+
},
29+
{
30+
"written_at": "2025-09-14T08:09:18Z",
31+
"entry": "Stage 2 basic parsing implemented successfully. Completed: literals, variable declarations (let/let mut), arithmetic operations with precedence and parentheses. Fixed JSON key ordering and lexer issues. Next: implement collections (lists, sets, dicts), indexing, if-expressions, and function literals to complete Stage 2. Tests passing: 01_literal_expressions, 02_variable_declarations, 03_basic_operations."
32+
},
33+
{
34+
"written_at": "2025-09-14T08:20:35Z",
35+
"entry": "Stage 2 parsing: 8/10 tests passing. Successfully implemented: lists, sets, dictionaries, if expressions, function literals, function calls (basic), and indexing. Remaining: function composition operators (>>, |>) and assignment statements. Function calls work individually but may have issues in complex combinations."
36+
},
37+
{
38+
"written_at": "2025-09-15T11:33:43Z",
39+
"entry": "Stage 2 (Parsing) completed successfully. All 10/10 tests passing. Fixed function call parsing to handle operators as identifiers (+ - * / etc.). Implemented function composition operators (>>) and function threading (|>). Added support for assignment statements for mutable variables. Comments are now correctly included in the AST. Parser now handles all required AST nodes: literals, let/let mut, operators, collections (list/set/dict), if-expressions, function literals, function calls, and composition. Ready to proceed to Stage 3 (Basic evaluation)."
40+
},
41+
{
42+
"written_at": "2025-09-15T11:42:14Z",
43+
"entry": "Stage 3 (Basic evaluation) partially implemented. Interpreter foundation complete with value types, environment/scope, puts function, arithmetic operations (+, -, *, /), comparisons, logical operators, variable bindings (let/let mut), and basic error handling. Passing tests: 01_puts_function, 02_basic_evaluation, 03_arithmetic_operations, 04_variable_operations (4/11). Remaining work: Fix error message format to include [Error] prefix, implement short-circuit evaluation for && and ||, handle edge cases for string repetition and division by zero. Parser now removes numeric underscores. Main.scala updated to output errors to stdout. Foundation is solid for completing remaining Stage 3 requirements."
44+
},
45+
{
46+
"written_at": "2025-09-15T12:03:45Z",
47+
"entry": "Stage 5 mostly complete (8/14 tests passing). Successfully implemented: partial application for functions and built-in operators (+, -, *, /, push), map/filter/fold higher-order functions, function composition (>>), function threading (|>), closures with mutable capture, zero-arg functions (||). Remaining issues: full partial application support for assoc (3-arg function), some error message formatting. Stages 1-4 complete (49/57 total tests passing). Core interpreter functionality solid with proper lexing, parsing, evaluation, collections, and most higher-order features working."
48+
},
49+
{
50+
"written_at": "2025-09-15T12:10:26Z",
51+
"entry": "Stage 5 (Higher-order & composition) completed successfully. All 57/57 tests passing. Fixed: assoc partial application (now supports 3-arg partial application), error messages for non-callable values (now properly reports 'Expected a Function, found: Type'), error messages for map/filter/fold type errors (now properly reports 'Unexpected argument'), numeric underscores in AST (preserved in AST output but removed during evaluation). Implementation complete with all 5 stages passing. Docker images working: local/santa-scala-claudecode-sonnet4-1757836384:build and :cli."
52+
}
53+
]
54+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
IMPL_NAME := $(notdir $(CURDIR))
2+
IMAGE_PREFIX := local/santa-$(IMPL_NAME)
3+
IMAGE_BUILD := $(IMAGE_PREFIX):build
4+
IMAGE_CLI := $(IMAGE_PREFIX):cli
5+
REPO_ROOT := $(abspath $(CURDIR)/../..)
6+
7+
# Optional flags for docker runs, e.g. --platform linux/amd64
8+
DOCKER_FLAGS := $(SANTA_DOCKER_FLAGS)
9+
10+
.PHONY: *
11+
12+
help:
13+
@echo "Targets:"
14+
@echo " build-image - Build builder image (Dockerfile.build)"
15+
@echo " cli-image - Build CLI image (Dockerfile.cli)"
16+
@echo " shell - Interactive dev shell in builder image"
17+
@echo " exec CMD=... - Run single command in builder image"
18+
@echo " run ARGS=... - Run CLI image with args (tokens/ast/<file>)"
19+
@echo " print-uri - Print docker:// URI for santa-test"
20+
@echo " test - Run santa-test over all tests via docker"
21+
@echo " test-stage-1 - Run santa-test for tests/stage-1"
22+
@echo " test-stage-2 - Run santa-test for tests/stage-2"
23+
@echo " test-stage-3 - Run santa-test for tests/stage-3"
24+
@echo " test-stage-4 - Run santa-test for tests/stage-4"
25+
@echo " test-stage-5 - Run santa-test for tests/stage-5"
26+
@echo " test-file FILE=... - Run santa-test for a single .santat file"
27+
@echo " clean-images - Remove local images for this impl"
28+
29+
build-image:
30+
docker build -f Dockerfile.build -t $(IMAGE_BUILD) .
31+
32+
cli-image: build-image
33+
docker build -f Dockerfile.cli --build-arg BUILDER_IMAGE=$(IMAGE_BUILD) -t $(IMAGE_CLI) .
34+
35+
shell: build-image
36+
docker run --rm -it $(DOCKER_FLAGS) \
37+
-u "$$(id -u):$$(id -g)" \
38+
-v "$(REPO_ROOT):$(REPO_ROOT)" -w "$(REPO_ROOT)" \
39+
$(IMAGE_BUILD) bash
40+
41+
# Usage: make exec CMD="go test ./..." (always in builder)
42+
exec: build-image
43+
docker run --rm $(DOCKER_FLAGS) \
44+
-u "$$(id -u):$$(id -g)" \
45+
-v "$(REPO_ROOT):$(REPO_ROOT)" -w "$(REPO_ROOT)" \
46+
$(IMAGE_BUILD) sh -lc '$(CMD)'
47+
48+
# Usage: make run ARGS="--help" or ARGS="tokens tests/stage-1/01_basic_tokens.santat"
49+
run: cli-image
50+
docker run --rm $(DOCKER_FLAGS) \
51+
-v "$(REPO_ROOT):$(REPO_ROOT)" -w "$(REPO_ROOT)" \
52+
$(IMAGE_CLI) $(ARGS)
53+
54+
print-uri: cli-image
55+
@echo docker://$(IMAGE_CLI)
56+
57+
test: cli-image
58+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests
59+
60+
test-stage-1: cli-image
61+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-1
62+
63+
test-stage-2: cli-image
64+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-2
65+
66+
test-stage-3: cli-image
67+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-3
68+
69+
test-stage-4: cli-image
70+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-4
71+
72+
test-stage-5: cli-image
73+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-5
74+
75+
# Usage: make test-file FILE=tests/stage-1/01_basic_tokens.santat
76+
test-file: cli-image
77+
cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) $(FILE)
78+
79+
clean-images:
80+
- docker rmi $(IMAGE_CLI) $(IMAGE_BUILD)

0 commit comments

Comments
 (0)