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