| 303 | } |
| 304 | |
| 305 | void fxDebugEvalBuffer(txMachine* the, txString buffer, txSlot* expression) |
| 306 | { |
| 307 | mxTry(the) { |
| 308 | txU1* src = (txU1*)buffer; |
| 309 | txU1* dst = src; |
| 310 | Atom atom; |
| 311 | txScript script; |
| 312 | txSlot* instance; |
| 313 | txSlot* code; |
| 314 | txSlot* home; |
| 315 | for (;;) { |
| 316 | txU4 byte = 0; |
| 317 | txU1 c = *src++; |
| 318 | if (c == 0) |
| 319 | break; |
| 320 | if (!fxParseHex(c, &byte)) |
| 321 | mxUnknownError("invalid buffer"); |
| 322 | c = *src++; |
| 323 | if (!fxParseHex(c, &byte)) |
| 324 | mxUnknownError("invalid buffer"); |
| 325 | *dst++ = (txU1)byte; |
| 326 | } |
| 327 | src = fxDebugEvalAtom(the, (txU1*)buffer, &atom, "XS_B"); |
| 328 | if (atom.atomSize != (txSize)(dst - (txU1*)buffer)) mxUnknownError("invalid buffer"); |
| 329 | src = fxDebugEvalAtom(the, src, &atom, "VERS"); |
| 330 | if (atom.atomSize != 12) mxUnknownError("invalid buffer"); |
| 331 | if (src[0] != XS_MAJOR_VERSION) mxUnknownError("invalid buffer"); |
| 332 | if (src[1] != XS_MINOR_VERSION) mxUnknownError("invalid buffer"); |
| 333 | src = fxDebugEvalAtom(the, src + 4, &atom, "SYMB"); |
| 334 | script.symbolsSize = atom.atomSize - sizeof(atom); |
| 335 | script.symbolsBuffer = (txByte*)src; |
| 336 | src = fxDebugEvalAtom(the, src + script.symbolsSize, &atom, "CODE"); |
| 337 | script.codeSize = atom.atomSize - sizeof(atom); |
| 338 | script.codeBuffer = (txByte*)src; |
| 339 | fxRemapScript(the, &script); |
| 340 | mxPop(); |
| 341 | mxPush(mxFunctionPrototype); |
| 342 | instance = fxNewFunctionInstance(the, XS_NO_ID); |
| 343 | code = instance->next; |
| 344 | code->value.code.address = fxNewChunk(the, script.codeSize); |
| 345 | c_memcpy(code->value.code.address, script.codeBuffer, script.codeSize); |
| 346 | code->kind = XS_CODE_KIND; |
| 347 | home = mxFunctionInstanceHome(instance); |
| 348 | home->ID = fxGenerateProfileID(the); |
| 349 | mxPullSlot(expression); |
| 350 | } |
| 351 | mxCatch(the) { |
| 352 | mxPush(mxException); |
| 353 | mxException = mxUndefined; |
| 354 | mxPullSlot(expression); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | txBoolean fxDebugEvalExpression(txMachine* the, txSlot* frame, txSlot* expression, txSlot* result) |
| 359 | { |
no test coverage detected