feat: allow functions from prelude
Co-authored-by: rvcas <x@rvcas.dev>
This commit is contained in:
parent
e495eefb34
commit
67e4ff8317
|
@ -505,7 +505,7 @@ pub fn prelude_functions() -> HashMap<FunctionAccessKey, TypedFunction> {
|
|||
body: TypedExpr::UnOp {
|
||||
location: Span::empty(),
|
||||
tipo: bool(),
|
||||
op: UnOp::Negate,
|
||||
op: UnOp::Not,
|
||||
value: Box::new(TypedExpr::Var {
|
||||
location: Span::empty(),
|
||||
constructor: ValueConstructor {
|
||||
|
|
|
@ -45,8 +45,6 @@ pub struct CodeGenerator<'a> {
|
|||
functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>,
|
||||
// type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
|
||||
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>,
|
||||
id_gen: IdGenerator,
|
||||
needs_field_access: bool,
|
||||
|
@ -58,8 +56,6 @@ impl<'a> CodeGenerator<'a> {
|
|||
functions: &'a HashMap<FunctionAccessKey, &'a TypedFunction>,
|
||||
// type_aliases: &'a HashMap<(String, String), &'a TypeAlias<Arc<tipo::Type>>>,
|
||||
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>,
|
||||
) -> Self {
|
||||
CodeGenerator {
|
||||
|
@ -67,8 +63,6 @@ impl<'a> CodeGenerator<'a> {
|
|||
functions,
|
||||
// type_aliases,
|
||||
data_types,
|
||||
// imports,
|
||||
// constants,
|
||||
module_types,
|
||||
id_gen: IdGenerator::new(),
|
||||
needs_field_access: false,
|
||||
|
@ -525,14 +519,13 @@ impl<'a> CodeGenerator<'a> {
|
|||
self.build_ir(then, ir_stack, scope);
|
||||
}
|
||||
|
||||
TypedExpr::TupleIndex {
|
||||
tipo, index, tuple, ..
|
||||
} => {
|
||||
TypedExpr::TupleIndex { index, tuple, .. } => {
|
||||
ir_stack.push(Air::TupleIndex {
|
||||
scope: scope.clone(),
|
||||
tipo: tuple.tipo(),
|
||||
index: *index,
|
||||
});
|
||||
|
||||
self.build_ir(tuple, ir_stack, scope);
|
||||
}
|
||||
|
||||
|
@ -2337,7 +2330,9 @@ impl<'a> CodeGenerator<'a> {
|
|||
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}")
|
||||
} else {
|
||||
|
|
|
@ -483,8 +483,6 @@ where
|
|||
let mut functions = HashMap::new();
|
||||
let mut type_aliases = HashMap::new();
|
||||
let mut data_types = HashMap::new();
|
||||
let mut imports = HashMap::new();
|
||||
let mut constants = HashMap::new();
|
||||
|
||||
let prelude_functions = builtins::prelude_functions();
|
||||
for (access_key, func) in prelude_functions.iter() {
|
||||
|
@ -513,7 +511,6 @@ where
|
|||
func,
|
||||
);
|
||||
}
|
||||
Definition::Test(_) => {}
|
||||
Definition::TypeAlias(ta) => {
|
||||
type_aliases.insert((module.name.clone(), ta.alias.clone()), ta);
|
||||
}
|
||||
|
@ -526,12 +523,8 @@ where
|
|||
dt,
|
||||
);
|
||||
}
|
||||
Definition::Use(import) => {
|
||||
imports.insert((module.name.clone(), import.module.join("/")), import);
|
||||
}
|
||||
Definition::ModuleConstant(mc) => {
|
||||
constants.insert((module.name.clone(), mc.name.clone()), mc);
|
||||
}
|
||||
|
||||
Definition::ModuleConstant(_) | Definition::Test(_) | Definition::Use(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -548,8 +541,6 @@ where
|
|||
&functions,
|
||||
// &type_aliases,
|
||||
&data_types,
|
||||
// &imports,
|
||||
// &constants,
|
||||
&self.module_types,
|
||||
);
|
||||
|
||||
|
@ -583,8 +574,6 @@ where
|
|||
let mut functions = HashMap::new();
|
||||
let mut type_aliases = HashMap::new();
|
||||
let mut data_types = HashMap::new();
|
||||
let mut imports = HashMap::new();
|
||||
let mut constants = HashMap::new();
|
||||
|
||||
let prelude_functions = builtins::prelude_functions();
|
||||
for (access_key, func) in prelude_functions.iter() {
|
||||
|
@ -637,12 +626,7 @@ where
|
|||
dt,
|
||||
);
|
||||
}
|
||||
Definition::Use(import) => {
|
||||
imports.insert((module.name.clone(), import.module.join("/")), import);
|
||||
}
|
||||
Definition::ModuleConstant(mc) => {
|
||||
constants.insert((module.name.clone(), mc.name.clone()), mc);
|
||||
}
|
||||
Definition::Use(_) | Definition::ModuleConstant(_) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -666,8 +650,6 @@ where
|
|||
&functions,
|
||||
// &type_aliases,
|
||||
&data_types,
|
||||
// &imports,
|
||||
// &constants,
|
||||
&self.module_types,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue