diff options
| author | elioat <elioat@tilde.institute> | 2025-07-20 17:13:01 -0400 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2025-07-20 17:13:01 -0400 |
| commit | acedbe9c853d53e250ab9238557191483100f45f (patch) | |
| tree | ee85983604dbd03f067000d99b9f5fd7e98cde35 /awk/scheme | |
| parent | 6d7584ef915e9554339582764c3269d496e16ba7 (diff) | |
| download | tour-acedbe9c853d53e250ab9238557191483100f45f.tar.gz | |
*
Diffstat (limited to 'awk/scheme')
| -rw-r--r-- | awk/scheme/scheme/README.md | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/awk/scheme/scheme/README.md b/awk/scheme/scheme/README.md index 4fdfbb5..5da2246 100644 --- a/awk/scheme/scheme/README.md +++ b/awk/scheme/scheme/README.md @@ -1,9 +1,9 @@ # Awk-Scheme ## Overview -A scheme interpreter implemented in AWK: +A simple Scheme interpreter implemented in AWK: -- A compiler that translates scheme expressions to stack-based VM instructions +- A compiler that translates Scheme expressions to stack-based VM instructions - A virtual machine that executes the compiled code - Support for basic arithmetic, list operations, functions, and variable bindings - **Closure support** for nested function definitions and lexical scoping @@ -14,7 +14,7 @@ A scheme interpreter implemented in AWK: ### Components 1. **Compiler** (`bin/compiler.awk`): - Lexical analyzer for tokenizing input - - Recursive descent parser for scheme expressions + - Recursive descent parser for Scheme expressions - Code generator that produces stack-based VM instructions - Handles nested expressions and proper scoping - **Generates closure creation code for lambda expressions** @@ -25,7 +25,7 @@ A scheme interpreter implemented in AWK: - Environment-based variable binding - **Direct function execution** (no program array modification) - **Closure support** with environment capture and restoration - - Heap memory for cons cells + - Simple heap for cons cells - State persistence for globals and functions 3. **REPL** (`bin/repl`): @@ -36,7 +36,7 @@ A scheme interpreter implemented in AWK: ### Data Types All values are tagged with their type: -- `N:value` - Numbers (integers) +- `N:value` - Numbers (integers only) - `B:value` - Booleans (0/1) - `P:index` - Pairs (cons cells) - `F:name` - Functions @@ -126,7 +126,7 @@ N:42 ```scheme scheme> (string-length "hello world") N:11 -scheme> (string-append "hello" " " "world") +scheme> (string-append "hello" " world") STR:hello world scheme> (string=? "hello" "hello") B:1 @@ -136,13 +136,11 @@ scheme> (substring "hello world" 0 4) STR:hell ``` -**Note**: Nested lambda definitions (lambdas defined inside other lambdas) are not yet supported. - ## Implementation Details ### Compiler Pipeline 1. **Lexical Analysis**: - - Tokenizes input into numbers, symbols, and parentheses + - Tokenizes input into numbers, symbols, parentheses, and strings - Handles whitespace and basic comments 2. **Parsing**: @@ -183,6 +181,28 @@ STR:hell - Automatic state loading/saving - **Note**: State persistence is enabled by default in the REPL +## Testing + +The project includes a comprehensive test suite: + +```bash +# Run all tests +./test/run_tests.sh + +# Run with debug output +DEBUG=1 ./test/run_tests.sh + +# Using make +make test +make test-debug +``` + +Test categories: +- **Unit tests**: Individual component tests +- **Integration tests**: End-to-end feature combinations +- **Example programs**: Demonstrations of language features +- **Regression tests**: Edge cases and complex expressions + ## Extending the System ### Adding New Special Forms @@ -211,7 +231,6 @@ STR:hell - Stack operations - Environment changes - **Closure creation and restoration** -- **Note**: Some debug output may be suppressed in the current implementation ## Limitations Current implementation does not support: @@ -223,6 +242,9 @@ Current implementation does not support: - Full numeric tower - Macros - Standard library +- Proper error handling and recovery +- Type checking beyond basic runtime checks +- **String operations limited to 2 arguments** (e.g., string-append only supports 2 strings) ## Future Enhancements 1. **Nested lambda support** (complex but achievable) |