about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-01-19 19:59:17 -0500
committerelioat <elioat@tilde.institute>2025-01-19 19:59:17 -0500
commit9563293d0521e5b5d3306e3bb3f512b5e4765d6b (patch)
tree57910cbd9524382a14323befd080aed86e43c2b2
parent750a35e4fb732a91548f967f25ed12251a111bc9 (diff)
downloadtour-9563293d0521e5b5d3306e3bb3f512b5e4765d6b.tar.gz
*
-rwxr-xr-xawk/scheme/scheme/bin/repl51
-rw-r--r--awk/scheme/scheme/examples/simple.scm1
2 files changed, 24 insertions, 28 deletions
diff --git a/awk/scheme/scheme/bin/repl b/awk/scheme/scheme/bin/repl
index a3f66fe..b865aa2 100755
--- a/awk/scheme/scheme/bin/repl
+++ b/awk/scheme/scheme/bin/repl
@@ -19,11 +19,12 @@ debug "Using VM: $VM"
 
 # Verify components exist and are executable
 for component in "$COMPILER" "$VM"; do
-    if [ ! -x "$component" ]; then
-        echo "Error: Cannot execute $component" >&2
-        echo "Please ensure all components are present and executable" >&2
+    if [ ! -f "$component" ]; then
+        echo "Error: Cannot find $component" >&2
+        echo "Please ensure all components are present" >&2
         exit 1
     fi
+    chmod +x "$component"
 done
 
 # Create temporary directory for our work
@@ -45,30 +46,18 @@ evaluate_expression() {
     local input="$1"
     local result
     
-    debug "Evaluating expression: $input"
+    # Skip empty lines
+    if [ -z "$input" ]; then
+        return 0
+    fi
     
-    # Write to input file
+    debug "Evaluating expression: $input"
     echo "$input" > "$INPUT_FILE"
-    debug "Wrote to input file: $INPUT_FILE"
     
-    # Show compilation command
-    debug "Running compiler: $COMPILER $INPUT_FILE > $ASM_FILE"
-    
-    # Compile and show the generated assembly
-    if "$COMPILER" "$INPUT_FILE" > "$ASM_FILE" 2>/dev/null; then
-        debug "Compilation successful"
-        debug "Generated assembly:"
-        debug "$(cat "$ASM_FILE")"
-        
-        debug "Running VM: $VM $ASM_FILE"
-        result=$("$VM" "$ASM_FILE")
-        debug "VM output: '$result'"
-        
-        # Only print if there's a result
+    if awk -f "$COMPILER" "$INPUT_FILE" > "$ASM_FILE" 2>/dev/null; then
+        result=$(awk -f "$VM" "$ASM_FILE")
         if [ -n "$result" ]; then
             echo "$result"
-        else
-            debug "No output from VM"
         fi
         return 0
     else
@@ -77,6 +66,18 @@ evaluate_expression() {
     fi
 }
 
+# Check if a file argument is provided
+if [ "$#" -gt 0 ]; then
+    if [ ! -f "$1" ]; then
+        echo "Error: File not found: $1" >&2
+        exit 1
+    fi
+    # Read entire file content at once
+    file_content=$(cat "$1" | tr '\n' ' ')
+    evaluate_expression "$file_content"
+    exit 0
+fi
+
 # REPL state
 paren_count=0
 current_input=""
@@ -87,14 +88,12 @@ echo
 
 # Main REPL loop
 while true; do
-    # Show appropriate prompt
     if [ $paren_count -eq 0 ]; then
         printf "scheme> "
     else
         printf "... "
     fi
     
-    # Read a line
     read -r line || exit 0
     
     # Skip empty lines
@@ -107,16 +106,12 @@ while true; do
     close_parens=$(echo "$line" | tr -cd ')' | wc -c)
     paren_count=$((paren_count + open_parens - close_parens))
     
-    debug "Paren count: $paren_count"
-    
-    # Append to current input
     if [ -n "$current_input" ]; then
         current_input="$current_input $line"
     else
         current_input="$line"
     fi
     
-    # If we have a complete expression, evaluate it
     if [ $paren_count -eq 0 ]; then
         evaluate_expression "$current_input"
         current_input=""
diff --git a/awk/scheme/scheme/examples/simple.scm b/awk/scheme/scheme/examples/simple.scm
new file mode 100644
index 0000000..4d956a6
--- /dev/null
+++ b/awk/scheme/scheme/examples/simple.scm
@@ -0,0 +1 @@
+(+ 1 2)