Add ArrayLength expression

This commit is contained in:
Dzmitry Malyshau authored and Dzmitry Malyshau committed 2020-09-16 09:29:26 -04:00
1 parent bcd3db2dad
commit 74c4a3ce18
4 files changed
+13

No files matched your search

+4
View File
@@ -1042,6 +1042,10 @@ fn write_expression<'a, 'b>(
.join(","),
))
}
Expression::ArrayLength(expr) => {
let base = write_expression(&builder.expressions[expr], module, builder)?;
Cow::Owned(format!("uint({}.length())", base))
}
})
}
+2
View File
@@ -635,6 +635,8 @@ pub enum Expression {
origin: FunctionOrigin,
arguments: Vec<Handle<Expression>>,
},
/// Get dynamic array length.
ArrayLength(Handle<Expression>),
}
/// A code block is just a vector of statements.
+3
View File
@@ -100,6 +100,9 @@ where
self.traverse_expr(argument);
}
}
E::ArrayLength(expr) => {
self.traverse_expr(expr);
}
}
}
+4
View File
@@ -262,6 +262,10 @@ impl Typifier {
.ok_or(ResolveError::FunctionReturnsVoid)?;
Resolution::Handle(ty)
}
crate::Expression::ArrayLength(_) => Resolution::Value(crate::TypeInner::Scalar {
kind: crate::ScalarKind::Uint,
width: 4,
}),
})
}