# Cadlang design
## Geometry
We can provide primitive geometries like Points, Lines, Rectangles like this.
Then to build other geometries, definitions of a geometry contains either primitive geometries or other geometry
```
// Pure geometry implementation
define Rectangle : Geometry {
a1 : Points
a2 : Points
a3 : Points
a4 : Points
};
// Self contained constraint
impl Constraint for Rectangle {
// ...
}
// Mixed Implementation
define House : Geometry {
r : Rectangle,
l1 : Line,
l2 : Line,
};
impl Constraint for House {
}
```
Then a usage would be
```
let rect = Rectangle {
a1 : (1, 1)
a2 : (2, 2)
a3 : (1, 2)
a4 : (2, 1)
}
```
```
```
Define primitives
Define a set of constraints: Distance, Alignment, Ordering of fields
### Constraints between geometries
We can define constraints via pairs of geometries?!
```
// Here, the constraint dictates that r1 is the centre.
// Suppose I edit some points of r1, r2 will adjusts automatically
// if i edit some points of r2, then the program logs this as an error
define C1 : MovableConstraint(r1 : Rectangle, r2 : Rectangle) {
};
// Here, no matter whose's element i change, i will get an error
define C2 : PanicConstraint(r1 : Rectangle, r2 : Rectangle) {
};
```
For impl, we can think of some kind of graph???:
For example, if b needs to be 2 units to the right of a, and 1 units up of a
then the constraint graph shows
```
a -> [{b, (1, 2)}]
```
> Is all elements tilable?
I think tiling suggests some kind of inferrence on the coordinates of the geometry.
Also what does tiling on a grid means???
```
// ONGOING WORK
// TODO
```
## Utilities
Maybe we need some kind of ports
## Vias/layers
Think about layers as some kind of group/scope
Maybe do the cell
```
Layer layer_1 {
...
...
...
#tag(draw_my_fav)
let rec : Rec = ...
draw(layer_1, rec)
}
Layer layer_2 {
...
...
...
}
draw layer_1 layer_2
// or
draw layer_1
draw layer_2
```
We need these information for gds format
```rust
// Required fields
/// Library name.
pub name: ArcStr,
/// Gds spec version.
pub version: i16,
/// Modification date(s).
pub dates: GdsDateTimes,
/// Spatial units.
pub units: GdsUnits,
/// Struct definitions.
pub structs: Vec<GdsStruct>,
// Unsupported Fields
#[serde(default, skip_serializing)]
#[builder(default)]
pub libdirsize: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub srfname: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub libsecur: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub reflibs: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub fonts: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub attrtable: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub generations: Unsupported,
#[serde(default, skip_serializing)]
#[builder(default)]
pub format_type: Unsupported,
}
```
Minimal is name and version
## Design Doc
### Lexer & Parser
We'll use logos and chumsky for lexing and parsing.