Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / share / swig / 1.3.26 / ruby / rubyprimtypes.swg
CommitLineData
920dae64
AT
1/* ------------------------------------------------------------
2 * Primitive Types
3 * ------------------------------------------------------------ */
4
5/* --- Input Values --- */
6
7%typemap(in) int "$1 = NUM2INT($input);";
8%typemap(in) unsigned int "$1 = NUM2UINT($input);";
9%typemap(in) short "$1 = NUM2SHRT($input);";
10%typemap(in) unsigned short "$1 = NUM2USHRT($input);";
11%typemap(in) long "$1 = NUM2LONG($input);";
12%typemap(in) unsigned long "$1 = NUM2ULONG($input);";
13%typemap(in) signed char "$1 = ($1_ltype) NUM2INT($input);";
14%typemap(in) unsigned char "$1 = ($1_ltype) NUM2INT($input);";
15%typemap(in) char "$1 = NUM2CHR($input);";
16%typemap(in) float, double "$1 = ($1_ltype) NUM2DBL($input);";
17%typemap(in) bool "$1 = RTEST($input);";
18
19/* Long long */
20
21%typemap(in) long long "$1 = ($1_ltype) NUM2LL($input);";
22%typemap(in) unsigned long long "$1 = ($1_ltype) NUM2ULL($input);";
23
24/* Const primitive references. Passed by value */
25
26%typemap(in) const int & (int temp),
27 const signed char & (signed char temp),
28 const unsigned char & (unsigned char temp)
29 "temp = ($*1_ltype) NUM2INT($input);
30 $1 = &temp;";
31
32%typemap(in) const short & (short temp)
33 "temp = ($*1_ltype) NUM2SHRT($input);
34 $1 = &temp;";
35
36%typemap(in) const long & (long temp)
37 "temp = ($*1_ltype) NUM2LONG($input);
38 $1 = &temp;";
39
40%typemap(in) const unsigned int & (unsigned int temp)
41 "temp = ($*1_ltype) NUM2UINT($input);
42 $1 = &temp;";
43
44%typemap(in) const unsigned short & (unsigned short temp)
45 "temp = ($*1_ltype) NUM2USHRT($input);
46 $1 = &temp;";
47
48%typemap(in) const unsigned long & (unsigned long temp)
49 "temp = ($*1_ltype) NUM2ULONG($input);
50 $1 = &temp;";
51
52%typemap(in) const bool & (bool temp)
53 "temp = ($*1_ltype) RTEST($input);
54 $1 = &temp;";
55
56%typemap(in) const float & (float temp),
57 const double & (double temp)
58 "temp = ($*1_ltype) NUM2DBL($input);
59 $1 = &temp;";
60
61%typemap(in) const long long & ($*1_ltype temp)
62 "temp = ($*1_ltype) NUM2LL($input);
63 $1 = &temp;";
64
65%typemap(in) const unsigned long long & ($*1_ltype temp)
66 "temp = ($*1_ltype) NUM2ULL($input);
67 $1 = &temp;";
68
69%typemap(in) const char &(char temp) {
70 char *stemp = StringValuePtr($input);
71 temp = *stemp;
72 $1 = &temp;
73}
74
75/* --- Output typemaps --- */
76
77%typemap(out) int, short, long, signed char
78 "$result = INT2NUM($1);";
79
80%typemap(out) unsigned int, unsigned short, unsigned long, unsigned char
81 "$result = UINT2NUM($1);";
82
83/* Long long */
84
85%typemap(out) long long "$result = LL2NUM($1);";
86%typemap(out) unsigned long long "$result = ULL2NUM($1);";
87
88/* Floating point output values */
89%typemap(out) double, float
90 "$result = rb_float_new($1);";
91
92/* Boolean */
93%typemap(out) bool
94 "$result = $1 ? Qtrue : Qfalse;";
95
96/* References to primitive types. Return by value */
97
98%typemap(out) const int &,
99 const short &,
100 const long &,
101 const signed char &
102 "$result = INT2NUM((long) *($1));";
103
104%typemap(out) const unsigned int &,
105 const unsigned short &,
106 const unsigned long &,
107 const unsigned char &
108 "$result = UINT2NUM((unsigned long) *($1));";
109
110%typemap(out) const bool &
111 "$result = *($1) ? Qtrue : Qfalse;";
112
113%typemap(out) const float &, const double &
114 "$result = rb_float_new((double) *($1));";
115
116%typemap(out) const long long &
117 "$result = LL2NUM(*($1));";
118
119%typemap(out) const unsigned long long &
120 "$result = ULL2NUM(*($1));";
121
122/* --- Variable Input --- */
123
124%typemap(varin) int "$1 = NUM2INT($input);";
125%typemap(varin) unsigned int "$1 = NUM2UINT($input);";
126%typemap(varin) short "$1 = NUM2SHRT($input);";
127%typemap(varin) unsigned short "$1 = NUM2USHRT($input);";
128%typemap(varin) long "$1 = NUM2LONG($input);";
129%typemap(varin) unsigned long "$1 = NUM2ULONG($input);";
130%typemap(varin) signed char "$1 = (signed char) NUM2INT($input);";
131%typemap(varin) unsigned char "$1 = (unsigned char) NUM2INT($input);";
132%typemap(varin) char "$1 = NUM2CHR($input);";
133%typemap(varin) float, double "$1 = ($1_ltype) NUM2DBL($input);";
134%typemap(varin) bool "$1 = RTEST($input);";
135
136%typemap(varin) long long "$1 = NUM2LL($input);";
137%typemap(varin) unsigned long long "$1 = NUM2ULL($input);";
138
139/* --- Variable Output --- */
140
141%typemap(varout) int, short, long, signed char
142 "$result = INT2NUM($1);";
143
144%typemap(varout) unsigned int, unsigned short, unsigned long, unsigned char
145 "$result = UINT2NUM($1);";
146
147%typemap(varout) long long "$result = LL2NUM($1);";
148%typemap(varout) unsigned long long "$result = ULL2NUM($1);";
149
150/* Floats and doubles */
151%typemap(varout) double, float
152 "$result = rb_float_new($1);";
153
154/* Boolean */
155%typemap(varout) bool
156 "$result = $1 ? Qtrue : Qfalse;";
157
158/* --- Constants --- */
159
160%typemap(constant) int, short, long, signed char
161 "rb_define_const($module,\"$symname\", INT2NUM($1));";
162
163%typemap(constant) unsigned int, unsigned short, unsigned long, unsigned char
164 "rb_define_const($module,\"$symname\", UINT2NUM($1));";
165
166%typemap(constant) long long
167 "rb_define_const($module,\"$symname\", LL2NUM($1));";
168
169%typemap(constant) unsigned long long
170 "rb_define_const($module,\"$symname\", ULL2NUM($1));";
171
172%typemap(constant) double, float
173 "rb_define_const($module,\"$symname\", rb_float_new($1));";
174
175%typemap(constant) bool
176 "rb_define_const($module,\"$symname\", ($1 ? Qtrue : Qfalse));";
177
178/* directorin typemaps */
179
180%typemap(directorin) int , const int& "$input = INT2NUM($1);";
181%typemap(directorin) short , const short& "$input = INT2NUM($1);";
182%typemap(directorin) long , const long& "$input = LONG2NUM($1);";
183%typemap(directorin) signed char , const signed char& "$input = INT2NUM($1);";
184%typemap(directorin) float , const float& "$input = rb_float_new($1);";
185%typemap(directorin) double , const double& "$input = rb_float_new($1);";
186%typemap(directorin) bool , const bool& "$input = $1 ? Qtrue : Qfalse;";
187%typemap(directorin) unsigned int , const unsigned int& "$input = UINT2NUM($1);";
188%typemap(directorin) unsigned short, const unsigned short& "$input = UINT2NUM($1);";
189%typemap(directorin) unsigned long , const unsigned long& "$input = ULONG2NUM($1);";
190%typemap(directorin) unsigned char , const unsigned char& "$input = UINT2NUM($1);";
191
192/* --- directorout typemaps --- */
193
194%define DIRECTOROUT_TYPEMAP(type, converter)
195%typemap(directorargout) type *DIRECTOROUT "*$result = (type) converter($input);";
196%typemap(directorout) type "$result = (type) converter($input);";
197%typemap(directorout) const type& {
198 $basetype temp = converter($input);
199 $result = &temp;
200}
201%typemap(directorout) type &DIRECTOROUT = type
202%enddef
203
204DIRECTOROUT_TYPEMAP(char, NUM2INT);
205DIRECTOROUT_TYPEMAP(unsigned char, NUM2UINT);
206DIRECTOROUT_TYPEMAP(short, NUM2INT);
207DIRECTOROUT_TYPEMAP(unsigned short, NUM2INT);
208DIRECTOROUT_TYPEMAP(int, NUM2INT);
209DIRECTOROUT_TYPEMAP(unsigned int, NUM2INT);
210DIRECTOROUT_TYPEMAP(long, NUM2INT);
211DIRECTOROUT_TYPEMAP(unsigned long, NUM2INT);
212DIRECTOROUT_TYPEMAP(long long, NUM2INT);
213DIRECTOROUT_TYPEMAP(unsigned long long, NUM2INT);
214DIRECTOROUT_TYPEMAP(float, NUM2DBL);
215DIRECTOROUT_TYPEMAP(double, NUM2DBL);
216DIRECTOROUT_TYPEMAP(bool, RTEST);
217
218/* ------------------------------------------------------------
219 * Typechecking rules
220 * ------------------------------------------------------------ */
221
222%typecheck(SWIG_TYPECHECK_BOOL) bool {
223 $1 = ($input == Qtrue || $input == Qfalse) ? 1 : 0;
224}
225
226%typecheck(SWIG_TYPECHECK_INTEGER)
227 int, short, long,
228 unsigned int, unsigned short, unsigned long,
229 signed char, unsigned char,
230 long long, unsigned long long,
231 const int &, const short &, const long &,
232 const unsigned int &, const unsigned short &, const unsigned long &,
233 const long long &, const unsigned long long &
234{
235 $1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
236}
237
238%typecheck(SWIG_TYPECHECK_DOUBLE)
239 float, double,
240 const float &, const double &
241{
242 $1 = ((TYPE($input) == T_FLOAT) || (TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
243}
244
245/* ------------------------------------------------------------
246 * Exception handling
247 * ------------------------------------------------------------ */
248
249%typemap(throws) int,
250 long,
251 short,
252 unsigned int,
253 unsigned long,
254 unsigned short {
255 rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(INT2NUM($1))));
256}
257