Skip to content

Commit 0ddf05f

Browse files
committed
wip: work on supporting dynamic typing
1 parent ac25e9e commit 0ddf05f

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

core/compiler/src/compile.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ pub enum Ty {
477477
/// Suppresses type checking of dependent properties.
478478
#[default]
479479
Unknown,
480+
/// Catch-all any type.
481+
///
482+
/// Should eventually be removed.
483+
Any,
480484
Bool,
481485
Float,
482486
Int,
@@ -498,6 +502,7 @@ impl Ty {
498502
match name {
499503
"Float" => Some(Ty::Float),
500504
"Rect" => Some(Ty::Rect),
505+
"Any" => Some(Ty::Any),
501506
"Int" => Some(Ty::Int),
502507
"String" => Some(Ty::String),
503508
"()" => Some(Ty::Nil),
@@ -728,7 +733,7 @@ impl<'a> VarIdTyPass<'a> {
728733
}
729734

730735
fn assert_eq_ty(&mut self, span: cfgrammar::Span, found: &Ty, expected: &Ty) {
731-
if *found != *expected {
736+
if *found != *expected && !(*found == Ty::Any || *expected == Ty::Any) {
732737
self.errors.push(StaticError {
733738
span: self.span(span),
734739
kind: StaticErrorKind::IncorrectTy {
@@ -740,7 +745,7 @@ impl<'a> VarIdTyPass<'a> {
740745
}
741746

742747
fn assert_ty_is_cell(&mut self, span: cfgrammar::Span, ty: &Ty) {
743-
if !matches!(ty, Ty::Cell(_)) {
748+
if !matches!(ty, Ty::Cell(_) | Ty::Any) {
744749
self.errors.push(StaticError {
745750
span: self.span(span),
746751
kind: StaticErrorKind::IncorrectTyCategory {
@@ -752,7 +757,7 @@ impl<'a> VarIdTyPass<'a> {
752757
}
753758

754759
fn assert_ty_is_enum(&mut self, span: cfgrammar::Span, ty: &Ty) {
755-
if !matches!(ty, Ty::Enum(_)) {
760+
if !matches!(ty, Ty::Enum(_) | Ty::Any) {
756761
self.errors.push(StaticError {
757762
span: self.span(span),
758763
kind: StaticErrorKind::IncorrectTyCategory {

core/compiler/src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod tests {
1919
use approx::assert_relative_eq;
2020
use const_format::concatcp;
2121

22-
use crate::compile::{compile, CellArg, CompileInput};
22+
use crate::compile::{CellArg, CompileInput, compile};
2323
const EPSILON: f64 = 1e-10;
2424

2525
const EXAMPLES_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../examples");
@@ -55,6 +55,7 @@ mod tests {
5555
const ARGON_WORKSPACE: &str = concatcp!(EXAMPLES_DIR, "/argon_workspace/lib.ar");
5656
const ARGON_EXTERNAL_MODS: &str = concatcp!(EXAMPLES_DIR, "/external_mods/main_crate/lib.ar");
5757
const ARGON_TEXT: &str = concatcp!(EXAMPLES_DIR, "/text/lib.ar");
58+
const ARGON_ANY_TYPE_INST: &str = concatcp!(EXAMPLES_DIR, "/any_type_inst/lib.ar");
5859

5960
#[test]
6061
fn argon_scopes() {
@@ -694,4 +695,24 @@ mod tests {
694695
assert_relative_eq!(t.x, 0., epsilon = EPSILON);
695696
assert_relative_eq!(t.y, 10., epsilon = EPSILON);
696697
}
698+
699+
#[test]
700+
fn argon_any_type_inst() {
701+
let o = parse_workspace_with_std(ARGON_ANY_TYPE_INST);
702+
assert!(o.static_errors().is_empty());
703+
let ast = o.ast();
704+
let cells = compile(
705+
&ast,
706+
CompileInput {
707+
cell: &["top"],
708+
args: Vec::new(),
709+
lyp_file: &PathBuf::from(SKY130_LYP),
710+
},
711+
);
712+
println!("{cells:#?}");
713+
714+
let cells = cells.unwrap_valid();
715+
let cell = &cells.cells[&cells.top];
716+
assert_eq!(cell.objects.len(), 2);
717+
}
697718
}

examples/any_type_inst/lib.ar

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
cell bot() {
3+
let met1 = rect("met1", x0=0., y0=0., x1=100., y1=100.);
4+
}
5+
6+
fn double(cell_: Any) -> [Any] {
7+
let i1 = inst(cell_, x=0., y=0.);
8+
let i2 = inst(cell_, x=200., y=0.);
9+
cons(i1, cons(i2, []))
10+
}
11+
12+
cell top() {
13+
let bot_cell = bot();
14+
double(bot_cell);
15+
}

0 commit comments

Comments
 (0)