1use crate::{semantic::entry::GlobalCx, TermIn};
4use logic_eval::{Name, Term};
5
6use crate::etc::util::IntoPathSegments;
7
8pub(crate) const FUNCTOR_IMPL: &str = "#impl";
10pub(crate) const FUNCTOR_TRAIT: &str = "#trait";
11pub(crate) const FUNCTOR_ASSOC_TY: &str = "#assoc_ty";
12pub(crate) const FUNCTOR_ASSOC_FN: &str = "#assoc_fn";
13pub(crate) const FUNCTOR_INHER_FN: &str = "#inher_fn";
14pub(crate) const FUNCTOR_ASSOC_CONST_TY: &str = "#assoc_const_ty";
15pub(crate) const FUNCTOR_ASSOC_CONST_VAL: &str = "#assoc_const_val";
16pub(crate) const FUNCTOR_INHER_CONST: &str = "#inher_const";
17pub(crate) const FUNCTOR_REF: &str = "#ref";
18pub(crate) const FUNCTOR_MUT: &str = "#mut";
19pub(crate) const FUNCTOR_ARRAY: &str = "#array";
20pub(crate) const FUNCTOR_TUPLE: &str = "#tuple";
21pub(crate) const FUNCTOR_SIG: &str = "#sig";
22pub(crate) const FUNCTOR_INT: &str = "#int";
23pub(crate) const FUNCTOR_FLOAT: &str = "#float";
24pub(crate) const FUNCTOR_UNIT: &str = "#unit";
25pub(crate) const FUNCTOR_LIST: &str = "#list"; pub(crate) const FUNCTOR_ARG: &str = "#arg";
27pub(crate) const FUNCTOR_DYN_ARRAY_LEN: &str = "#dyn";
28
29pub fn impl_1<'gcx>(self_ty: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
40 Term {
41 functor: Name::with_intern(FUNCTOR_IMPL, gcx),
42 args: [self_ty].into(),
43 }
44}
45
46pub fn impl_2<'gcx>(
56 self_ty: TermIn<'gcx>,
57 trait_: TermIn<'gcx>,
58 gcx: &'gcx GlobalCx<'gcx>,
59) -> TermIn<'gcx> {
60 Term {
61 functor: Name::with_intern(FUNCTOR_IMPL, gcx),
62 args: [self_ty, trait_].into(),
63 }
64}
65
66pub fn trait_1<'gcx>(trait_: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
77 Term {
78 functor: Name::with_intern(FUNCTOR_TRAIT, gcx),
79 args: [trait_].into(),
80 }
81}
82
83pub fn assoc_ty_4<'gcx>(
97 self_ty: TermIn<'gcx>,
98 trait_: TermIn<'gcx>,
99 assoc_ty: TermIn<'gcx>,
100 assign_ty: TermIn<'gcx>,
101 gcx: &'gcx GlobalCx<'gcx>,
102) -> TermIn<'gcx> {
103 Term {
104 functor: Name::with_intern(FUNCTOR_ASSOC_TY, gcx),
105 args: [self_ty, trait_, assoc_ty, assign_ty].into(),
106 }
107}
108
109pub fn assoc_fn_3<'gcx>(
122 trait_: TermIn<'gcx>,
123 fn_ident: TermIn<'gcx>,
124 sig: TermIn<'gcx>,
125 gcx: &'gcx GlobalCx<'gcx>,
126) -> TermIn<'gcx> {
127 Term {
128 functor: Name::with_intern(FUNCTOR_ASSOC_FN, gcx),
129 args: [trait_, fn_ident, sig].into(),
130 }
131}
132
133pub fn inher_fn_3<'gcx>(
146 self_ty: TermIn<'gcx>,
147 fn_ident: TermIn<'gcx>,
148 sig: TermIn<'gcx>,
149 gcx: &'gcx GlobalCx<'gcx>,
150) -> TermIn<'gcx> {
151 Term {
152 functor: Name::with_intern(FUNCTOR_INHER_FN, gcx),
153 args: [self_ty, fn_ident, sig].into(),
154 }
155}
156
157pub fn assoc_const_ty_3<'gcx>(
170 trait_: TermIn<'gcx>,
171 const_ident: TermIn<'gcx>,
172 const_ty: TermIn<'gcx>,
173 gcx: &'gcx GlobalCx<'gcx>,
174) -> TermIn<'gcx> {
175 Term {
176 functor: Name::with_intern(FUNCTOR_ASSOC_CONST_TY, gcx),
177 args: [trait_, const_ident, const_ty].into(),
178 }
179}
180
181pub fn assoc_const_val_3<'gcx>(
194 trait_: TermIn<'gcx>,
195 const_ident: TermIn<'gcx>,
196 const_id: TermIn<'gcx>,
197 gcx: &'gcx GlobalCx<'gcx>,
198) -> TermIn<'gcx> {
199 Term {
200 functor: Name::with_intern(FUNCTOR_ASSOC_CONST_VAL, gcx),
201 args: [trait_, const_ident, const_id].into(),
202 }
203}
204
205pub fn assoc_const_val_4<'gcx>(
217 self_ty: TermIn<'gcx>,
218 trait_: TermIn<'gcx>,
219 const_ident: TermIn<'gcx>,
220 const_id: TermIn<'gcx>,
221 gcx: &'gcx GlobalCx<'gcx>,
222) -> TermIn<'gcx> {
223 Term {
224 functor: Name::with_intern(FUNCTOR_ASSOC_CONST_VAL, gcx),
225 args: [self_ty, trait_, const_ident, const_id].into(),
226 }
227}
228
229pub fn inher_const_4<'gcx>(
243 self_ty: TermIn<'gcx>,
244 const_ident: TermIn<'gcx>,
245 const_ty: TermIn<'gcx>,
246 const_id: TermIn<'gcx>,
247 gcx: &'gcx GlobalCx<'gcx>,
248) -> TermIn<'gcx> {
249 Term {
250 functor: Name::with_intern(FUNCTOR_INHER_CONST, gcx),
251 args: [self_ty, const_ident, const_ty, const_id].into(),
252 }
253}
254
255pub fn ref_1<'gcx>(ty: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
266 Term {
267 functor: Name::with_intern(FUNCTOR_REF, gcx),
268 args: [ty].into(),
269 }
270}
271
272pub fn mut_1<'gcx>(ty: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
283 Term {
284 functor: Name::with_intern(FUNCTOR_MUT, gcx),
285 args: [ty].into(),
286 }
287}
288
289pub fn array_1<'gcx>(elem: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
300 let len = Term {
301 functor: Name::with_intern(FUNCTOR_DYN_ARRAY_LEN, gcx),
302 args: [].into(),
303 };
304 Term {
305 functor: Name::with_intern(FUNCTOR_ARRAY, gcx),
306 args: [elem, len].into(),
307 }
308}
309
310pub fn array_2<'gcx>(
320 elem: TermIn<'gcx>,
321 len: TermIn<'gcx>,
322 gcx: &'gcx GlobalCx<'gcx>,
323) -> TermIn<'gcx> {
324 Term {
325 functor: Name::with_intern(FUNCTOR_ARRAY, gcx),
326 args: [elem, len].into(),
327 }
328}
329
330pub fn tuple_n<'gcx>(elems: Vec<TermIn<'gcx>>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
341 Term {
342 functor: Name::with_intern(FUNCTOR_TUPLE, gcx),
343 args: elems,
344 }
345}
346
347pub fn sig_n<'gcx>(args: Vec<TermIn<'gcx>>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
360 Term {
361 functor: Name::with_intern(FUNCTOR_SIG, gcx),
362 args,
363 }
364}
365
366pub fn int_1<'gcx>(int: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
377 Term {
378 functor: Name::with_intern(FUNCTOR_INT, gcx),
379 args: [int].into(),
380 }
381}
382
383pub fn float_1<'gcx>(float: TermIn<'gcx>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
394 Term {
395 functor: Name::with_intern(FUNCTOR_FLOAT, gcx),
396 args: [float].into(),
397 }
398}
399
400pub fn unit_0<'gcx>(gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
406 Term {
407 functor: Name::with_intern(FUNCTOR_UNIT, gcx),
408 args: [].into(),
409 }
410}
411
412pub fn list_n<'gcx>(elems: Vec<TermIn<'gcx>>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
425 Term {
426 functor: Name::with_intern(FUNCTOR_LIST, gcx),
427 args: elems,
428 }
429}
430
431pub fn arg_n<'gcx>(args: Vec<TermIn<'gcx>>, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
446 Term {
447 functor: Name::with_intern(FUNCTOR_ARG, gcx),
448 args,
449 }
450}
451
452pub fn path_to_list<'gcx, T: IntoPathSegments>(path: T, gcx: &'gcx GlobalCx<'gcx>) -> TermIn<'gcx> {
457 let segments = path
458 .segments()
459 .map(|segment| {
460 let empty_arg = arg_n([].into(), gcx);
461 let functor = Name::with_intern(segment.as_ref(), gcx);
462 Term {
463 functor,
464 args: [empty_arg].into(),
465 }
466 })
467 .collect();
468
469 list_n(segments, gcx)
470}