about summary refs log tree commit diff stats
path: root/config.mk
blob: 0a86a54cddc7d0ca8e8521ad385a5f5f339fd4db (plain) (blame)
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
# dwm version
VERSION = 1.4

# Customize below to fit your system

# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man

X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib

# includes and libs
INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11

# flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}

# compiler and linker
CC = cc
LD = ${CC}
: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/bin/bash

# Enable debug tracing
DEBUG=0

debug() {
    if [ "$DEBUG" = "1" ]; then
        echo "[DEBUG] $*" >&2
    fi
}

# Find the directory containing this script and the components
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
COMPILER="$DIR/compiler.awk"
VM="$DIR/vm.awk"

debug "Using compiler: $COMPILER"
debug "Using VM: $VM"

# Verify components exist and are executable
for component in "$COMPILER" "$VM"; do
    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

# Set up temporary files and state
TMPDIR=$(mktemp -d)
debug "Created temp dir: $TMPDIR"
STATE_FILE="/tmp/scheme_vm.state"

cleanup() {
    debug "Cleaning up temp dir: $TMPDIR"
    rm -rf "$TMPDIR"
    if [ "$1" != "keep_state" ]; then
        rm -f "$STATE_FILE"
        rm -f "/tmp/scheme_vm.env"
    fi
}
trap "cleanup" EXIT

# Set up temporary files
INPUT_FILE="$TMPDIR/input.scm"
ASM_FILE="$TMPDIR/output.asm"
DEBUG_FILE="$TMPDIR/debug.out"

# Initialize/clear state files at REPL start
if [ "$#" -eq 0 ]; then  # Only for interactive mode
    : > "/tmp/scheme_vm.state"
    : > "/tmp/scheme_vm.env"
fi

# Function to handle evaluation
evaluate_expression() {
    local input="$1"
    local result
    
    # Skip empty lines
    if [ -z "$input" ]; then
        return 0
    fi
    
    debug "Evaluating expression: $input"
    echo "$input" > "$INPUT_FILE"
    debug "Input file contents:"
    cat "$INPUT_FILE" >&2
    
    # Show compilation output even if it fails
    debug "Running compiler..."
    if awk -f "$COMPILER" "$INPUT_FILE" > "$ASM_FILE" 2> "$DEBUG_FILE"; then
        debug "Compilation successful. Debug output:"
        cat "$DEBUG_FILE" >&2
        debug "Generated assembly:"
        cat "$ASM_FILE" >&2
        
        debug "Running VM..."
        # Use persistent VM state
        result=$(awk -v PERSIST=1 -f "$VM" "$ASM_FILE" 2>&1)
        debug "VM output: $result"
        if [ -n "$result" ]; then
            echo "$result"
        fi
        return 0
    else
        echo "Compilation error" >&2
        debug "Compiler output:"
        cat "$DEBUG_FILE" >&2
        return 1
    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
    debug "Reading file: $1"
    file_content=$(cat "$1" | tr '\n' ' ')
    debug "File content: $file_content"
    evaluate_expression "$file_content"
    cleanup "keep_state"  # Keep state after file execution
    exit 0
fi

# REPL state
paren_count=0
current_input=""

# Print welcome message
echo "Scheme REPL (Press Ctrl+D to exit)"
echo

# Main REPL loop
while true; do
    if [ $paren_count -eq 0 ]; then
        printf "scheme> "
    else
        printf "... "
    fi
    
    read -r line || exit 0
    
    # Skip empty lines
    if [ -z "$line" ]; then
        continue
    fi
    
    # Count parentheses
    open_parens=$(echo "$line" | tr -cd '(' | wc -c)
    close_parens=$(echo "$line" | tr -cd ')' | wc -c)
    paren_count=$((paren_count + open_parens - close_parens))
    
    if [ -n "$current_input" ]; then
        current_input="$current_input $line"
    else
        current_input="$line"
    fi
    
    if [ $paren_count -eq 0 ]; then
        evaluate_expression "$current_input"
        current_input=""
    fi
done