fetish_lib/
term_application.rs1use crate::term_pointer::*;
2use crate::context::*;
3use crate::term_reference::*;
4use crate::type_id::*;
5use std::cmp::*;
6use std::fmt::*;
7use std::hash::*;
8use crate::interpreter_state::*;
9use crate::displayable_with_state::*;
10
11#[derive(Clone, PartialEq, Hash, Eq)]
14pub struct TermApplication {
15 pub func_ptr : TermPointer,
16 pub arg_ref : TermReference
17}
18
19impl TermApplication {
20 pub fn get_arg_type(&self, ctxt : &Context) -> TypeId {
22 let (arg_type, _) = self.get_func_type_pair(ctxt);
23 arg_type
24 }
25
26 pub fn get_ret_type(&self, ctxt : &Context) -> TypeId {
28 let (_, ret_type) = self.get_func_type_pair(ctxt);
29 ret_type
30 }
31
32 pub fn get_func_type(&self) -> TypeId {
34 self.func_ptr.type_id
35 }
36
37 fn get_func_type_pair(&self, ctxt : &Context) -> (TypeId, TypeId) {
39 let func_id : TypeId = self.get_func_type();
40 let func_type : Type = ctxt.get_type(func_id);
41 if let Type::FuncType(arg_id, ret_id) = func_type {
42 (arg_id, ret_id)
43 } else {
44 panic!();
45 }
46 }
47}
48
49impl DisplayableWithState for TermApplication {
50 fn display(&self, state : &InterpreterState) -> String {
51 format!("{} {}", self.func_ptr.display(state), self.arg_ref.display(state))
52 }
53}