pearc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -0
- package/dist/codegen.d.ts +29 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +644 -0
- package/dist/codegen.js.map +1 -0
- package/dist/compiler.d.ts +23 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +370 -0
- package/dist/compiler.js.map +1 -0
- package/dist/decompiler.d.ts +25 -0
- package/dist/decompiler.d.ts.map +1 -0
- package/dist/decompiler.js +294 -0
- package/dist/decompiler.js.map +1 -0
- package/dist/interpreter.d.ts +72 -0
- package/dist/interpreter.d.ts.map +1 -0
- package/dist/interpreter.js +2063 -0
- package/dist/interpreter.js.map +1 -0
- package/dist/lexer.d.ts +125 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +563 -0
- package/dist/lexer.js.map +1 -0
- package/dist/mcp-server.d.ts +3 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +228 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/parser.d.ts +307 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +1047 -0
- package/dist/parser.js.map +1 -0
- package/examples/hello.pr +2 -0
- package/examples/pointers.pr +32 -0
- package/examples/structs.pr +6 -0
- package/package.json +40 -0
- package/spec/pear.md +213 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# pearc
|
|
2
|
+
|
|
3
|
+
**Pear** is an ultra-minified C-targeting programming language designed to reduce token usage in LLM workflows while producing real, executable code.
|
|
4
|
+
|
|
5
|
+
The idea: write code that compiles to C — with ~35–50% fewer tokens than idiomatic C — then expand it back to readable code via a decompiler or MCP tool.
|
|
6
|
+
|
|
7
|
+
```pear
|
|
8
|
+
im<stdio.h>
|
|
9
|
+
st Point{x:f64;y:f64}
|
|
10
|
+
fn dist(a:*Point,b:*Point)->f64{dx:f64=a->x-b->x;dy:f64=a->y-b->y;rt sqrt(dx*dx+dy*dy)}
|
|
11
|
+
fn main()->i32{p1:Point={1.0,2.0};p2:Point={4.0,6.0};printf("%f\n",dist(&p1,&p2));rt 0}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g pearc
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pearc run file.pr # interpret and run directly (no C compiler needed)
|
|
24
|
+
pearc file.pr # compile Pear → C (stdout)
|
|
25
|
+
pearc file.pr -o out.c # compile Pear → C file
|
|
26
|
+
pearc file.pr --binary -o out # compile Pear → native binary (requires gcc/clang)
|
|
27
|
+
pearc --decompile file.c # minify existing C → Pear
|
|
28
|
+
pearc --mcp # start MCP server (stdio)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## MCP Server
|
|
32
|
+
|
|
33
|
+
Add to Claude Code or any MCP client:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"mcpServers": {
|
|
38
|
+
"pear": {
|
|
39
|
+
"command": "npx",
|
|
40
|
+
"args": ["pearc", "--mcp"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Tools exposed:**
|
|
47
|
+
|
|
48
|
+
| Tool | Description |
|
|
49
|
+
|------|-------------|
|
|
50
|
+
| `pear_to_c` | Compile Pear → C source |
|
|
51
|
+
| `c_to_pear` | Minify C → Pear |
|
|
52
|
+
| `pear_run` | Interpret and run Pear, returns stdout/stderr |
|
|
53
|
+
| `pear_compile` | Compile Pear → binary via gcc/clang |
|
|
54
|
+
|
|
55
|
+
## Language Reference
|
|
56
|
+
|
|
57
|
+
### Types
|
|
58
|
+
|
|
59
|
+
| Pear | C |
|
|
60
|
+
|------|---|
|
|
61
|
+
| `i8` `i16` `i32` `i64` | `int8_t` `int16_t` `int32_t` `int64_t` |
|
|
62
|
+
| `u8` `u16` `u32` `u64` | `uint8_t` `uint16_t` `uint32_t` `uint64_t` |
|
|
63
|
+
| `f32` `f64` | `float` `double` |
|
|
64
|
+
| `v` | `void` |
|
|
65
|
+
| `c` | `char` |
|
|
66
|
+
| `b` | `bool` |
|
|
67
|
+
| `sz` | `size_t` |
|
|
68
|
+
| `*T` | pointer to T |
|
|
69
|
+
|
|
70
|
+
### Keywords
|
|
71
|
+
|
|
72
|
+
| Pear | C |
|
|
73
|
+
|------|---|
|
|
74
|
+
| `fn` | function |
|
|
75
|
+
| `st` | struct |
|
|
76
|
+
| `un` | union |
|
|
77
|
+
| `en` | enum |
|
|
78
|
+
| `tp` | typedef |
|
|
79
|
+
| `if` `ei` `el` | if / else if / else |
|
|
80
|
+
| `lp` | for |
|
|
81
|
+
| `wh` | while |
|
|
82
|
+
| `dw` | do...while |
|
|
83
|
+
| `sw` `cs` `dv` | switch / case / default |
|
|
84
|
+
| `rt` | return |
|
|
85
|
+
| `bk` `ct` | break / continue |
|
|
86
|
+
| `sc` `ex` `in` `vl` `cn` | static / extern / inline / volatile / const |
|
|
87
|
+
| `im` | #include |
|
|
88
|
+
| `df` | #define |
|
|
89
|
+
| `pr` | #pragma |
|
|
90
|
+
| `so` | sizeof |
|
|
91
|
+
|
|
92
|
+
### Syntax
|
|
93
|
+
|
|
94
|
+
```pear
|
|
95
|
+
// Variable declaration: name:type = value
|
|
96
|
+
x:i32=5
|
|
97
|
+
ptr:*c=name
|
|
98
|
+
|
|
99
|
+
// Function: fn name(param:type,...)->rettype{...}
|
|
100
|
+
fn add(a:i32,b:i32)->i32{rt a+b}
|
|
101
|
+
|
|
102
|
+
// Struct
|
|
103
|
+
st Vec3{x:f32;y:f32;z:f32}
|
|
104
|
+
|
|
105
|
+
// For loop (same structure as C)
|
|
106
|
+
lp(i:i32=0;i<10;i++){printf("%d\n",i)}
|
|
107
|
+
|
|
108
|
+
// Include / define
|
|
109
|
+
im<stdio.h>
|
|
110
|
+
df MAX 1024
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Preprocessor
|
|
114
|
+
|
|
115
|
+
```pear
|
|
116
|
+
im<stdio.h> // #include <stdio.h>
|
|
117
|
+
im"myfile.h" // #include "myfile.h"
|
|
118
|
+
df NAME value // #define NAME value
|
|
119
|
+
pr once // #pragma once
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Token Savings
|
|
123
|
+
|
|
124
|
+
Pear reduces token count by ~35–50% vs idiomatic C:
|
|
125
|
+
|
|
126
|
+
```pear
|
|
127
|
+
// Pear: ~45 tokens
|
|
128
|
+
im<stdint.h>
|
|
129
|
+
st Point{x:f64;y:f64}
|
|
130
|
+
fn dist(a:*Point,b:*Point)->f64{dx:f64=a->x-b->x;dy:f64=a->y-b->y;rt sqrt(dx*dx+dy*dy)}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```c
|
|
134
|
+
// C: ~85 tokens
|
|
135
|
+
#include <stdint.h>
|
|
136
|
+
typedef struct { double x; double y; } Point;
|
|
137
|
+
double dist(Point *a, Point *b) {
|
|
138
|
+
double dx = a->x - b->x;
|
|
139
|
+
double dy = a->y - b->y;
|
|
140
|
+
return sqrt(dx*dx + dy*dy);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Program, Expr } from './parser';
|
|
2
|
+
export declare class CodeGenerator {
|
|
3
|
+
private output;
|
|
4
|
+
private indent;
|
|
5
|
+
private needsStdint;
|
|
6
|
+
private needsStdbool;
|
|
7
|
+
private hasStdint;
|
|
8
|
+
private hasStdbool;
|
|
9
|
+
generate(program: Program): string;
|
|
10
|
+
private detectRequiredHeaders;
|
|
11
|
+
private checkTypeForHeaders;
|
|
12
|
+
private emit;
|
|
13
|
+
private emitIndent;
|
|
14
|
+
private formatType;
|
|
15
|
+
private genNode;
|
|
16
|
+
private genBodyStmt;
|
|
17
|
+
private genVarDecl;
|
|
18
|
+
private genFunction;
|
|
19
|
+
private genStruct;
|
|
20
|
+
private genUnion;
|
|
21
|
+
private genEnum;
|
|
22
|
+
private genTypedef;
|
|
23
|
+
private genBlock;
|
|
24
|
+
private genIf;
|
|
25
|
+
private genFor;
|
|
26
|
+
genExprStr(expr: Expr): string;
|
|
27
|
+
}
|
|
28
|
+
export declare function generate(program: import('./parser').Program): string;
|
|
29
|
+
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAGA,OAAO,EACI,OAAO,EAMhB,IAAI,EAGL,MAAM,UAAU,CAAC;AASlB,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,UAAU,CAAkB;IAEpC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAqBlC,OAAO,CAAC,qBAAqB;IAmE7B,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,UAAU;IA4BlB,OAAO,CAAC,OAAO;IA2Kf,OAAO,CAAC,WAAW;IAiCnB,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,WAAW;IAkCnB,OAAO,CAAC,SAAS;IAsBjB,OAAO,CAAC,QAAQ;IAqBhB,OAAO,CAAC,OAAO;IAuBf,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,KAAK;IAgDb,OAAO,CAAC,MAAM;IAqCd,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;CAyE/B;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,UAAU,EAAE,OAAO,GAAG,MAAM,CAGpE"}
|