Skip to content

Commit be34210

Browse files
committed
helix-ts: basic IR
1 parent 5560cd8 commit be34210

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

helix-ts/deno.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tasks": {
3+
"dev": "deno run --watch main.ts"
4+
}
5+
}

helix-ts/ir.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
export const ExprKindString = { kind: "String" as const };
2+
export const ExprKindI64 = { kind: "I64" as const };
3+
export const ExprKindF64 = { kind: "F64" as const };
4+
export const ExprKindBoolean = { kind: "Boolean" as const };
5+
export const ExprKindVector = { kind: "Vector" as const };
6+
export const ExprKindList = (item: ExprKind) => ({
7+
kind: "List" as const,
8+
item,
9+
});
10+
export const ExprKindStruct = (fields: Record<string, ExprKind>) => ({
11+
kind: "Struct" as const,
12+
fields,
13+
});
14+
15+
export type ExprKind =
16+
| typeof ExprKindString
17+
| typeof ExprKindI64
18+
| typeof ExprKindF64
19+
| typeof ExprKindBoolean
20+
| typeof ExprKindVector
21+
| { kind: "List"; item: ExprKind }
22+
| { kind: "Struct"; fields: Record<string, ExprKind> };
23+
24+
export type Expr = {
25+
kind: ExprKind;
26+
expr:
27+
| { expr: "Argument"; index: number }
28+
| { expr: "PropAccess"; target: Expr; field: string }
29+
| { expr: "Literal"; value: any }
30+
| { expr: "BinaryOp"; op: string; left: Expr; right: Expr }
31+
| { expr: "Call"; func: string; args: Expr[] };
32+
};
33+
34+
export type Statement =
35+
| { stmt: "Expr"; expr: Expr }
36+
| { stmt: "Return"; value: Expr };
37+
38+
export type Block = Statement[];
39+
40+
export type QueryDefinition = {
41+
name: string;
42+
arguments: ExprKind[];
43+
returns: ExprKind;
44+
body: Block;
45+
};
46+
47+
export type NodeName = `node_${number}`;
48+
export type Node = {
49+
id: typeof ExprKindI64;
50+
[_: string]: ExprKind;
51+
};
52+
53+
export type EdgeName = `edge_${number}`;
54+
export type Edge = {
55+
id: typeof ExprKindI64;
56+
from: NodeName;
57+
to: NodeName;
58+
};
59+
60+
export const GlobalVectorspaceName = `vectorspace_global` as const;
61+
export type GlobalVectorspaceName = typeof GlobalVectorspaceName;
62+
export type GlobalVectorspace = symbol;
63+
64+
export type VectorspaceName = `vectorspace_${number}`;
65+
export type Vectorspace = {
66+
dimensions: number;
67+
hnsw: any; // TODO
68+
};
69+
70+
export type Schema = {
71+
nodes: Record<NodeName, Node>;
72+
indices: [{ on: NodeName; field: string; unique: boolean }];
73+
74+
edges: Record<EdgeName, Edge>;
75+
76+
vectorspaces:
77+
& Record<GlobalVectorspaceName, GlobalVectorspace>
78+
& Record<VectorspaceName, Vectorspace>;
79+
};

helix-ts/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (import.meta.main) {
2+
console.log("it runs!");
3+
}

0 commit comments

Comments
 (0)