# HG changeset patch # User Mike Pavone # Date 1377396179 25200 # Node ID ab7c142090a034cbbf6003d331dab947904e53f1 # Parent f188723c15b4c826162d9ddc8789caad2217d43c Make method names available at runtime so they can be included in method not implemented error messages diff -r f188723c15b4 -r ab7c142090a0 cbackend.js --- a/cbackend.js Sat Aug 24 16:21:42 2013 -0700 +++ b/cbackend.js Sat Aug 24 19:02:59 2013 -0700 @@ -1,14 +1,14 @@ var mainModule; var modules = {}; -var nextmethodId = 0; var methodIds = {}; +var methodNames = []; var assignNames; function getMethodId(methodName) { if (!(methodName in methodIds)) { - methodIds[methodName] = nextmethodId++; - + methodIds[methodName] = methodNames.length; + methodNames.push(methodName); } return methodIds[methodName]; } @@ -1019,11 +1019,16 @@ var moduleinit = processUsedToplevel(toplevel); debugprint('//------COMPILING AST-----'); var rest = 'object * mainModule() {\n' + moduleinit + '\tmain_module = ' + obj.toCModuleInstance() + ';\n\treturn main_module;\n}\n'; + var mnames = 'char * methodNames[] = {\n'; + for (var i = 0; i < methodNames.length; i++) { + mnames += '\t"' + methodNames[i].replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n") + '",\n'; + } + mnames += '};\n'; return '#include "runtime/proghead.inc"\n' + '#define METHOD_ID_MAIN ' + getMethodId('main') + '\n' + '#define METHOD_ID_EMPTY ' + getMethodId('empty') + '\n' + '#define METHOD_ID_CONS ' + getMethodId(getOpMethodName('|')) + '\n' + - forwarddec + toplevelcode + rest + '#include "runtime/progfoot.inc"\n'; + mnames + forwarddec + toplevelcode + rest + '#include "runtime/progfoot.inc"\n'; } object.prototype.toCModule = function() { diff -r f188723c15b4 -r ab7c142090a0 runtime/proghead.inc --- a/runtime/proghead.inc Sat Aug 24 16:21:42 2013 -0700 +++ b/runtime/proghead.inc Sat Aug 24 19:02:59 2013 -0700 @@ -6,9 +6,11 @@ object * main_module; +char * methodNames[]; + object * no_impl(uint32_t method_id, uint32_t num_args, object * self, va_list args) { - fprintf(stderr, "method %d is not implemented on object %p\n", method_id, self); + fprintf(stderr, "method %s(%d) is not implemented on object %p\n", methodNames[method_id], method_id, self); fprintf(stderr, "main_module %p\n", main_module); exit(1); return NULL;