From 9028424a9629029dfa00e466569bbe6f6fed4fc4 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 21 Dec 2022 15:11:35 -0500 Subject: [PATCH] feat: rename Nil to Unit --- crates/lang/src/builtins.rs | 18 +++++++++--------- crates/lang/src/expr.rs | 4 ++-- crates/lang/src/tipo.rs | 14 +++++++------- crates/lang/src/uplc.rs | 8 ++++---- examples/acceptance_tests/019/lib/test.ak | 2 +- examples/acceptance_tests/025/lib/test.ak | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/lang/src/builtins.rs b/crates/lang/src/builtins.rs index 13ae64fa..9d7fc0f0 100644 --- a/crates/lang/src/builtins.rs +++ b/crates/lang/src/builtins.rs @@ -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::, 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 { }) } -pub fn nil() -> Arc { +pub fn unit() -> Arc { Arc::new(Type::App { args: vec![], public: true, - name: NIL.to_string(), + name: UNIT.to_string(), module: "".to_string(), }) } diff --git a/crates/lang/src/expr.rs b/crates/lang/src/expr.rs index d57c8e46..1ea26268 100644 --- a/crates/lang/src/expr.rs +++ b/crates/lang/src/expr.rs @@ -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) } } } diff --git a/crates/lang/src/tipo.rs b/crates/lang/src/tipo.rs index 493cd468..217247be 100644 --- a/crates/lang/src/tipo.rs +++ b/crates/lang/src/tipo.rs @@ -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, diff --git a/crates/lang/src/uplc.rs b/crates/lang/src/uplc.rs index bb095575..aa1c6a16 100644 --- a/crates/lang/src/uplc.rs +++ b/crates/lang/src/uplc.rs @@ -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(), diff --git a/examples/acceptance_tests/019/lib/test.ak b/examples/acceptance_tests/019/lib/test.ak index c6c876c4..28b2789a 100644 --- a/examples/acceptance_tests/019/lib/test.ak +++ b/examples/acceptance_tests/019/lib/test.ak @@ -10,5 +10,5 @@ test map_1() { } test map_2() { - map(None, fn(_) { Nil }) == None + map(None, fn(_) { Unit }) == None } diff --git a/examples/acceptance_tests/025/lib/test.ak b/examples/acceptance_tests/025/lib/test.ak index 3f5d0828..70c2523f 100644 --- a/examples/acceptance_tests/025/lib/test.ak +++ b/examples/acceptance_tests/025/lib/test.ak @@ -2,5 +2,5 @@ // Should != be false or true? test nil_1() { - Nil == Nil + Unit == Unit }