ShellLite v0.05.0 (Performance Update) introduces native compilation via LLVM, enabling significant performance improvements for compute-intensive applications.
ShellLite supports three compilation targets:
| Target | Description | Use Case |
|---|---|---|
| LLVM | Native machine code | Maximum performance |
| JavaScript | Browser-compatible JS | Web deployment |
| Python | Python source code | Integration with Python ecosystem |
The LLVM backend compiles ShellLite code to native machine code for optimal performance.
pip install llvmlite# Compile to LLVM IR (default)
shl compile script.shl
# Explicit LLVM target
shl compile script.shl --target llvm- Lexing: Source code is tokenized
- Parsing: Tokens are parsed into an AST
- Code Generation: AST is converted to LLVM IR
- Optimization: LLVM applies optimizations
- Output: Native object code or executable
script.shl → script.ll (LLVM IR)
→ script.o (Object file)
→ script (Executable, platform-dependent)
Compile ShellLite to JavaScript for web deployment.
shl compile script.shl --target jsThis generates a .js file that can run in browsers or Node.js.
- Web applications
- Server-side Node.js apps
- Browser-based tools
input.shl:
to greet name
say "Hello, " + name
greet "World"output.js:
function greet(name) {
console.log("Hello, " + name);
}
greet("World");Transpile ShellLite to Python source code.
shl compile script.shl --target python- Integration with existing Python projects
- Access to Python debugging tools
- Gradual migration from ShellLite to Python
use "time"
start = time.now()
# Your code here
for i in range 1 1000000
x = i * 2
end = time.now()
say "Elapsed: " + str(end - start) + " seconds"# Slower: variable lookup each iteration
multiplier = 2
for i in range 1 1000000
x = i * multiplier
# Faster: constant (may be inlined)
const MULTIPLIER = 2
for i in range 1 1000000
x = i * MULTIPLIER# Slower: function call each iteration
for i in range 1 1000000
x = len(mylist)
# Faster: cache the value
list_length = len(mylist)
for i in range 1 1000000
x = list_length# Slower: manual implementation
total = 0
for n in numbers
total += n
# Faster: built-in
total = sum(numbers)# Slower: creates new string each iteration
result = ""
for word in words
result = result + word + " "
# Faster: use join
result = join(words, " ")use "builtins"
# Slower: traditional loop
squares = a list
for i in range 1 100
add i * i to squares
# Faster: list comprehension in Python
squares = [i * i for i in range(1, 100)]use "sys"
# Check object size
data = list of 1, 2, 3, 4, 5
say "Size: " + str(sys.getsizeof(data)) + " bytes"- Release large objects when done
large_data = load_huge_file()
process(large_data)
large_data = none # Allow garbage collection- Use generators for large datasets
# Instead of loading all at once
# all_data = load_all_records() # Memory intensive
# Process one at a time
for record in load_records_iterator()
process(record)- Avoid unnecessary copies
# Creates a copy
sorted_list = sort(original_list)
# Modifies in place (if available)
original_list.sort()Use The Bridge to profile your code.
use "cProfile"
use "pstats"
to expensive_function
total = 0
for i in range 1 100000
total += i * i
give total
# Profile the function
profiler = cProfile.Profile()
profiler.enable()
result = expensive_function()
profiler.disable()
stats = pstats.Stats(profiler)
stats.sort_stats("cumulative")
stats.print_stats(10)# Enable debug output
SHL_DEBUG=1 shl compile script.shl# Use Geometric Binding Parser (experimental)
USE_GBP=1 shl script.shl| Execution Mode | Relative Speed | Use Case |
|---|---|---|
| Interpreted | 1x (baseline) | Development, debugging |
| Python Compiled | ~1.2x | Integration |
| JavaScript (Node) | ~2-5x | Web deployment |
| LLVM Native | ~10-50x | Production, compute-heavy |
Note: Actual performance varies based on the specific code and operations.
- Profile before optimizing: Don't guess where bottlenecks are
- Use appropriate data structures: Lists vs. dictionaries vs. sets
- Compile for production: Use LLVM for deployed applications
- Cache expensive computations: Memoize functions that are called repeatedly
- Use The Bridge wisely: Python libraries may have optimized C implementations
- Avoid premature optimization: Write clean code first, optimize later
# O(n²) - can be very slow for large n
for i in range 1 n
for j in range 1 n
process(i, j)# Slow: O(n²) due to string immutability
result = ""
for i in range 1 10000
result += str(i)
# Better: collect then join
parts = a list
for i in range 1 10000
add str(i) to parts
result = join(parts, "")# Slow: O(n) lookup in list
if item in large_list
say "Found"
# Fast: O(1) lookup in set
large_set = a unique set of ...
if item in large_set
say "Found"Error: 'llvmlite' is required for LLVM compilation.
Solution: pip install llvmlite
The compiler will show the line number and error. Check for:
- Missing colons after control statements
- Incorrect indentation
- Unclosed strings or brackets
Some errors only appear at runtime:
- Type mismatches
- Undefined variables in conditional branches
- Division by zero