graphix_compiler/node/
genn.rs1use super::{bind::Ref, callsite::CallSite, Constant, Nop, NOP};
2use crate::{
3 expr::{ExprId, ModPath},
4 typ::{FnType, Type},
5 BindId, ExecCtx, Node, Rt, Scope, UserEvent,
6};
7use netidx::publisher::{Typ, Value};
8use poolshark::local::LPooled;
9use std::collections::HashMap;
10
11pub fn nop<R: Rt, E: UserEvent>(typ: Type) -> Node<R, E> {
13 Nop::new(typ)
14}
15
16pub fn bind<R: Rt, E: UserEvent>(
18 ctx: &mut ExecCtx<R, E>,
19 scope: &ModPath,
20 name: &str,
21 typ: Type,
22 top_id: ExprId,
23) -> (BindId, Node<R, E>) {
24 let id = ctx.env.bind_variable(scope, name, typ.clone()).id;
25 ctx.rt.ref_var(id, top_id);
26 (id, Box::new(Ref { spec: NOP.clone(), typ, id, top_id }))
27}
28
29pub fn reference<R: Rt, E: UserEvent>(
31 ctx: &mut ExecCtx<R, E>,
32 id: BindId,
33 typ: Type,
34 top_id: ExprId,
35) -> Node<R, E> {
36 ctx.rt.ref_var(id, top_id);
37 Box::new(Ref { spec: NOP.clone(), typ, id, top_id })
38}
39
40pub fn constant<R: Rt, E: UserEvent>(v: Value) -> Node<R, E> {
41 Box::new(Constant {
42 spec: NOP.clone(),
43 typ: Type::Primitive(Typ::get(&v).into()),
44 value: v,
45 })
46}
47
48pub fn apply<R: Rt, E: UserEvent>(
50 fnode: Node<R, E>,
51 scope: Scope,
52 args: Vec<Node<R, E>>,
53 typ: &FnType,
54 top_id: ExprId,
55) -> Node<R, E> {
56 let ftype = typ.reset_tvars();
57 ftype.alias_tvars(&mut LPooled::take());
58 Box::new(CallSite {
59 spec: NOP.clone(),
60 ftype,
61 args,
62 scope,
63 arg_spec: HashMap::default(),
64 fnode,
65 function: None,
66 top_id,
67 })
68}