forked from bonetblai/mini-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.h
46 lines (40 loc) · 1.39 KB
/
functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include "types.h"
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <tr1/unordered_set>
typedef int Function;
class FunctionSet : public std::tr1::unordered_set<Function> { };
class FunctionTable
{
std::vector<std::string> names_;
std::map<std::string, Function> functions_;
std::vector<TypeList*> parameters_;
FunctionSet static_functions_;
public:
~FunctionTable();
Function add_function( const std::string& name );
std::pair<Function,bool> find_function( const std::string& name ) const;
Function first_function( void ) const { return( 0 ); }
Function last_function( void ) const { return( names_.size() - 1 ); }
void add_parameter( Function function, Type type)
{
parameters_[function]->push_back( type );
}
const std::string& name( Function function ) const { return( names_[function] ); }
size_t arity( Function function ) const { return( parameters_[function]->size() ); }
Type parameter( Function function, size_t i ) const
{
return( (*parameters_[function])[i] );
}
void make_dynamic( Function function ) { static_functions_.erase( function ); }
bool static_function( Function function ) const
{
return( static_functions_.find( function ) != static_functions_.end() );
}
void print_function( std::ostream& os, Function function ) const;
};
#endif // FUNCTIONS_H