Skip to content

Commit fdbd136

Browse files
committed
Add Ruby Rednose implementation
1 parent c925973 commit fdbd136

12 files changed

Lines changed: 2551 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Ruby specific
2+
*.gem
3+
*.rbc
4+
/.config
5+
/coverage/
6+
/InstalledFiles
7+
/pkg/
8+
/spec/reports/
9+
/spec/examples.txt
10+
/test/tmp/
11+
/test/version_tmp/
12+
/tmp/
13+
14+
# Implementation specific temp directory
15+
/tmp
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ruby:3.4
2+
3+
# Create non-root user
4+
RUN useradd -m -s /bin/bash dev
5+
6+
# Set work directory
7+
WORKDIR /work
8+
9+
# Switch to dev user
10+
USER dev
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG BUILDER_IMAGE=local/santa-ruby-claudecode-sonnet4-1757425857:build
2+
3+
FROM $BUILDER_IMAGE
4+
5+
# Copy source files
6+
COPY --chown=dev:dev . /work/
7+
8+
# Make CLI executable
9+
USER root
10+
RUN chmod +x /work/cli
11+
USER dev
12+
13+
# Set entrypoint to CLI
14+
ENTRYPOINT ["/work/cli"]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"author": "Ruby Rednose",
3+
"details": {
4+
"language": "Ruby",
5+
"model": "Sonnet 4",
6+
"harness": "Claude Code",
7+
"requirements": "Use Ruby 3.4, without any external packages or dependencies."
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-09T13:52:41Z",
19+
"entry": "Starting elf-lang Ruby implementation as author 'Ruby Rednose'. Initial focus: set up Dockerized toolchain and begin Stage 1 lexing. Resume command: make -C ./impl/ruby-claudecode-sonnet4-1757425857 cli-image"
20+
},
21+
{
22+
"written_at": "2025-09-09T13:54:20Z",
23+
"entry": "Developer tooling setup complete. Built local/santa-ruby-claudecode-sonnet4-1757425857:build and :cli images successfully. Commands used: make build-image, make cli-image. CLI is ready for testing."
24+
},
25+
{
26+
"written_at": "2025-09-09T13:56:21Z",
27+
"entry": "Stage 1 COMPLETE! All lexing tests passing. Implemented comprehensive Ruby lexer supporting integers, decimals with underscores, strings with UTF-8 and escapes, booleans, nil, operators, keywords, identifiers, and comments. Fixed comment tokenization bug by properly handling newline characters. Next step: Stage 2 parsing."
28+
},
29+
{
30+
"written_at": "2025-09-09T14:11:58Z",
31+
"entry": "Stage 2 COMPLETE\\! All parsing tests now passing (10/10). Fixed AST structure issues: Set/Dictionary 'items' field, Index 'left' field, If expression 'consequence'/'alternative' fields, Function literals always wrapped in Block, and special handling for FunctionComposition (>>) and FunctionThread (|>) operators with flattened arrays. Parser now correctly handles all Stage 2 features: literals, variable declarations, arithmetic with precedence, collections (lists/sets/dicts), indexing, if-expressions, function literals, function calls, and composition. Ready to advance to Stage 3 - Basic evaluation."
32+
},
33+
{
34+
"written_at": "2025-09-09T14:24:38Z",
35+
"entry": "Stage 3 COMPLETE! All 11 evaluation tests passing. Implemented full evaluator with environment, variables (let/let mut), assignment, arithmetic operations, puts function, operator functions (+, -, *, /), type mixing, string operations, error handling, and proper integer division (truncate toward zero). All stages 1-3 now passing. Ready to advance to Stage 4 - Collections & indexing."
36+
},
37+
{
38+
"written_at": "2025-09-09T14:26:24Z",
39+
"entry": "Starting Stage 4 - Collections & indexing. Key requirements: immutable operations (push, assoc), built-ins (first, rest, size), indexing for strings/lists/dicts, structural equality, collection merging. Focus on maintaining existing functionality while adding new features."
40+
},
41+
{
42+
"written_at": "2025-09-09T14:30:43Z",
43+
"entry": "Stage 4 COMPLETE! All 17 collection and indexing tests now passing. Implemented: immutable collections (List, Set, Dictionary), built-in functions (push, assoc, first, rest, size), collection operations (+), indexing for strings/lists/dictionaries, structural equality, error handling for type mismatches, and deterministic printing with proper sorting. Key features: push/assoc return new collections, proper Unicode byte-size counting, negative indexing, Set deduplication, right-biased dictionary merging. All stages 1-4 passing. Ready for Stage 5 - Higher-order & composition."
44+
},
45+
{
46+
"written_at": "2025-09-09T14:43:58Z",
47+
"entry": "Stage 5 progress: 12/14 tests passing. Successfully implemented: partial application, higher-order functions (map/filter/fold), function composition (>>), pipeline threading (|>), recursive functions, and all error handling. Remaining issues: 1) Closures not properly capturing mutable variables by reference - assignment in closures doesn't affect captured vars, 2) assoc partial application with threading has argument count issue. Core functionality complete, working on final two edge cases."
48+
},
49+
{
50+
"written_at": "2025-09-09T14:53:13Z",
51+
"entry": "🎉 IMPLEMENTATION COMPLETE! All 57/57 tests passing across all stages 1-5. Successfully fixed the final two issues in Stage 5: 1) Closures now properly capture mutable variables by reference using shared VariableCell objects, and assignment expressions return their assigned values, 2) Fixed program evaluation logic to ignore trailing comments when determining final result. The elf-lang Ruby implementation is fully functional with comprehensive lexing, parsing, evaluation, closures, higher-order functions, partial application, function composition, threading, and error handling. Ready for production use."
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)