| 51 | } |
| 52 | |
| 53 | void Override(NULLCRef dest, NULLCArray code) |
| 54 | { |
| 55 | assert(linker); |
| 56 | static unsigned int overrideID = 0; |
| 57 | |
| 58 | if(linker->exTypes[dest.typeID].subCat != ExternTypeInfo::CAT_FUNCTION) |
| 59 | { |
| 60 | nullcThrowError("Destination variable is not a function"); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | char tmp[2048]; |
| 65 | char *it = tmp; |
| 66 | unsigned int *memberList = &linker->exTypeExtra[linker->exTypes[dest.typeID].memberOffset]; |
| 67 | ExternTypeInfo &returnType = linker->exTypes[memberList[0]]; |
| 68 | it += SafeSprintf(it, 2048 - int(it - tmp), "import __last;\r\n%s __override%d(", &linker->exSymbols[0] + returnType.offsetToName, overrideID); |
| 69 | |
| 70 | for(unsigned int i = 0, memberCount = linker->exTypes[dest.typeID].memberCount; i != memberCount; i++) |
| 71 | it += SafeSprintf(it, 2048 - int(it - tmp), "%s arg%d%s", &linker->exSymbols[0] + linker->exTypes[memberList[i + 1]].offsetToName, i, i == memberCount - 1 ? "" : ", "); |
| 72 | it += SafeSprintf(it, 2048 - int(it - tmp), "){ %s }", code.ptr); |
| 73 | overrideID++; |
| 74 | |
| 75 | if(!nullcCompile(tmp)) |
| 76 | { |
| 77 | nullcThrowError("%s", nullcGetLastError()); |
| 78 | return; |
| 79 | } |
| 80 | char *bytecode = NULL; |
| 81 | nullcGetBytecodeNoCache(&bytecode); |
| 82 | if(!nullcLinkCode(bytecode)) |
| 83 | { |
| 84 | delete[] bytecode; |
| 85 | nullcThrowError("%s", nullcGetLastError()); |
| 86 | return; |
| 87 | } |
| 88 | delete[] bytecode; |
| 89 | |
| 90 | ExternFuncInfo &destFunc = linker->exFunctions[((NULLCFuncPtr*)dest.ptr)->id]; |
| 91 | ExternFuncInfo &srcFunc = linker->exFunctions.back(); |
| 92 | if(nullcGetCurrentExecutor(NULL) == NULLC_X86) |
| 93 | RewriteX86(((NULLCFuncPtr*)dest.ptr)->id, linker->exFunctions.size() - 1); |
| 94 | destFunc.address = srcFunc.address; |
| 95 | destFunc.codeSize = srcFunc.codeSize; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | #define REGISTER_FUNC(funcPtr, name, index) if(!nullcBindModuleFunction("std.dynamic", (void(*)())NULLCDynamic::funcPtr, name, index)) return false; |
nothing calls this directly
no test coverage detected