From ac6349533c29d386ea7d65b66e1126236eb51384 Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Thu, 4 Apr 2024 17:12:41 +0300 Subject: [PATCH] Added Basic types --- src/types/ast.ts | 126 +++++++++++++++++++++++++++++++++++ src/types/circuitArtifact.ts | 14 ++++ 2 files changed, 140 insertions(+) create mode 100644 src/types/ast.ts create mode 100644 src/types/circuitArtifact.ts diff --git a/src/types/ast.ts b/src/types/ast.ts new file mode 100644 index 0000000..93cdc4c --- /dev/null +++ b/src/types/ast.ts @@ -0,0 +1,126 @@ +// Helper types + +export type SignalType = "Output" | "Input" | "Intermediate"; + +// Compiler and Definitions + +export interface CompilerConfig { + meta: Meta; + compiler_version: number[]; + custom_gates: boolean; + custom_gates_declared: boolean; + includes: string[]; + definitions: Definition[]; + main_component?: MainComponent; +} + +export type MainComponent = [string[], Call]; + +export interface Call { + meta: Meta; + id: string; + args: any[]; +} + +export type Definition = { + Template?: Template; +}; + +export interface Template { + meta: Meta; + name: string; + args: string[]; + arg_location: Location; + body: Body; + parallel: boolean; + is_custom_gate: boolean; +} + +export interface Body { + Block: Block; +} + +export interface Block { + meta: Meta; + stmts: Stmt[]; +} + +export type Stmt = { + InitializationBlock?: InitializationBlock; + Substitution?: Substitution; +}; + +export interface InitializationBlock { + meta: Meta; + xtype: XType; + initializations: Initialization[]; +} + +export type Initialization = { + Declaration: Declaration; +}; + +export interface Declaration { + meta: Meta; + xtype: XType; + name: string; + dimensions: any[]; + is_constant: boolean; +} + +export interface Substitution { + meta: Meta; + var: string; + access: any[]; + op: string; + rhe: Rhe; +} + +export interface Rhe { + InfixOp: InfixOp; +} + +export interface InfixOp { + meta: Meta; + lhe: Variable; + infix_op: string; + rhe: Variable; +} + +export interface Variable { + meta: Meta; + name: string; + access: any[]; +} + +export type XType = { + Signal: [string, any[]]; +}; + +// Base Types + +export interface Meta { + elem_id: number; + start: number; + end: number; + location: Location; + file_id?: string; + component_inference?: string; + type_knowledge: TypeKnowledge; + memory_knowledge: MemoryKnowledge; +} + +export interface Location { + start: number; + end: number; +} + +export interface TypeKnowledge { + reduces_to?: string; +} + +export interface MemoryKnowledge { + concrete_dimensions?: string; + full_length?: string; + abstract_memory_address?: string; +} diff --git a/src/types/circuitArtifact.ts b/src/types/circuitArtifact.ts new file mode 100644 index 0000000..765a14f --- /dev/null +++ b/src/types/circuitArtifact.ts @@ -0,0 +1,14 @@ +import { SignalType } from "./ast"; + +export interface CircuitArtifact { + _format: string; + circuitName: string; + sourceName: string; + signals: Signal[]; +} + +export interface Signal { + name: string; + type: SignalType; + internalType: string; +}