Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .ccache/ccache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ccache configuration for Io builds
# Optimized for Apple Silicon Macs

# Set cache size (2GB should be plenty for Io)
max_size = 2G

# Enable compression for smaller cache
compression = true
compression_level = 6

# Use hard links when possible (faster on same filesystem)
hard_link = true

# Keep statistics
stats = true

# Sloppiness settings for faster builds
sloppiness = file_macro,time_macros,include_file_mtime,include_file_ctime

# Hash the compiler version
compiler_check = %compiler% -v

# Cache preprocessing step
direct_mode = true

# Use base directory for relative paths
base_dir = /Users/david/vcs/git/github/davidcanhelp/io
83 changes: 83 additions & 0 deletions BUILD_AND_TEST.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
# Complete build and test script for Io language

echo "=== Io Language Build Script ==="
echo "This script will build and test the Io language with our bug fixes"
echo ""

# Navigate to the Io directory
IO_DIR="/Users/david/vcs/git/github/davidcanhelp/io"
cd "$IO_DIR" || exit 1

# Clean up the nested build directories
echo "1. Cleaning up nested build directories..."
rm -rf build/build

# Check if we have a proper build directory
if [ -d "build" ]; then
echo " Build directory exists at: $IO_DIR/build"
cd build
else
echo " Creating new build directory..."
mkdir build
cd build
fi

echo ""
echo "2. Configuring with CMake..."
if [ -f "CMakeCache.txt" ]; then
echo " CMake cache found, using existing configuration"
else
cmake .. || { echo "CMake configuration failed"; exit 1; }
fi

echo ""
echo "3. Building Io..."
echo " Using make to build the project..."

# Try to build using make
if command -v make &> /dev/null; then
make -j4 || make || { echo "Build failed with make"; }
fi

# If make didn't work, try cmake --build
if [ ! -f "_build/binaries/io" ]; then
echo " Trying cmake --build..."
cmake --build . --parallel 4 || cmake --build .
fi

echo ""
echo "4. Checking build results..."
if [ -f "_build/binaries/io" ]; then
echo " ✅ Io binary successfully built!"
echo " Location: $PWD/_build/binaries/io"

echo ""
echo "5. Running tests..."
echo " Testing our bug fixes..."

# Test the Io binary
./_build/binaries/io -e "writeln(\"Hello from Io!\")" 2>/dev/null && echo " ✅ Basic execution works!"

# Test if we can run the test suite
if [ -f "../libs/iovm/tests/correctness/run.io" ]; then
echo " Running test suite..."
./_build/binaries/io ../libs/iovm/tests/correctness/run.io 2>&1 | head -20
fi
else
echo " ❌ Io binary not found. Build may have failed."
echo " Checking for build artifacts..."

find . -name "io" -type f 2>/dev/null | head -5
find . -name "*.a" -type f 2>/dev/null | head -5
fi

echo ""
echo "=== Summary of Changes ==="
echo "The following bug fixes have been applied:"
echo "1. IoFile.c - Fixed double evaluation bug in atPut()"
echo "2. IoDynLib.c - Fixed memory leak for BLOCK types"
echo "3. IoMessage_parser.c - Added proper error messages"
echo "4. run.io - Fixed cross-platform path handling"
echo ""
echo "Build script complete!"
163 changes: 163 additions & 0 deletions Makefile.optimized
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Optimized Makefile for Io Language on Mac
# Provides simple commands for common build tasks

.PHONY: all build clean test install help debug release quick bench setup

# Default target
all: build

