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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# Pry Programming Language
Pry is a simple, statically-typed programming language that compiles to native code via LLVM. It features a minimal C-like syntax with basic functional programming elements.
<img src="images/logo.svg" width="200" alt="Logo" />
## Features
- **Static typing** with explicit type annotations
- **Basic functions** with parameters and return types
- **Structs** with field access
- **Manual memory management** via C library functions
- **C interoperability** through extern declarations
- **Simple import system** for code organization
- **LLVM backend** for native code generation
## Quick Start
### Prerequisites
- Zig (latest stable version)
- LLVM development libraries
- A C compiler (gcc/clang) for linking
### Using with Nix
If you have Nix with flakes enabled:
```bash
# Enter development shell with all dependencies
nix develop
# Or run directly
nix develop -c zig build run -- examples/1.pry
```
The flake provides Zig, ZLS (Zig Language Server), LLVM, and debugging tools.
### Building and Running
1. **Compile a Pry program:**
```bash
zig build run -- examples/1.pry
```
2. **Link and create executable:**
```bash
cc output.o -o program
```
3. **Run the program:**
```bash
./program
```
## Language Overview
### Basic Syntax
```pry
// Hello World
import "!stdlib.pry";
let main = () => i64 {
printf("Hello, World!\n");
return 0;
};
```
### Variables and Types
```pry
let x = 42; // i64 integer
let name = "Alice"; // String literal (*i8)
let flag = true; // Boolean
```
**Built-in types:**
- `i64`, `i32`, `i8` - Signed integers
- `bool` - Boolean values
- `*T` - Pointers to type T
- `void` - Unit type
### Functions
```pry
// Function with explicit parameter types
let add = (a: i64, b: i64) => i64 {
return a + b;
};
// Recursive function
let fib = (n: i64) => i64 {
if n == 0 {
return 0;
};
if n == 1 {
return 1;
};
return fib(n-2) + fib(n-1);
};
```
### Control Flow
```pry
// If statements (no else yet)
if condition {
// statements
};
// While loops
let i = 0;
while i < 10 {
printf("%d\n", i);
i = i + 1;
};
```
### Structs
```pry
// Define a struct type
let Point = struct {
x: i64,
y: i64
};
let main = () => i64 {
let p = Point{}; // Empty initialization
p.x = 10; // Field assignment
p.y = 20;
return 0;
};
```
### Memory Management
```pry
// Use C library functions for memory management
extern malloc = (i64) => *void;
extern free = (*void) => void;
let main = () => i64 {
let ptr = cast(*i64, malloc(8));
*ptr = 42;
free(cast(*void, ptr));
return 0;
};
```
### C Interoperability
```pry
// Declare external C functions
extern printf = (*i8, varargs) => void;
extern putchar = (i64) => i64;
let main = () => i64 {
putchar(72); // 'H'
putchar(105); // 'i'
putchar(10); // '\n'
return 0;
};
```
## Current Limitations
Pry is a work-in-progress language with several limitations:
- No `else` clauses for if statements
- No `for` loops (only `while`)
- No arrays (use pointers and manual indexing)
- No string manipulation beyond C functions
- No generics or templates
- No pattern matching
- Limited error handling
- Basic type system
## Examples
The `examples/` directory contains test programs showing:
- Basic I/O (`examples/1.pry`)
- Recursive functions (`examples/8.pry`)
- Memory management (`examples/20.pry`)
- Struct usage (`examples/22.pry`, `examples/24.pry`)
- C library integration (`examples/15.pry`)
Try running:
```bash
zig build run -- examples/8.pry # Fibonacci sequence
zig build run -- examples/1.pry # Hello world
zig build run -- examples/20.pry # Array manipulation
```
## Standard Library
The minimal standard library (`std/stdlib.pry`) provides:
- `printf` - C printf wrapper
- `strcmp` - String comparison
- `isdigit`, `isalpha` - Character classification helpers
- `assert` - Simple assertion function
## Implementation
Pry is currently implemented in Zig with plans for self-hosting:
- `src/main.zig` - Compiler entry point
- `src/tokenizer.zig` - Lexical analysis
- `src/parser.zig` - Syntax analysis and AST generation
- `src/codegen.zig` - LLVM IR generation
- `src/bootstrap/` - Future self-hosted compiler (work in progress)
The grammar is formally defined in `grammar.ebnf`.
## Development Status
Pry is an experimental language currently in active development. While functional for basic programs, it's not yet feature-complete.
---
*Pry is a minimal systems programming language focused on simplicity and clean design.*
|