Mercurial > repos > tabletprog
comparison cbackend.js @ 266:75dc7161c1ca
Added object module which provides some basic reflection capabilities
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 17 Jul 2014 23:57:41 -0700 |
parents | d6a4c9e7716e |
children | d2b70cba661e |
comparison
equal
deleted
inserted
replaced
265:d6a4c9e7716e | 266:75dc7161c1ca |
---|---|
520 } | 520 } |
521 | 521 |
522 cObject.prototype.toCDef = function() { | 522 cObject.prototype.toCDef = function() { |
523 this.checkInitMsg(); | 523 this.checkInitMsg(); |
524 var slotdefs = ''; | 524 var slotdefs = ''; |
525 var methlists = ''; | |
526 var methdict = '}, {' | |
525 var metadef = 'obj_meta ' + this.name + '_meta = {sizeof(' + this.name +'), {'; | 527 var metadef = 'obj_meta ' + this.name + '_meta = {sizeof(' + this.name +'), {'; |
526 for (var i = 0; i < 16; i++) { | 528 for (var i = 0; i < 16; i++) { |
527 if (i) { | 529 if (i) { |
528 metadef += ', '; | 530 metadef += ', '; |
529 } | 531 } |
550 } | 552 } |
551 slotdefs += '\t\tdefault:\n' + | 553 slotdefs += '\t\tdefault:\n' + |
552 '\t\t\treturn no_impl(method_id, num_params, (object *)self, args);\n\t}\n}\n'; | 554 '\t\t\treturn no_impl(method_id, num_params, (object *)self, args);\n\t}\n}\n'; |
553 | 555 |
554 } | 556 } |
557 methlists += 'uint32_t ' + this.name + '_methods_' + i + '[] = {' | |
558 for (j in this.slots[i]) { | |
559 methlists += this.slots[i][j][0] + ', '; | |
560 } | |
561 methlists += 'LAST_METHOD};'; | |
555 metadef += this.name + '_slot_' + i; | 562 metadef += this.name + '_slot_' + i; |
563 methdict += (i ? ', ' : '') + this.name + '_methods_' + i; | |
556 } else { | 564 } else { |
557 metadef += 'no_impl'; | 565 metadef += 'no_impl'; |
558 } | 566 methdict += (i ? ', ' : '') + 'NULL'; |
559 } | 567 } |
560 metadef += '}};\n'; | 568 } |
561 return slotdefs + metadef; | 569 metadef += methdict + '}};\n'; |
570 return slotdefs + methlists + metadef; | |
562 } | 571 } |
563 | 572 |
564 cObject.prototype.toCInstance = function() { | 573 cObject.prototype.toCInstance = function() { |
565 this.checkInitMsg(); | 574 this.checkInitMsg(); |
566 var ret = 'make_object(&' + this.name + '_meta, ' + this.parent + ', ' + this.values.length + (this.values.length ? ', ' : '') + this.values.join(', ') + ')'; | 575 var ret = 'make_object(&' + this.name + '_meta, ' + this.parent + ', ' + this.values.length + (this.values.length ? ', ' : '') + this.values.join(', ') + ')'; |