-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyType.h
More file actions
77 lines (68 loc) · 2.09 KB
/
PyType.h
File metadata and controls
77 lines (68 loc) · 2.09 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* File: PyType.h
* Author: Kent D. Lee
* (c) 2013
* Created on February 12, 2013, 10:58 PM
*
* License:
* Please read the LICENSE file in this distribution for details regarding
* the licensing of this code. This code is freely available for educational
* use. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
*
* Description:
* Most of the types in CoCo are instances of this class. The exceptions are
* range objects and exception objects. All other types of objects share a
* common behavior and are instances of PyType. The main.cpp file contains
* the code that creates the type instances. There is one instance of each
* different type of CoCo value. For instance, there is one instance of PyType
* for all PyInt objects. All PyInt objects, when their type is requested (via
* the type function) return the one instance of the PyInt type. This is found
* by looking up the instance in the PyTypes map that is declared at the
* bottom of this header file. The main.cpp code initializes this map.
*/
#ifndef PYTYPE_H
#define PYTYPE_H
#include "PyCallable.h"
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
enum PyTypeId {
PyTypeType,
PyNoneType,
PyBoolType,
PyIntType,
PyFloatType,
PyStrType,
PyFunctionType,
PyBuiltInType,
PyRangeTypeId,
PyRangeIteratorType,
PyListType,
PyListIteratorType,
PyFunListType,
PyFunListIteratorType,
PyStrIteratorType,
PyCodeType,
PyTupleType,
PyTupleIteratorType,
PyCellType,
PyExceptionTypeId
};
class PyType : public PyCallable {
public:
PyType(string typeString, PyTypeId id);
virtual ~PyType();
string toString();
PyType* getType();
PyTypeId typeId();
string callName();
protected:
string typeString;
PyTypeId index;
virtual PyObject* __call__(vector<PyObject*>* args);
virtual PyObject* __str__(vector<PyObject*>* args);
virtual PyObject* __type__(vector<PyObject*>* args);
};
extern unordered_map<PyTypeId, PyType*, std::hash<int> > PyTypes;
#endif /* PYTYPE_H */