-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommon_types.m
More file actions
127 lines (94 loc) · 3.42 KB
/
common_types.m
File metadata and controls
127 lines (94 loc) · 3.42 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
%-----------------------------------------------------------------------%
% vim: ts=4 sw=4 et
%-----------------------------------------------------------------------%
:- module common_types.
%
% Copyright (C) Plasma Team
% Distributed under the terms of the MIT License see ../LICENSE.code
%
% This module defines types useful to multiple Plasma tools.
%
%-----------------------------------------------------------------------%
:- interface.
:- import_module set.
:- import_module util.
:- import_module util.pretty.
% Is a declaration visible outside of its defining module.
%
:- type sharing
---> s_public
; s_private.
% Types and resources have a 3rd option, to export the name but not its
% details.
%
:- type sharing_opaque
---> so_private
; so_public
; so_public_opaque.
% Is an exported function an entrypoint.
%
:- type is_entrypoint
---> is_entrypoint
; not_entrypoint.
% Has a declaration been imported from another module?
%
:- type imported
---> i_local
; i_imported.
% The arity of an expression is the number of results it returns.
%
:- type arity
---> arity(a_num :: int).
% The number of a particular field within a structure. This is 1-based,
% that is the first field is field_num_(1).
%
:- type field_num
---> field_num(field_num_int :: int).
:- func field_num_first = field_num.
:- func field_num_next(field_num) = field_num.
%-----------------------------------------------------------------------%
% A constant in an expression.
%
:- type const_type
---> c_string(string)
; c_number(int)
; c_func(func_id)
; c_ctor(set(ctor_id)).
:- type id_printer(ID) == (func(ID) = pretty).
:- func const_pretty(id_printer(func_id), id_printer(set(ctor_id)),
const_type) = pretty.
%-----------------------------------------------------------------------%
:- type func_id
---> func_id(int).
%-----------------------------------------------------------------------%
:- type type_id
---> type_id(int).
%-----------------------------------------------------------------------%
:- type resource_id
---> resource_id(int).
:- type maybe_resources
---> resources(
r_uses :: set(resource_id),
r_observes :: set(resource_id)
)
; unknown_resources.
%-----------------------------------------------------------------------%
:- type ctor_id
---> ctor_id(int).
%-----------------------------------------------------------------------%
%-----------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module string.
:- import_module util.my_string.
%-----------------------------------------------------------------------%
field_num_first = field_num(1).
field_num_next(field_num(Num)) = field_num(Num + 1).
%-----------------------------------------------------------------------%
const_pretty(_, _, c_number(Int)) = p_str(string(Int)).
const_pretty(_, _, c_string(String)) =
p_str(escape_string(String)).
const_pretty(FuncPretty, _, c_func(FuncId)) = FuncPretty(FuncId).
const_pretty(_, CtorPretty, c_ctor(CtorId)) = CtorPretty(CtorId).
%-----------------------------------------------------------------------%
%-----------------------------------------------------------------------%