Skip to content

Commit c886d36

Browse files
authored
Merge branch 'main' into eigen
2 parents 4ed432e + bbb74be commit c886d36

File tree

6 files changed

+196
-102
lines changed

6 files changed

+196
-102
lines changed

core/compiler/src/compile.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,17 @@ impl<'a> VarIdTyPass<'a> {
753753
}
754754

755755
fn assert_eq_ty(&mut self, span: cfgrammar::Span, found: &Ty, expected: &Ty) {
756-
if *found != *expected && !(*found == Ty::Any || *expected == Ty::Any) {
756+
if *found == Ty::Any || *expected == Ty::Any {
757+
return;
758+
}
759+
760+
if let Ty::Seq(found) = found
761+
&& let Ty::Seq(expected) = expected
762+
{
763+
return self.assert_eq_ty(span, found, expected);
764+
}
765+
766+
if *found != *expected {
757767
self.errors.push(StaticError {
758768
span: self.span(span),
759769
kind: StaticErrorKind::IncorrectTy {
@@ -1620,10 +1630,10 @@ impl<'a> AstTransformer for VarIdTyPass<'a> {
16201630
);
16211631
if let Some(ty) = args.posargs.first() {
16221632
self.assert_ty_is_cell(ty.span(), &ty.ty());
1623-
if let Ty::Cell(c) = ty.ty() {
1624-
(None, Ty::Inst(c.clone()))
1625-
} else {
1626-
(None, Ty::Unknown)
1633+
match ty.ty() {
1634+
Ty::Cell(c) => (None, Ty::Inst(c.clone())),
1635+
Ty::Any => (None, Ty::Any),
1636+
_ => (None, Ty::Unknown),
16271637
}
16281638
} else {
16291639
(None, Ty::Unknown)
@@ -3871,7 +3881,22 @@ impl<'a> ExecPass<'a> {
38713881
let cell = &self.compiled_cells[&inst_cell_id];
38723882
let state = self.cell_states.get_mut(&cell_id).unwrap();
38733883
let obj_id = &mut self.next_id;
3874-
Some(Value::from_array(cell.field(field).unwrap().map(
3884+
let field_value =
3885+
if let Some(field_value) = cell.field(field) {
3886+
field_value
3887+
} else {
3888+
self.errors.push(ExecError {
3889+
span: Some(self.span(
3890+
&vref.loc,
3891+
field_access_expr.expr.span,
3892+
)),
3893+
cell: cell_id,
3894+
// TODO: More descriptive error
3895+
kind: ExecErrorKind::EmptyBbox,
3896+
});
3897+
return Err(());
3898+
};
3899+
Some(Value::from_array(field_value.map(
38753900
&mut move |v| match v {
38763901
SolvedValue::Rect(rect) => {
38773902
let id = object_id(obj_id);

core/compiler/src/gds.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl GdsExporter {
3535
}
3636

3737
fn coord_to_gds(&self, coord: f64) -> i32 {
38-
(coord * 1e-9 / self.lib.units.db_unit()) as i32
38+
(coord * 1e-9 / self.lib.units.db_unit()).round() as i32
3939
}
4040
}
4141

@@ -154,8 +154,8 @@ impl CompiledData {
154154
layer,
155155
xtype: texttype,
156156
} = exporter.map[&text.layer];
157-
let x = text.x as i32;
158-
let y = text.y as i32;
157+
let x = exporter.coord_to_gds(text.x);
158+
let y = exporter.coord_to_gds(text.y);
159159
ocell.elems.push(GdsElement::GdsTextElem(GdsTextElem {
160160
string: ArcStr::from(&text.text),
161161
layer,
@@ -165,7 +165,9 @@ impl CompiledData {
165165
}));
166166
}
167167
SolvedValue::Instance(i) => {
168-
self.cell_to_gds(exporter, i.cell)?;
168+
if exporter.names.name(&i.cell).is_none() {
169+
self.cell_to_gds(exporter, i.cell)?;
170+
}
169171
ocell.elems.push(GdsElement::GdsStructRef(GdsStructRef {
170172
name: exporter.names.name(&i.cell).unwrap().clone(),
171173
xy: GdsPoint::new(exporter.coord_to_gds(i.x), exporter.coord_to_gds(i.y)),

core/compiler/src/std/lib.ar

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,76 @@ fn union(rect1: Rect, rect2: Rect) -> Rect {
3131
}
3232

3333
fn array(r: Rect, n: Int, xpitch: Float, ypitch: Float) -> Rect {
34-
#scope0 if n == 1 {
35-
let first_rect = rect(r.layer);
36-
eq(first_rect.w, r.w);
37-
eq(first_rect.h, r.h);
38-
first_rect
39-
} else {
40-
let subarray = #scope2 array(r, n - 1, xpitch, ypitch);
41-
let first_rect = rect(r.layer);
42-
eq(first_rect.w, r.w);
43-
eq(first_rect.h, r.h);
44-
eq(first_rect.x0 + xpitch, subarray.x0);
45-
eq(first_rect.y0 + ypitch, subarray.y0);
46-
let out_rect = crect();
47-
#scope0 if xpitch > 0. {
48-
eq(out_rect.x0, first_rect.x0);
49-
eq(out_rect.x1, subarray.x1);
50-
} else {
51-
eq(out_rect.x0, subarray.x0);
52-
eq(out_rect.x1, first_rect.x1);
53-
}
54-
#scope1 if ypitch > 0. {
55-
eq(out_rect.y0, first_rect.y0);
56-
eq(out_rect.y1, subarray.y1);
34+
#scope0 if n >= 1 {
35+
#scope0 if n == 1 {
36+
let first_rect = rect(r.layer);
37+
eq(first_rect.w, r.w);
38+
eq(first_rect.h, r.h);
39+
first_rect
5740
} else {
58-
eq(out_rect.y0, subarray.y0);
59-
eq(out_rect.y1, first_rect.y1);
41+
let subarray = #scope2 array(r, n - 1, xpitch, ypitch);
42+
let first_rect = rect(r.layer);
43+
eq(first_rect.w, r.w);
44+
eq(first_rect.h, r.h);
45+
eq(first_rect.x0 + xpitch, subarray.x0);
46+
eq(first_rect.y0 + ypitch, subarray.y0);
47+
let out_rect = crect();
48+
#scope0 if xpitch > 0. {
49+
eq(out_rect.x0, first_rect.x0);
50+
eq(out_rect.x1, subarray.x1);
51+
} else {
52+
eq(out_rect.x0, subarray.x0);
53+
eq(out_rect.x1, first_rect.x1);
54+
}
55+
#scope1 if ypitch > 0. {
56+
eq(out_rect.y0, first_rect.y0);
57+
eq(out_rect.y1, subarray.y1);
58+
} else {
59+
eq(out_rect.y0, subarray.y0);
60+
eq(out_rect.y1, first_rect.y1);
61+
}
62+
out_rect
6063
}
61-
out_rect
64+
} else {
65+
crect(w=0., h=0.)
6266
}
6367
}
6468

6569
fn array2(r: Rect, nx: Int, ny: Int, xpitch: Float, ypitch: Float) -> Rect {
66-
#scope0 if ny == 1 {
67-
#scope0 array(r, nx, xpitch, 0.)
68-
} else {
69-
let subarray = #scope1 array2(r, nx, ny-1, xpitch, ypitch);
70-
let first_rect = #scope2 array(r, nx, xpitch, 0.);
71-
eq(first_rect.x0, subarray.x0);
72-
eq(first_rect.y0 + ypitch, subarray.y0);
73-
let out_rect = crect();
74-
eq(out_rect.x0, first_rect.x0);
75-
eq(out_rect.x1, first_rect.x1);
76-
#scope0 if ypitch > 0. {
77-
eq(out_rect.y0, first_rect.y0);
78-
eq(out_rect.y1, subarray.y1);
70+
#scope0 if nx >= 1 {
71+
#scope0 if ny >= 1 {
72+
#scope0 if ny == 1 {
73+
#scope0 array(r, nx, xpitch, 0.)
74+
} else {
75+
let subarray = #scope1 array2(r, nx, ny-1, xpitch, ypitch);
76+
let first_rect = #scope2 array(r, nx, xpitch, 0.);
77+
eq(first_rect.x0, subarray.x0);
78+
eq(first_rect.y0 + ypitch, subarray.y0);
79+
let out_rect = crect();
80+
eq(out_rect.x0, first_rect.x0);
81+
eq(out_rect.x1, first_rect.x1);
82+
#scope0 if ypitch > 0. {
83+
eq(out_rect.y0, first_rect.y0);
84+
eq(out_rect.y1, subarray.y1);
85+
} else {
86+
eq(out_rect.y0, subarray.y0);
87+
eq(out_rect.y1, first_rect.y1);
88+
}
89+
out_rect
90+
}
7991
} else {
80-
eq(out_rect.y0, subarray.y0);
81-
eq(out_rect.y1, first_rect.y1);
92+
crect(w=0., h=0.)
8293
}
83-
out_rect
94+
} else {
95+
crect(w=0., h=0.)
8496
}
8597
}
8698

8799
fn max_array(r: Rect, w: Float, h: Float, xpitch: Float, ypitch: Float) -> Rect {
88100
let nx = (((w - r.w) / xpitch) as Int + 1);
89101
let ny = (((h - r.h) / ypitch) as Int + 1);
90-
if nx >= 1 {
91-
if ny >= 1 {
102+
#scope0 if nx >= 1 {
103+
#scope0 if ny >= 1 {
92104
#scope0 array2(r, nx, ny, xpitch, ypitch)
93105
} else {
94106
crect(w=0., h=0.)

core/lang-server/src/document.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use arcstr::ArcStr;
2+
use cfgrammar::Span;
23
use lsp_document::{IndexedText, Pos, TextChange, TextMap, apply_change};
34
use tower_lsp_server::lsp_types::{Position, Range};
45

@@ -36,6 +37,13 @@ impl Document {
3637
pos2position(self.contents.offset_to_pos(offset).unwrap())
3738
}
3839

40+
pub(crate) fn span_to_range(&self, span: Span) -> Range {
41+
Range::new(
42+
self.offset_to_pos(span.start()),
43+
self.offset_to_pos(span.end()),
44+
)
45+
}
46+
3947
pub(crate) fn substr(&self, range: std::ops::Range<Position>) -> &str {
4048
self.contents
4149
.substr(position2pos(range.start)..position2pos(range.end))

0 commit comments

Comments
 (0)