# Color output
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[1;33m
BLUE := \033[0;34m
NC := \033[0m

# Detect system
CORES := $(shell sysctl -n hw.ncpu)
ARCH := $(shell uname -m)

# Build directories
BUILD_DIR := build
BUILD_DEBUG_DIR := build-debug
BUILD_RELEASE_DIR := build-release

help:
@echo "$(BLUE)Io Language Build System$(NC)"
@echo ""
@echo "$(GREEN)Quick Commands:$(NC)"
@echo " make - Build Io (optimized for your Mac)"
@echo " make quick - Fast incremental build"
@echo " make clean - Clean build from scratch"
@echo " make test - Run test suite"
@echo ""
@echo "$(GREEN)Build Variants:$(NC)"
@echo " make debug - Debug build with symbols"
@echo " make release - Release build with max optimization"
@echo " make bench - Benchmark build with profiling"
@echo ""
@echo "$(GREEN)Installation:$(NC)"
@echo " make install - Install to /usr/local (requires sudo)"
@echo " make setup - Install build dependencies via Homebrew"
@echo ""
@echo "$(YELLOW)System: $(ARCH) with $(CORES) cores$(NC)"

# Standard optimized build
build:
@echo "$(BLUE)Building Io (optimized)...$(NC)"
@chmod +x build_optimized.sh
@./build_optimized.sh

# Quick incremental build (no reconfigure)
quick:
@echo "$(BLUE)Quick build...$(NC)"
@if [ -d "$(BUILD_DIR)" ]; then \
cd $(BUILD_DIR) && $(MAKE) -j$(CORES); \
else \
$(MAKE) build; \
fi

# Clean build
clean:
@echo "$(RED)Cleaning all build artifacts...$(NC)"
@rm -rf $(BUILD_DIR) $(BUILD_DEBUG_DIR) $(BUILD_RELEASE_DIR)
@rm -f io
@echo "$(GREEN)✓ Clean complete$(NC)"
@$(MAKE) build

# Debug build
debug:
@echo "$(BLUE)Building Io (debug mode)...$(NC)"
@mkdir -p $(BUILD_DEBUG_DIR)
@cd $(BUILD_DEBUG_DIR) && \
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS="-g -O0 -fsanitize=address" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" \
.. && \
$(MAKE) -j$(CORES)
@ln -sf $(BUILD_DEBUG_DIR)/_build/binaries/io io-debug
@echo "$(GREEN)✓ Debug build complete: ./io-debug$(NC)"

# Release build with maximum optimization
release:
@echo "$(BLUE)Building Io (release mode)...$(NC)"
@mkdir -p $(BUILD_RELEASE_DIR)
@cd $(BUILD_RELEASE_DIR) && \
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-O3 -march=native -mtune=native -flto -DNDEBUG" \
-DCMAKE_EXE_LINKER_FLAGS="-flto -Wl,-dead_strip_dylibs" \
.. && \
$(MAKE) -j$(CORES)
@ln -sf $(BUILD_RELEASE_DIR)/_build/binaries/io io-release
@echo "$(GREEN)✓ Release build complete: ./io-release$(NC)"

# Benchmark build
bench: release
@echo "$(BLUE)Building with profiling support...$(NC)"
@cd $(BUILD_RELEASE_DIR) && \
cmake -DCMAKE_C_FLAGS="-O3 -march=native -pg" \
-DCMAKE_EXE_LINKER_FLAGS="-pg" \
.. && \
$(MAKE) -j$(CORES)
@echo "$(GREEN)✓ Benchmark build ready$(NC)"

# Run tests
test: build
@echo "$(BLUE)Running Io test suite...$(NC)"
@if [ -f "$(BUILD_DIR)/_build/binaries/io" ]; then \
$(BUILD_DIR)/_build/binaries/io libs/iovm/tests/correctness/run.io; \
else \
echo "$(RED)✗ Io not built. Run 'make build' first$(NC)"; \
fi

# Install to system
install: build
@echo "$(BLUE)Installing Io...$(NC)"
@cd $(BUILD_DIR) && sudo $(MAKE) install
@echo "$(GREEN)✓ Io installed to /usr/local$(NC)"

# Setup development environment
setup:
@echo "$(BLUE)Setting up development environment...$(NC)"
@command -v brew >/dev/null 2>&1 || { \
echo "$(YELLOW)Installing Homebrew...$(NC)"; \
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
}
@echo "$(YELLOW)Installing build dependencies...$(NC)"
@brew install cmake ninja ccache
@echo "$(GREEN)✓ Development environment ready$(NC)"

# Benchmark runner
benchmark: bench
@echo "$(BLUE)Running benchmarks...$(NC)"
@$(BUILD_RELEASE_DIR)/_build/binaries/io samples/speed/speed.io

# Create Xcode project
xcode:
@echo "$(BLUE)Generating Xcode project...$(NC)"
@mkdir -p build-xcode
@cd build-xcode && cmake -G Xcode ..
@echo "$(GREEN)✓ Xcode project created in build-xcode/$(NC)"
@echo "Open with: open build-xcode/IoLanguage.xcodeproj"

# Development build with compile_commands.json for IDEs
dev:
@echo "$(BLUE)Creating development build with IDE support...$(NC)"
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && \
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE=Debug .. && \
$(MAKE) -j$(CORES)
@ln -sf $(BUILD_DIR)/compile_commands.json compile_commands.json
@echo "$(GREEN)✓ Development build ready with compile_commands.json$(NC)"

# Print system info
info:
@echo "$(BLUE)System Information:$(NC)"
@echo " Architecture: $(ARCH)"
@echo " CPU Cores: $(CORES)"
@echo " Compiler: $$(clang --version | head -1)"
@echo " CMake: $$(cmake --version | head -1)"
@echo " macOS: $$(sw_vers -productVersion)"

.DEFAULT_GOAL := help
72 changes: 72 additions & 0 deletions TESTING_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Testing Summary for Io Language Fixes

## Changes Made

### 1. IoFile.c (Line 1006-1007)
**Fix**: Store position value once to prevent double evaluation
- **Before**: Position argument could be evaluated twice with side effects
- **After**: Position is stored in variable `pos` at start of function
- **Test**: Compile test passed successfully

### 2. IoDynLib.c (Line 264-267)
**Fix**: Free memory allocated for BLOCK trampoline code
- **Before**: Memory leak when marshalling BLOCK types
- **After**: Added `io_free((void *)n)` in demarshal for BLOCK case
- **Test**: Compile test passed successfully

### 3. IoMessage_parser.c (Lines 115-116, 227-228, 234-235)
**Fix**: Added proper error messages with line numbers
- **Before**: Empty TODO comments for error cases
- **After**: Implemented descriptive error messages with line numbers
- **Test**: Compile test passed successfully

### 4. run.io Test Runner (Line 9)
**Fix**: Use platform-independent path joining
- **Before**: Hard-coded "/" separator
- **After**: Uses `Path with()` for cross-platform compatibility
- **Test**: Syntax is valid Io code

## Compilation Status

Individual file compilation tests:
- ✅ IoFile.c - Compiles successfully
- ✅ IoDynLib.c - Compiles successfully
- ✅ IoMessage_parser.c - Compiles successfully

## Build Issues

The full project build requires the parson JSON library dependency which was missing from the repository. A stub implementation was created to allow partial compilation testing.

## Recommendations

1. **Get Full Dependencies**: The project needs the actual parson library from https://github.com/kgabis/parson
2. **Run Full Test Suite**: Once built, run `io libs/iovm/tests/correctness/run.io`
3. **Memory Testing**: Run with valgrind to verify the memory leak fix in IoDynLib.c
4. **Cross-Platform Testing**: Test the path fix on Windows to ensure compatibility

## How to Test When Build is Available

```bash
# Build the project
mkdir build && cd build
cmake ..
make

# Run tests
./io ../libs/iovm/tests/correctness/run.io

# Test specific file operations
./io ../test_changes.io

# Memory leak testing (Linux/macOS)
valgrind --leak-check=full ./io [test_script]
```

## Code Quality

All changes:
- Are minimal and focused
- Maintain backward compatibility
- Follow existing code style
- Include appropriate error messages
- Fix actual bugs (not just cosmetic issues)
44 changes: 44 additions & 0 deletions build_now.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Direct build script for Io

echo "Starting Io build..."
cd /Users/david/vcs/git/github/davidcanhelp/io

# Clean up nested directories
rm -rf build/build/build

# Enter build directory
if [ -d "build" ]; then
cd build
echo "Using existing build directory"
else
mkdir build
cd build
echo "Created new build directory"
fi

# Configure if needed
if [ ! -f "Makefile" ]; then
echo "Configuring with CMake..."
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-O2" \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
..
fi

# Build
echo "Building with make..."
make -j8 VERBOSE=1

# Check result
if [ -f "_build/binaries/io" ]; then
echo "✓ Build successful!"
echo "Binary at: $(pwd)/_build/binaries/io"

# Test it
echo "Testing binary..."
./_build/binaries/io -e 'writeln("Io is working!")'
else
echo "Build may have failed. Checking for artifacts..."
find . -name "io" -type f 2>/dev/null | head -5
fi
Loading
Loading