comparison cbackend.js @ 168:224071eed9dd

Add os sleep
author Mike Pavone <pavone@retrodev.com>
date Sun, 11 Aug 2013 04:02:51 -0700
parents 157cc497a7f1
children 869399ff7faa
comparison
equal deleted inserted replaced
167:5a6a55592c45 168:224071eed9dd
773 var os = new cObject('mod_obj_os'); 773 var os = new cObject('mod_obj_os');
774 os.addInclude('<sys/stat.h>'); 774 os.addInclude('<sys/stat.h>');
775 os.addInclude('<fcntl.h>'); 775 os.addInclude('<fcntl.h>');
776 os.addInclude('<stdlib.h>'); 776 os.addInclude('<stdlib.h>');
777 os.addInclude('<time.h>'); 777 os.addInclude('<time.h>');
778 os.addInclude('<unistd.h>');
778 os.addMessage('write', { 779 os.addMessage('write', {
779 vars: {str: 'string *', intret: 'obj_int32 *', filedes: 'obj_int32 *'}, 780 vars: {str: 'string *', intret: 'obj_int32 *', filedes: 'obj_int32 *'},
780 lines: [ 781 lines: [
781 'filedes = va_arg(args, obj_int32 *);', 782 'filedes = va_arg(args, obj_int32 *);',
782 'str = va_arg(args, string *);', 783 'str = va_arg(args, string *);',
903 'intret64 = (obj_int64 *)make_object(&obj_int64_meta, NULL, 0);', 904 'intret64 = (obj_int64 *)make_object(&obj_int64_meta, NULL, 0);',
904 'intret64->num = time(NULL);', 905 'intret64->num = time(NULL);',
905 'return &(intret64->header);' 906 'return &(intret64->header);'
906 ] 907 ]
907 }); 908 });
909 os.addMessage('sleep', {
910 vars: {osecs: 'object *', secs: 'obj_int32 *', intret: 'obj_int32 *'},
911 lines: [
912 'osecs = va_arg(args, object *);',
913 'secs = mcall(' + getMethodId("int32") + ', 1, osecs);',
914 'intret = (obj_int32 *)make_object(&obj_int32_meta, NULL, 0);',
915 'intret->num = sleep(secs->num);',
916 'return &(intret->header);'
917 ]
918 });
908 toplevel.names['os'] = os; 919 toplevel.names['os'] = os;
909 } 920 }
910 921
911 modulefile.prototype.toC = function(){ 922 modulefile.prototype.toC = function(){
912 return this.ast.toCModuleInstance(); 923 return this.ast.toCModuleInstance();