feat: rename Nil to Unit
This commit is contained in:
parent
9df5005820
commit
9028424a96
|
@ -18,7 +18,7 @@ pub const BOOL: &str = "Bool";
|
|||
pub const INT: &str = "Int";
|
||||
pub const DATA: &str = "Data";
|
||||
pub const LIST: &str = "List";
|
||||
pub const NIL: &str = "Nil";
|
||||
pub const UNIT: &str = "Unit";
|
||||
pub const RESULT: &str = "Result";
|
||||
pub const STRING: &str = "String";
|
||||
pub const OPTION: &str = "Option";
|
||||
|
@ -144,14 +144,14 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
|||
},
|
||||
);
|
||||
|
||||
// Nil
|
||||
// Unit
|
||||
prelude.values.insert(
|
||||
NIL.to_string(),
|
||||
UNIT.to_string(),
|
||||
ValueConstructor::public(
|
||||
nil(),
|
||||
unit(),
|
||||
ValueConstructorVariant::Record {
|
||||
module: "".into(),
|
||||
name: NIL.to_string(),
|
||||
name: UNIT.to_string(),
|
||||
arity: 0,
|
||||
field_map: None::<FieldMap>,
|
||||
location: Span::empty(),
|
||||
|
@ -161,11 +161,11 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
|
|||
);
|
||||
|
||||
prelude.types.insert(
|
||||
NIL.to_string(),
|
||||
UNIT.to_string(),
|
||||
TypeConstructor {
|
||||
location: Span::empty(),
|
||||
parameters: vec![],
|
||||
tipo: nil(),
|
||||
tipo: unit(),
|
||||
module: "".to_string(),
|
||||
public: true,
|
||||
},
|
||||
|
@ -477,11 +477,11 @@ pub fn string() -> Arc<Type> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn nil() -> Arc<Type> {
|
||||
pub fn unit() -> Arc<Type> {
|
||||
Arc::new(Type::App {
|
||||
args: vec![],
|
||||
public: true,
|
||||
name: NIL.to_string(),
|
||||
name: UNIT.to_string(),
|
||||
module: "".to_string(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
Annotation, Arg, AssignmentKind, BinOp, CallArg, Clause, DefinitionLocation, IfBranch,
|
||||
Pattern, RecordUpdateSpread, Span, TodoKind, TypedRecordUpdateArg, UntypedRecordUpdateArg,
|
||||
},
|
||||
builtins::{bool, nil},
|
||||
builtins::{bool, unit},
|
||||
tipo::{ModuleValueConstructor, PatternConstructor, Type, ValueConstructor},
|
||||
};
|
||||
|
||||
|
@ -183,7 +183,7 @@ impl TypedExpr {
|
|||
| Self::RecordAccess { tipo, .. }
|
||||
| Self::RecordUpdate { tipo, .. } => tipo.clone(),
|
||||
Self::Pipeline { expressions, .. } | Self::Sequence { expressions, .. } => {
|
||||
expressions.last().map(TypedExpr::tipo).unwrap_or_else(nil)
|
||||
expressions.last().map(TypedExpr::tipo).unwrap_or_else(unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,10 +87,10 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_nil(&self) -> bool {
|
||||
pub fn is_unit(&self) -> bool {
|
||||
match self {
|
||||
Self::App { module, name, .. } if "Nil" == name && module.is_empty() => true,
|
||||
Self::Var { tipo } => tipo.borrow().is_nil(),
|
||||
Self::App { module, name, .. } if "Unit" == name && module.is_empty() => true,
|
||||
Self::Var { tipo } => tipo.borrow().is_unit(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -400,9 +400,9 @@ impl TypeVar {
|
|||
matches!(self, Self::Unbound { .. })
|
||||
}
|
||||
|
||||
pub fn is_nil(&self) -> bool {
|
||||
pub fn is_unit(&self) -> bool {
|
||||
match self {
|
||||
Self::Link { tipo } => tipo.is_nil(),
|
||||
Self::Link { tipo } => tipo.is_unit(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -708,10 +708,10 @@ pub enum ModuleValueConstructor {
|
|||
/// point to some other module and function when this is an `external fn`.
|
||||
///
|
||||
/// This function has module "themodule" and name "wibble"
|
||||
/// pub fn wibble() { Nil }
|
||||
/// pub fn wibble() { Unit }
|
||||
///
|
||||
/// This function has module "other" and name "whoop"
|
||||
/// pub external fn wibble() -> Nil =
|
||||
/// pub external fn wibble() -> Unit =
|
||||
/// "other" "whoop"
|
||||
///
|
||||
module: String,
|
||||
|
|
|
@ -2005,7 +2005,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
if constructor.tipo.is_bool() {
|
||||
arg_stack
|
||||
.push(Term::Constant(UplcConstant::Bool(constr_name == "True")));
|
||||
} else if constructor.tipo.is_nil() {
|
||||
} else if constructor.tipo.is_unit() {
|
||||
arg_stack.push(Term::Constant(UplcConstant::Unit));
|
||||
} else {
|
||||
let data_type = self.data_types.get(&data_type_key).unwrap();
|
||||
|
@ -2612,7 +2612,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
};
|
||||
arg_stack.push(term);
|
||||
return;
|
||||
} else if tipo.is_nil() {
|
||||
} else if tipo.is_unit() {
|
||||
arg_stack.push(Term::Constant(UplcConstant::Bool(true)));
|
||||
return;
|
||||
}
|
||||
|
@ -2762,7 +2762,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
|
||||
arg_stack.push(term);
|
||||
return;
|
||||
} else if tipo.is_nil() {
|
||||
} else if tipo.is_unit() {
|
||||
arg_stack.push(Term::Constant(UplcConstant::Bool(false)));
|
||||
return;
|
||||
}
|
||||
|
@ -3712,7 +3712,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
let term = Term::Apply {
|
||||
function: Term::Apply {
|
||||
function: Term::Builtin(DefaultFunction::Trace).force_wrap().into(),
|
||||
argument: Term::Constant(uplc::ast::Constant::String(
|
||||
argument: Term::Constant(UplcConstant::String(
|
||||
text.unwrap_or_else(|| "aike::trace".to_string()),
|
||||
))
|
||||
.into(),
|
||||
|
|
|
@ -10,5 +10,5 @@ test map_1() {
|
|||
}
|
||||
|
||||
test map_2() {
|
||||
map(None, fn(_) { Nil }) == None
|
||||
map(None, fn(_) { Unit }) == None
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Should != be false or true?
|
||||
|
||||
test nil_1() {
|
||||
Nil == Nil
|
||||
Unit == Unit
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue