/
boolean.pmc
152 lines (96 loc) · 2.43 KB
/
boolean.pmc
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Copyright (C) 2001-2006, The Perl Foundation.
$Id$
=head1 NAME
src/pmc/boolean.pmc - Boolean PMC
=head1 DESCRIPTION
This class implements a boolean value variable.
Albeit the C<Boolean PMC> is derived from the C<Integer PMC>,
it doesn't morph to other types. Only its value is changed.
=head2 Methods
=over 4
=cut
*/
#include "parrot/parrot.h"
pmclass Boolean extends Integer does boolean does scalar {
/*
=item C<class_init()>
Define 2 pythonic globals C<True>, C<False>.
XXX are these generally useful or should they be moved to src/py_func.c?
=cut
*/
void class_init() {
if (pass) {
PMC *t;
STRING *s;
t = pmc_new(INTERP, enum_class_Boolean);
PMC_int_val(t) = 1;
s = CONST_STRING(INTERP, "True");
Parrot_store_global_cur(INTERP, s, t);
t = pmc_new(INTERP, enum_class_Boolean);
s = CONST_STRING(INTERP, "False");
Parrot_store_global_cur(INTERP, s, t);
}
}
/*
=item C<PMC* instantiate(PMC* sig)>
Object constructor. SELF is a Boolean Class object. Return a new
C<bool> object according to the passed PMC value.
=cut
*/
PMC* instantiate(PMC* sig) {
/* XXX other types */
const int argcP = REG_INT(3);
PMC * const res = pmc_new(interp, enum_class_Boolean);
if (argcP)
PMC_int_val(res) = VTABLE_get_bool(interp, REG_PMC(5));
return PMCNULL; /* TODO */
return res;
}
/*
=item C<STRING* get_string()>
Return "1" or "0".
=cut
*/
STRING* get_string() {
return SUPER();
}
/*
=item C<void set_integer_native(INTVAL value)>
=item C<void set_bool(INTVAL value)>
=item C<void set_pmc(PMC* value)>
=cut
*/
void set_integer_native(INTVAL value) {
PMC_int_val(SELF) = (value != 0);
}
void set_bool(INTVAL value) {
PMC_int_val(SELF) = (value != 0);
}
/*
=item C<void set_number_native(FLOATVAL value)>
Sets the value to C<value> evaluated in a boolean context.
=cut
*/
void set_number_native(FLOATVAL value) {
PMC_int_val(SELF) = (value!=0);
}
/*
=item C<void set_string_native(STRING* value)>
Sets the value to C<*value> evaluated in a boolean context.
=cut
*/
void set_string_native(STRING* value) {
PMC_int_val(SELF) = string_bool(INTERP, value);
}
}
/*
=back
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/