intrinsics pr-02

This commit is contained in:
2026-03-24 13:40:45 +00:00
parent eb835bafee
commit 8545c67939
11 changed files with 315 additions and 4 deletions
@@ -180,6 +180,31 @@ impl IntrinsicMeta {
pub const fn key(&self) -> IntrinsicKey {
IntrinsicKey::new(self.owner, self.name, self.version)
}
pub fn arg_slots(&self) -> usize {
self.arg_layout.len()
}
pub fn ret_slots(&self) -> usize {
self.ret_layout.len()
}
pub fn validate_result_values(&self, values: &[Value]) -> Result<(), IntrinsicExecutionError> {
if values.len() != self.ret_slots() {
return Err(IntrinsicExecutionError::ArityMismatch {
expected: self.ret_slots(),
got: values.len(),
});
}
for (index, (value, expected)) in values.iter().zip(self.ret_layout.iter()).enumerate() {
if !value_matches_abi_type(value, *expected) {
return Err(IntrinsicExecutionError::TypeMismatch { index, expected: *expected });
}
}
Ok(())
}
}
const COLOR: BuiltinTypeKey = BuiltinTypeKey::new("color", 1);
@@ -352,6 +377,15 @@ fn expect_float_arg(args: &[Value], index: usize) -> Result<f64, IntrinsicExecut
})
}
fn value_matches_abi_type(value: &Value, expected: AbiType) -> bool {
match expected {
AbiType::Scalar(BuiltinScalarType::Int) => value.as_integer().is_some(),
AbiType::Scalar(BuiltinScalarType::Float) => value.as_float().is_some(),
AbiType::Scalar(BuiltinScalarType::Bool) => matches!(value, Value::Boolean(_)),
AbiType::Builtin(_) => value.as_integer().is_some(),
}
}
fn vec2_dot(args: &[Value]) -> Result<Vec<Value>, IntrinsicExecutionError> {
if args.len() != 4 {
return Err(IntrinsicExecutionError::ArityMismatch { expected: 4, got: args.len() });