paul@261 | 1 | #!/usr/bin/env python |
paul@261 | 2 | |
paul@261 | 3 | """ |
paul@261 | 4 | A native function library for a really simple virtual processor. |
paul@261 | 5 | |
paul@354 | 6 | Copyright (C) 2007, 2008, 2009, 2010 Paul Boddie <paul@boddie.org.uk> |
paul@261 | 7 | |
paul@261 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@261 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@261 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@261 | 11 | version. |
paul@261 | 12 | |
paul@261 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@261 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@261 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@261 | 16 | details. |
paul@261 | 17 | |
paul@261 | 18 | You should have received a copy of the GNU General Public License along with |
paul@261 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@261 | 20 | """ |
paul@261 | 21 | |
paul@264 | 22 | from micropython.program import DataValue |
paul@261 | 23 | import operator |
paul@261 | 24 | |
paul@261 | 25 | class Library: |
paul@261 | 26 | |
paul@261 | 27 | "Native function implementations." |
paul@261 | 28 | |
paul@395 | 29 | # NOTE: These attributes need changing if the instance layout changes. |
paul@395 | 30 | |
paul@395 | 31 | instance_data_offset = 2 |
paul@395 | 32 | instance_size = 3 |
paul@395 | 33 | |
paul@354 | 34 | def __init__(self, machine, constants): |
paul@261 | 35 | |
paul@261 | 36 | """ |
paul@354 | 37 | Initialise the library with the 'machine' and the 'constants' addresses |
paul@354 | 38 | dictionary. |
paul@261 | 39 | """ |
paul@261 | 40 | |
paul@261 | 41 | self.machine = machine |
paul@354 | 42 | self.constants = constants |
paul@261 | 43 | |
paul@261 | 44 | # Native class constants. |
paul@261 | 45 | |
paul@261 | 46 | cls = self.machine._get_class("__builtins__", "int") |
paul@261 | 47 | self.int_class = cls.location |
paul@261 | 48 | self.int_instance = cls.instance_template_location |
paul@261 | 49 | cls = self.machine._get_class("__builtins__", "list") |
paul@346 | 50 | if cls is not None: |
paul@346 | 51 | self.list_class = cls.location |
paul@346 | 52 | self.list_instance = cls.instance_template_location |
paul@261 | 53 | cls = self.machine._get_class("__builtins__", "IndexError") |
paul@346 | 54 | if cls is not None: |
paul@346 | 55 | self.index_error = cls.location |
paul@346 | 56 | self.index_error_instance = cls.instance_template_location |
paul@262 | 57 | cls = self.machine._get_class("__builtins__", "basestring") |
paul@346 | 58 | if cls is not None: |
paul@346 | 59 | self.str_class = cls.location |
paul@346 | 60 | self.str_instance = cls.instance_template_location |
paul@261 | 61 | |
paul@261 | 62 | self.tuple_class = self.machine.tuple_class |
paul@261 | 63 | self.type_error_instance = self.machine.type_error_instance |
paul@261 | 64 | |
paul@261 | 65 | self.frame_stack = self.machine.frame_stack |
paul@261 | 66 | self.local_sp_stack = self.machine.local_sp_stack |
paul@261 | 67 | |
paul@391 | 68 | def _check_index(self, pos, nelements): |
paul@391 | 69 | return pos >= 0 and pos < nelements |
paul@390 | 70 | |
paul@261 | 71 | def builtins_int_arithmetic_op(self, op): |
paul@261 | 72 | frame = self.local_sp_stack[-1] |
paul@261 | 73 | |
paul@261 | 74 | # Get operands addresses. |
paul@261 | 75 | |
paul@264 | 76 | left_value = self.frame_stack[frame] |
paul@264 | 77 | right_value = self.frame_stack[frame + 1] |
paul@261 | 78 | |
paul@261 | 79 | # Test operand suitability. |
paul@261 | 80 | # NOTE: Support other types. |
paul@261 | 81 | |
paul@264 | 82 | if not (self.machine._CheckInstance(left_value.ref, self.int_class) and |
paul@264 | 83 | self.machine._CheckInstance(right_value.ref, self.int_class)): |
paul@264 | 84 | |
paul@395 | 85 | self.machine.exception = self.machine._MakeObject(self.instance_size, self.type_error_instance) |
paul@261 | 86 | return self.machine.RaiseException() |
paul@261 | 87 | |
paul@395 | 88 | left_data = left_value.ref + self.instance_data_offset |
paul@395 | 89 | right_data = right_value.ref + self.instance_data_offset |
paul@261 | 90 | |
paul@261 | 91 | # Make a new object. |
paul@261 | 92 | |
paul@395 | 93 | addr = self.machine._MakeObject(self.instance_size, self.int_instance) |
paul@261 | 94 | |
paul@261 | 95 | # Store the result. |
paul@261 | 96 | # NOTE: The data is considered ready to use. |
paul@261 | 97 | |
paul@395 | 98 | self.machine.save(addr + self.instance_data_offset, op(self.machine.load(left_data), self.machine.load(right_data))) |
paul@261 | 99 | |
paul@261 | 100 | # Return the new object. |
paul@261 | 101 | # Introduce object as context for the new object. |
paul@261 | 102 | |
paul@264 | 103 | self.machine.result = DataValue(addr, addr) |
paul@261 | 104 | |
paul@354 | 105 | def builtins_logical_op(self, operand_class, op): |
paul@262 | 106 | frame = self.local_sp_stack[-1] |
paul@262 | 107 | |
paul@262 | 108 | # Get operands addresses. |
paul@262 | 109 | |
paul@264 | 110 | left_value = self.frame_stack[frame] |
paul@264 | 111 | right_value = self.frame_stack[frame + 1] |
paul@262 | 112 | |
paul@262 | 113 | # Test operand suitability. |
paul@262 | 114 | # NOTE: Handle comparisons of incompatible types more appropriately. |
paul@354 | 115 | # NOTE: Return NotImplemented. |
paul@262 | 116 | |
paul@264 | 117 | if not (self.machine._CheckInstance(left_value.ref, operand_class) and |
paul@264 | 118 | self.machine._CheckInstance(right_value.ref, operand_class)): |
paul@264 | 119 | |
paul@354 | 120 | notimpl = self.constants[NotImplemented] |
paul@354 | 121 | self.machine.result = DataValue(notimpl, notimpl) |
paul@262 | 122 | return |
paul@262 | 123 | |
paul@395 | 124 | left_data = left_value.ref + self.instance_data_offset |
paul@395 | 125 | right_data = right_value.ref + self.instance_data_offset |
paul@262 | 126 | |
paul@262 | 127 | # Test the data. |
paul@262 | 128 | # NOTE: The data is considered ready to use. |
paul@262 | 129 | |
paul@262 | 130 | if op(self.machine.load(left_data), self.machine.load(right_data)): |
paul@354 | 131 | self.machine.result = DataValue(self.constants[True], self.constants[True]) |
paul@262 | 132 | else: |
paul@354 | 133 | self.machine.result = DataValue(self.constants[False], self.constants[False]) |
paul@262 | 134 | |
paul@262 | 135 | # Operators. |
paul@262 | 136 | # Although this takes a short-cut by using the operator module, testing is |
paul@262 | 137 | # still performed on the operands to ensure that they qualify for these |
paul@262 | 138 | # native operations. |
paul@262 | 139 | |
paul@262 | 140 | def builtins_int_add(self): |
paul@262 | 141 | return self.builtins_int_arithmetic_op(operator.add) |
paul@262 | 142 | |
paul@262 | 143 | def builtins_int_sub(self): |
paul@262 | 144 | return self.builtins_int_arithmetic_op(operator.sub) |
paul@262 | 145 | |
paul@262 | 146 | def builtins_int_pow(self): |
paul@262 | 147 | return self.builtins_int_arithmetic_op(operator.pow) |
paul@262 | 148 | |
paul@262 | 149 | def builtins_int_lt(self): |
paul@354 | 150 | return self.builtins_logical_op(self.int_class, operator.lt) |
paul@262 | 151 | |
paul@262 | 152 | def builtins_int_le(self): |
paul@354 | 153 | return self.builtins_logical_op(self.int_class, operator.le) |
paul@262 | 154 | |
paul@262 | 155 | def builtins_int_gt(self): |
paul@354 | 156 | return self.builtins_logical_op(self.int_class, operator.gt) |
paul@262 | 157 | |
paul@262 | 158 | def builtins_int_ge(self): |
paul@354 | 159 | return self.builtins_logical_op(self.int_class, operator.ge) |
paul@262 | 160 | |
paul@262 | 161 | def builtins_int_eq(self): |
paul@354 | 162 | return self.builtins_logical_op(self.int_class, operator.eq) |
paul@262 | 163 | |
paul@262 | 164 | def builtins_int_ne(self): |
paul@354 | 165 | return self.builtins_logical_op(self.int_class, operator.ne) |
paul@262 | 166 | |
paul@262 | 167 | def builtins_str_lt(self): |
paul@354 | 168 | return self.builtins_logical_op(self.str_class, operator.lt) |
paul@262 | 169 | |
paul@262 | 170 | def builtins_str_le(self): |
paul@354 | 171 | return self.builtins_logical_op(self.str_class, operator.le) |
paul@262 | 172 | |
paul@262 | 173 | def builtins_str_gt(self): |
paul@354 | 174 | return self.builtins_logical_op(self.str_class, operator.gt) |
paul@262 | 175 | |
paul@262 | 176 | def builtins_str_ge(self): |
paul@354 | 177 | return self.builtins_logical_op(self.str_class, operator.ge) |
paul@262 | 178 | |
paul@262 | 179 | def builtins_str_eq(self): |
paul@354 | 180 | return self.builtins_logical_op(self.str_class, operator.eq) |
paul@262 | 181 | |
paul@262 | 182 | def builtins_str_ne(self): |
paul@354 | 183 | return self.builtins_logical_op(self.str_class, operator.ne) |
paul@262 | 184 | |
paul@262 | 185 | def builtins_int_and(self): |
paul@262 | 186 | return self.builtins_int_arithmetic_op(operator.and_) |
paul@262 | 187 | |
paul@262 | 188 | def builtins_int_or(self): |
paul@262 | 189 | return self.builtins_int_arithmetic_op(operator.or_) |
paul@262 | 190 | |
paul@262 | 191 | # Specific operator methods. |
paul@262 | 192 | |
paul@261 | 193 | def builtins_int_bool(self): |
paul@261 | 194 | frame = self.local_sp_stack[-1] |
paul@261 | 195 | |
paul@261 | 196 | # Get operands addresses. |
paul@261 | 197 | |
paul@264 | 198 | left_value = self.frame_stack[frame] |
paul@261 | 199 | |
paul@261 | 200 | # Test operand suitability. |
paul@261 | 201 | |
paul@264 | 202 | if not self.machine._CheckInstance(left_value.ref, self.int_class): |
paul@395 | 203 | self.machine.exception = self.machine._MakeObject(self.instance_size, self.type_error_instance) |
paul@261 | 204 | return self.machine.RaiseException() |
paul@261 | 205 | |
paul@395 | 206 | left_data = left_value.ref + self.instance_data_offset |
paul@261 | 207 | |
paul@261 | 208 | # Test the data. |
paul@261 | 209 | # NOTE: The data is considered ready to use. |
paul@261 | 210 | |
paul@261 | 211 | if self.machine.load(left_data) != 0: |
paul@354 | 212 | self.machine.result = DataValue(self.constants[True], self.constants[True]) |
paul@261 | 213 | else: |
paul@354 | 214 | self.machine.result = DataValue(self.constants[False], self.constants[False]) |
paul@261 | 215 | |
paul@261 | 216 | def builtins_int_neg(self): |
paul@261 | 217 | frame = self.local_sp_stack[-1] |
paul@261 | 218 | |
paul@261 | 219 | # Get operands addresses. |
paul@261 | 220 | |
paul@264 | 221 | left_value = self.frame_stack[frame] |
paul@261 | 222 | |
paul@261 | 223 | # Test operand suitability. |
paul@261 | 224 | |
paul@264 | 225 | if not self.machine._CheckInstance(left_value.ref, self.int_class): |
paul@395 | 226 | self.machine.exception = self.machine._MakeObject(self.instance_size, self.type_error_instance) |
paul@261 | 227 | return self.machine.RaiseException() |
paul@261 | 228 | |
paul@395 | 229 | left_data = left_value.ref + self.instance_data_offset |
paul@261 | 230 | |
paul@261 | 231 | # Make a new object. |
paul@261 | 232 | |
paul@395 | 233 | addr = self.machine._MakeObject(self.instance_size, self.int_instance) |
paul@261 | 234 | |
paul@261 | 235 | # Store the result. |
paul@261 | 236 | # NOTE: The data is considered ready to use. |
paul@261 | 237 | |
paul@395 | 238 | self.machine.save(addr + self.instance_data_offset, -self.machine.load(left_data)) |
paul@261 | 239 | |
paul@261 | 240 | # Return the new object. |
paul@261 | 241 | # Introduce object as context for the new object. |
paul@261 | 242 | |
paul@264 | 243 | self.machine.result = DataValue(addr, addr) |
paul@261 | 244 | |
paul@262 | 245 | # Various built-in methods. |
paul@261 | 246 | |
paul@261 | 247 | def builtins_bool_bool(self): |
paul@261 | 248 | frame = self.local_sp_stack[-1] |
paul@261 | 249 | |
paul@261 | 250 | # Get operands addresses. |
paul@261 | 251 | |
paul@264 | 252 | left_value = self.frame_stack[frame] |
paul@264 | 253 | self.machine.result = DataValue(left_value.ref, left_value.ref) |
paul@261 | 254 | |
paul@261 | 255 | def builtins_list_new(self): |
paul@261 | 256 | frame = self.local_sp_stack[-1] |
paul@261 | 257 | |
paul@332 | 258 | # The first parameter should be the instance. |
paul@261 | 259 | |
paul@332 | 260 | list_value = self.frame_stack[frame] |
paul@261 | 261 | |
paul@332 | 262 | # Make a new sequence. |
paul@332 | 263 | # NOTE: Using an arbitrary size. |
paul@261 | 264 | |
paul@336 | 265 | new_fragment = self.machine._MakeFragment(1, 5) # include the header |
paul@261 | 266 | |
paul@332 | 267 | # Complete the list instance by saving the fragment reference. |
paul@336 | 268 | # NOTE: This requires an attribute in the list structure. |
paul@261 | 269 | |
paul@395 | 270 | addr = list_value.ref + self.instance_data_offset |
paul@332 | 271 | self.machine.save(addr, DataValue(None, new_fragment)) |
paul@261 | 272 | |
paul@390 | 273 | def builtins_list_get_single_item(self): |
paul@261 | 274 | frame = self.local_sp_stack[-1] |
paul@261 | 275 | |
paul@261 | 276 | # Get the operand address. |
paul@261 | 277 | |
paul@264 | 278 | item_value = self.frame_stack[frame + 1] |
paul@261 | 279 | |
paul@261 | 280 | # Get the list address. |
paul@261 | 281 | |
paul@264 | 282 | obj_value = self.frame_stack[frame] |
paul@261 | 283 | |
paul@261 | 284 | # Get the fragment address. |
paul@261 | 285 | |
paul@395 | 286 | fragment = self.machine.load(obj_value.ref + self.instance_data_offset) |
paul@261 | 287 | |
paul@261 | 288 | # Get the fragment header. |
paul@261 | 289 | |
paul@264 | 290 | header = self.machine.load(fragment.ref) |
paul@261 | 291 | nelements = header.occupied_size - 1 |
paul@261 | 292 | |
paul@395 | 293 | # Get the item position. |
paul@261 | 294 | |
paul@395 | 295 | item_pos = self.machine.load(item_value.ref + self.instance_data_offset) |
paul@261 | 296 | |
paul@391 | 297 | if not self._check_index(item_pos, nelements): |
paul@395 | 298 | self.machine.exception = self.machine._MakeObject(self.instance_size, self.index_error_instance) |
paul@261 | 299 | return self.machine.RaiseException() |
paul@261 | 300 | |
paul@395 | 301 | # Get the item itself. |
paul@261 | 302 | |
paul@399 | 303 | self.machine.result = self.machine.load(fragment.ref + 1 + item_pos) |
paul@261 | 304 | |
paul@261 | 305 | def builtins_list_len(self): |
paul@261 | 306 | frame = self.local_sp_stack[-1] |
paul@261 | 307 | |
paul@261 | 308 | # Get the list address. |
paul@261 | 309 | |
paul@264 | 310 | obj_value = self.frame_stack[frame] |
paul@261 | 311 | |
paul@261 | 312 | # Get the fragment address. |
paul@261 | 313 | |
paul@395 | 314 | fragment = self.machine.load(obj_value.ref + self.instance_data_offset) |
paul@261 | 315 | |
paul@261 | 316 | # Get the fragment header. |
paul@261 | 317 | |
paul@264 | 318 | header = self.machine.load(fragment.ref) |
paul@261 | 319 | nelements = header.occupied_size - 1 |
paul@261 | 320 | |
paul@261 | 321 | # Make a new object. |
paul@261 | 322 | |
paul@395 | 323 | addr = self.machine._MakeObject(self.instance_size, self.int_instance) |
paul@261 | 324 | |
paul@261 | 325 | # Store the result. |
paul@261 | 326 | # NOTE: The data is considered ready to use. |
paul@261 | 327 | |
paul@395 | 328 | self.machine.save(addr + self.instance_data_offset, nelements) |
paul@261 | 329 | |
paul@261 | 330 | # Return the new object. |
paul@261 | 331 | # Introduce object as context for the new object. |
paul@261 | 332 | |
paul@264 | 333 | self.machine.result = DataValue(addr, addr) |
paul@261 | 334 | |
paul@261 | 335 | def builtins_list_append(self): |
paul@261 | 336 | frame = self.local_sp_stack[-1] |
paul@261 | 337 | |
paul@261 | 338 | # Get operand address. |
paul@261 | 339 | |
paul@264 | 340 | arg_value = self.frame_stack[frame + 1] |
paul@261 | 341 | |
paul@261 | 342 | # Get the list address. |
paul@261 | 343 | |
paul@264 | 344 | obj_value = self.frame_stack[frame] |
paul@261 | 345 | |
paul@261 | 346 | # Get the fragment address. |
paul@261 | 347 | |
paul@395 | 348 | fragment = self.machine.load(obj_value.ref + self.instance_data_offset) |
paul@261 | 349 | |
paul@261 | 350 | # Get the fragment header. |
paul@261 | 351 | |
paul@264 | 352 | header = self.machine.load(fragment.ref) |
paul@261 | 353 | |
paul@261 | 354 | # Attempt to add the reference. |
paul@261 | 355 | |
paul@261 | 356 | if header.occupied_size < header.allocated_size: |
paul@264 | 357 | self.machine.save(fragment.ref + header.occupied_size, arg_value) |
paul@261 | 358 | header.occupied_size += 1 |
paul@261 | 359 | else: |
paul@261 | 360 | |
paul@261 | 361 | # Make a new fragment, maintaining more space than currently |
paul@261 | 362 | # occupied in order to avoid reallocation. |
paul@261 | 363 | |
paul@337 | 364 | new_fragment = self.machine._MakeFragment(header.occupied_size + 1, header.occupied_size * 2) |
paul@261 | 365 | |
paul@261 | 366 | # Copy existing elements. |
paul@261 | 367 | |
paul@336 | 368 | for i in range(1, header.occupied_size): |
paul@264 | 369 | self.machine.save(new_fragment + i, self.machine.load(fragment.ref + i)) |
paul@261 | 370 | |
paul@336 | 371 | self.machine.save(new_fragment + header.occupied_size, arg_value) |
paul@261 | 372 | |
paul@261 | 373 | # Set the new fragment in the object. |
paul@261 | 374 | # NOTE: The old fragment could be deallocated. |
paul@261 | 375 | |
paul@395 | 376 | self.machine.save(obj_value.ref + self.instance_data_offset, DataValue(None, new_fragment)) |
paul@261 | 377 | |
paul@261 | 378 | def builtins_tuple_len(self): |
paul@261 | 379 | frame = self.local_sp_stack[-1] |
paul@261 | 380 | |
paul@261 | 381 | # Get the tuple address. |
paul@261 | 382 | |
paul@264 | 383 | obj_value = self.frame_stack[frame] |
paul@261 | 384 | |
paul@261 | 385 | # Get the header. |
paul@261 | 386 | |
paul@264 | 387 | header = self.machine.load(obj_value.ref) |
paul@395 | 388 | nelements = header.size - self.instance_data_offset |
paul@261 | 389 | |
paul@261 | 390 | # Make a new object. |
paul@261 | 391 | |
paul@395 | 392 | addr = self.machine._MakeObject(self.instance_size, self.int_instance) |
paul@261 | 393 | |
paul@261 | 394 | # Store the result. |
paul@261 | 395 | # NOTE: The data is considered ready to use. |
paul@261 | 396 | |
paul@395 | 397 | self.machine.save(addr + self.instance_data_offset, nelements) |
paul@261 | 398 | |
paul@261 | 399 | # Return the new object. |
paul@261 | 400 | # Introduce object as context for the new object. |
paul@261 | 401 | |
paul@264 | 402 | self.machine.result = DataValue(addr, addr) |
paul@261 | 403 | |
paul@390 | 404 | def builtins_tuple_get_single_item(self): |
paul@261 | 405 | frame = self.local_sp_stack[-1] |
paul@261 | 406 | |
paul@261 | 407 | # Get the operand address. |
paul@261 | 408 | |
paul@264 | 409 | item_value = self.frame_stack[frame + 1] |
paul@261 | 410 | |
paul@261 | 411 | # Get the tuple address. |
paul@261 | 412 | |
paul@264 | 413 | obj_value = self.frame_stack[frame] |
paul@261 | 414 | |
paul@261 | 415 | # Get the header. |
paul@261 | 416 | |
paul@264 | 417 | header = self.machine.load(obj_value.ref) |
paul@395 | 418 | nelements = header.size - self.instance_data_offset |
paul@261 | 419 | |
paul@261 | 420 | # NOTE: Assume single location for data and header. |
paul@261 | 421 | |
paul@395 | 422 | item_pos = self.machine.load(item_value.ref + self.instance_data_offset) |
paul@261 | 423 | |
paul@391 | 424 | if not self._check_index(item_pos, nelements): |
paul@395 | 425 | self.machine.exception = self.machine._MakeObject(self.instance_size, self.index_error_instance) |
paul@261 | 426 | return self.machine.RaiseException() |
paul@261 | 427 | |
paul@395 | 428 | # Get the item. |
paul@261 | 429 | |
paul@395 | 430 | self.machine.result = self.machine.load(obj_value.ref + self.instance_data_offset + item_pos) |
paul@261 | 431 | |
paul@261 | 432 | def builtins_object_init(self): |
paul@261 | 433 | pass |
paul@261 | 434 | |
paul@377 | 435 | def builtins_isinstance(self): |
paul@377 | 436 | frame = self.local_sp_stack[-1] |
paul@377 | 437 | |
paul@377 | 438 | # Get the operand addresses. |
paul@377 | 439 | |
paul@377 | 440 | obj_value = self.frame_stack[frame] |
paul@377 | 441 | cls_value = self.frame_stack[frame + 1] |
paul@377 | 442 | |
paul@377 | 443 | if self.machine._CheckInstance(obj_value.ref, cls_value.ref): |
paul@377 | 444 | self.machine.result = DataValue(self.constants[True], self.constants[True]) |
paul@377 | 445 | else: |
paul@377 | 446 | self.machine.result = DataValue(self.constants[False], self.constants[False]) |
paul@377 | 447 | |
paul@261 | 448 | native_functions = { |
paul@261 | 449 | |
paul@261 | 450 | # Native method implementations: |
paul@261 | 451 | |
paul@261 | 452 | "__builtins__.int.__add__" : builtins_int_add, |
paul@261 | 453 | "__builtins__.int.__radd__" : builtins_int_add, # NOTE: To be made distinct. |
paul@261 | 454 | "__builtins__.int.__sub__" : builtins_int_sub, |
paul@262 | 455 | "__builtins__.int.__pow__" : builtins_int_pow, |
paul@261 | 456 | "__builtins__.int.__iadd__" : builtins_int_add, |
paul@261 | 457 | "__builtins__.int.__bool__" : builtins_int_bool, |
paul@261 | 458 | "__builtins__.int.__neg__" : builtins_int_neg, |
paul@261 | 459 | "__builtins__.int.__lt__" : builtins_int_lt, |
paul@261 | 460 | "__builtins__.int.__le__" : builtins_int_le, |
paul@261 | 461 | "__builtins__.int.__gt__" : builtins_int_gt, |
paul@261 | 462 | "__builtins__.int.__ge__" : builtins_int_ge, |
paul@261 | 463 | "__builtins__.int.__eq__" : builtins_int_eq, |
paul@261 | 464 | "__builtins__.int.__ne__" : builtins_int_ne, |
paul@261 | 465 | "__builtins__.int.__and__" : builtins_int_and, |
paul@261 | 466 | "__builtins__.int.__rand__" : builtins_int_and, |
paul@261 | 467 | "__builtins__.int.__or__" : builtins_int_or, |
paul@261 | 468 | "__builtins__.int.__ror__" : builtins_int_or, |
paul@261 | 469 | "__builtins__.bool.__bool__" : builtins_bool_bool, |
paul@390 | 470 | "__builtins__.list.__get_single_item__" : builtins_list_get_single_item, |
paul@261 | 471 | "__builtins__.list.__len__" : builtins_list_len, |
paul@261 | 472 | "__builtins__.list.append" : builtins_list_append, |
paul@261 | 473 | "__builtins__.tuple.__len__" : builtins_tuple_len, |
paul@390 | 474 | "__builtins__.tuple.__get_single_item__" : builtins_tuple_get_single_item, |
paul@262 | 475 | "__builtins__.basestring.__lt__" : builtins_str_lt, |
paul@262 | 476 | "__builtins__.basestring.__le__" : builtins_str_le, |
paul@262 | 477 | "__builtins__.basestring.__gt__" : builtins_str_gt, |
paul@262 | 478 | "__builtins__.basestring.__ge__" : builtins_str_ge, |
paul@262 | 479 | "__builtins__.basestring.__eq__" : builtins_str_eq, |
paul@262 | 480 | "__builtins__.basestring.__ne__" : builtins_str_ne, |
paul@261 | 481 | |
paul@261 | 482 | # Native initialisers: |
paul@261 | 483 | |
paul@261 | 484 | "__builtins__.object.__init__" : builtins_object_init, # NOTE: A no-operation. |
paul@261 | 485 | "__builtins__.BaseException.__init__" : builtins_object_init, # NOTE: To be made distinct, potentially in the builtins module. |
paul@261 | 486 | |
paul@332 | 487 | # Native instantiator helpers: |
paul@261 | 488 | |
paul@332 | 489 | "__builtins__.list.__new__" : builtins_list_new, |
paul@377 | 490 | |
paul@377 | 491 | # Native helper functions: |
paul@377 | 492 | |
paul@377 | 493 | "__builtins__._isinstance" : builtins_isinstance, |
paul@261 | 494 | } |
paul@261 | 495 | |
paul@261 | 496 | # vim: tabstop=4 expandtab shiftwidth=4 |