fix: expect_type now works on recursice constructors and validator args are now handled by air

This commit is contained in:
Kasey White
2023-04-06 00:44:03 -04:00
committed by Kasey
parent a1b3ae52d8
commit bc7b07c1d9
3 changed files with 181 additions and 95 deletions

View File

@@ -3,7 +3,7 @@ use std::sync::Arc;
use uplc::builtins::DefaultFunction;
use crate::{
ast::{BinOp, UnOp},
ast::{Arg, BinOp, UnOp},
tipo::{Type, ValueConstructor},
};
@@ -213,8 +213,9 @@ pub enum Air {
scope: Scope,
tipo: Arc<Type>,
},
Noop {
Validator {
scope: Scope,
params: Vec<Arg<Arc<Type>>>,
},
FieldsEmpty {
scope: Scope,
@@ -263,7 +264,7 @@ impl Air {
| Air::TupleIndex { scope, .. }
| Air::ErrorTerm { scope, .. }
| Air::Trace { scope, .. }
| Air::Noop { scope } => scope.clone(),
| Air::Validator { scope, .. } => scope.clone(),
}
}
pub fn scope_mut(&mut self) -> &mut Scope {
@@ -307,7 +308,7 @@ impl Air {
| Air::TupleIndex { scope, .. }
| Air::ErrorTerm { scope, .. }
| Air::Trace { scope, .. }
| Air::Noop { scope } => scope,
| Air::Validator { scope, .. } => scope,
}
}
pub fn tipo(&self) -> Option<Arc<Type>> {
@@ -398,7 +399,7 @@ impl Air {
| Air::Finally { .. }
| Air::FieldsExpose { .. }
| Air::FieldsEmpty { .. }
| Air::Noop { .. } => None,
| Air::Validator { .. } => None,
Air::UnOp { op, .. } => match op {
UnOp::Not => Some(
Type::App {

View File

@@ -1,10 +1,11 @@
use std::{rc::Rc, sync::Arc};
use indexmap::IndexSet;
use uplc::{builder::EXPECT_ON_LIST, builtins::DefaultFunction};
use crate::{
ast::Span,
ast::{Arg, Span},
builtins::{data, list, void},
tipo::{Type, ValueConstructor, ValueConstructorVariant},
IdGenerator,
@@ -681,30 +682,31 @@ impl AirStack {
pub fn define_func(
&mut self,
func_name: String,
module_name: String,
variant_name: String,
func_name: impl ToString,
module_name: impl ToString,
variant_name: impl ToString,
params: Vec<String>,
recursive: bool,
body_stack: AirStack,
) {
self.air.push(Air::DefineFunc {
scope: self.scope.clone(),
func_name,
module_name,
func_name: func_name.to_string(),
module_name: module_name.to_string(),
params,
recursive,
variant_name,
variant_name: variant_name.to_string(),
});
self.merge_child(body_stack);
}
pub fn noop(&mut self) {
pub fn validator(&mut self, params: Vec<Arg<Arc<Type>>>) {
self.new_scope();
self.air.push(Air::Noop {
self.air.push(Air::Validator {
scope: self.scope.clone(),
params,
});
}
@@ -752,13 +754,7 @@ impl AirStack {
void_stack.void();
void_stack.void();
self.list_clause(
void(),
"__list_to_check",
None,
false,
void_stack,
);
self.list_clause(void(), "__list_to_check", None, false, void_stack);
self.choose_unit(check_with_stack);