feat: allow functions from prelude

Co-authored-by: rvcas <x@rvcas.dev>
This commit is contained in:
Kasey White 2022-12-30 23:55:20 -05:00 committed by Kasey
parent e495eefb34
commit 67e4ff8317
3 changed files with 9 additions and 32 deletions

View File

@ -505,7 +505,7 @@ pub fn prelude_functions() -> HashMap<FunctionAccessKey, TypedFunction> {
body: TypedExpr::UnOp { body: TypedExpr::UnOp {
location: Span::empty(), location: Span::empty(),
tipo: bool(), tipo: bool(),
op: UnOp::Negate, op: UnOp::Not,
value: Box::new(TypedExpr::Var { value: Box::new(TypedExpr::Var {
location: Span::empty(), location: Span::empty(),
constructor: ValueConstructor { constructor: ValueConstructor {

View File

@ -45,8 +45,6 @@ pub struct CodeGenerator<'a> {
functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>, functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>,
// type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>, // type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
data_types: &'a HashMap<DataTypeKey, &'a TypedDataType>, data_types: &'a HashMap<DataTypeKey, &'a TypedDataType>,
// imports: &'a HashMap<(String, String), &'a Use<String>>,
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
module_types: &'a HashMap<String, TypeInfo>, module_types: &'a HashMap<String, TypeInfo>,
id_gen: IdGenerator, id_gen: IdGenerator,
needs_field_access: bool, needs_field_access: bool,
@ -58,8 +56,6 @@ impl<'a> CodeGenerator<'a> {
functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>, functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>,
// type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>, // type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
data_types: &'a HashMap<DataTypeKey, &'a TypedDataType>, data_types: &'a HashMap<DataTypeKey, &'a TypedDataType>,
// imports: &'a HashMap<(String, String), &'a Use<String>>,
// constants: &'a HashMap<(String, String), &'a ModuleConstant<Arc<tipo::Type>, String>>,
module_types: &'a HashMap<String, TypeInfo>, module_types: &'a HashMap<String, TypeInfo>,
) -> Self { ) -> Self {
CodeGenerator { CodeGenerator {
@ -67,8 +63,6 @@ impl<'a> CodeGenerator<'a> {
functions, functions,
// type_aliases, // type_aliases,
data_types, data_types,
// imports,
// constants,
module_types, module_types,
id_gen: IdGenerator::new(), id_gen: IdGenerator::new(),
needs_field_access: false, needs_field_access: false,
@ -525,14 +519,13 @@ impl<'a> CodeGenerator<'a> {
self.build_ir(then, ir_stack, scope); self.build_ir(then, ir_stack, scope);
} }
TypedExpr::TupleIndex { TypedExpr::TupleIndex { index, tuple, .. } => {
tipo, index, tuple, ..
} => {
ir_stack.push(Air::TupleIndex { ir_stack.push(Air::TupleIndex {
scope: scope.clone(), scope: scope.clone(),
tipo: tuple.tipo(), tipo: tuple.tipo(),
index: *index, index: *index,
}); });
self.build_ir(tuple, ir_stack, scope); self.build_ir(tuple, ir_stack, scope);
} }
@ -2337,7 +2330,9 @@ impl<'a> CodeGenerator<'a> {
module, module,
.. ..
} => { } => {
let name = if *func_name == name || name == format!("{module}_{func_name}") let name = if (*func_name == name
|| name == format!("{module}_{func_name}"))
&& !module.is_empty()
{ {
format!("{module}_{func_name}{variant_name}") format!("{module}_{func_name}{variant_name}")
} else { } else {

View File

@ -483,8 +483,6 @@ where
let mut functions = HashMap::new(); let mut functions = HashMap::new();
let mut type_aliases = HashMap::new(); let mut type_aliases = HashMap::new();
let mut data_types = HashMap::new(); let mut data_types = HashMap::new();
let mut imports = HashMap::new();
let mut constants = HashMap::new();
let prelude_functions = builtins::prelude_functions(); let prelude_functions = builtins::prelude_functions();
for (access_key, func) in prelude_functions.iter() { for (access_key, func) in prelude_functions.iter() {
@ -513,7 +511,6 @@ where
func, func,
); );
} }
Definition::Test(_) => {}
Definition::TypeAlias(ta) => { Definition::TypeAlias(ta) => {
type_aliases.insert((module.name.clone(), ta.alias.clone()), ta); type_aliases.insert((module.name.clone(), ta.alias.clone()), ta);
} }
@ -526,12 +523,8 @@ where
dt, dt,
); );
} }
Definition::Use(import) => {
imports.insert((module.name.clone(), import.module.join("/")), import); Definition::ModuleConstant(_) | Definition::Test(_) | Definition::Use(_) => {}
}
Definition::ModuleConstant(mc) => {
constants.insert((module.name.clone(), mc.name.clone()), mc);
}
} }
} }
} }
@ -548,8 +541,6 @@ where
&functions, &functions,
// &type_aliases, // &type_aliases,
&data_types, &data_types,
// &imports,
// &constants,
&self.module_types, &self.module_types,
); );
@ -583,8 +574,6 @@ where
let mut functions = HashMap::new(); let mut functions = HashMap::new();
let mut type_aliases = HashMap::new(); let mut type_aliases = HashMap::new();
let mut data_types = HashMap::new(); let mut data_types = HashMap::new();
let mut imports = HashMap::new();
let mut constants = HashMap::new();
let prelude_functions = builtins::prelude_functions(); let prelude_functions = builtins::prelude_functions();
for (access_key, func) in prelude_functions.iter() { for (access_key, func) in prelude_functions.iter() {
@ -637,12 +626,7 @@ where
dt, dt,
); );
} }
Definition::Use(import) => { Definition::Use(_) | Definition::ModuleConstant(_) => (),
imports.insert((module.name.clone(), import.module.join("/")), import);
}
Definition::ModuleConstant(mc) => {
constants.insert((module.name.clone(), mc.name.clone()), mc);
}
} }
} }
} }
@ -666,8 +650,6 @@ where
&functions, &functions,
// &type_aliases, // &type_aliases,
&data_types, &data_types,
// &imports,
// &constants,
&self.module_types, &self.module_types,
); );