Skip to content

Commit

Permalink
fix: complain if metering is requested but not compiled in
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 11, 2021
1 parent b418db5 commit 857d4ba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/xsnap/makefiles/lin/xsnap.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ C_OPTIONS = \
-DmxRun=1 \
-DmxSloppy=1 \
-DmxSnapshot=1 \
-DmxMetering=1 \
-DmxRegExpUnicodePropertyEscapes=1 \
-I$(INC_DIR) \
-I$(PLT_DIR) \
Expand Down
1 change: 1 addition & 0 deletions packages/xsnap/makefiles/win/xsnap.mak
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ C_OPTIONS = \
/D mxRun=1 \
/D mxSloppy=1 \
/D mxSnapshot=1 \
/D mxMetering=1 \
/D mxRegExpUnicodePropertyEscapes=1 \
/I$(INC_DIR) \
/I$(PLT_DIR) \
Expand Down
9 changes: 7 additions & 2 deletions packages/xsnap/src/xsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ static int fxSnapshotWrite(void* stream, void* address, size_t size)
#define xsBeginMetering(_THE, _CALLBACK, _STEP)
#define xsEndMetering(_THE)
#define xsPatchHostFunction(_FUNCTION,_PATCH)
#define xsMeterHostFunction(_COUNT)
#define xsMeterHostFunction(_COUNT) (void)(_COUNT)
#define xsBeginCrank(_THE, _LIMIT)
#define xsEndCrank(_THE) 0
#endif

static xsUnsignedValue gxCrankMeteringLimit = 0;
static xsUnsignedValue gxCurrentMeter = 0;
static xsBooleanValue fxMeteringCallback(xsMachine* the, xsUnsignedValue index)
xsBooleanValue fxMeteringCallback(xsMachine* the, xsUnsignedValue index)
{
if (gxCurrentMeter > 0 && index > gxCurrentMeter) {
// Just throw right out of the main loop and exit.
Expand Down Expand Up @@ -254,13 +254,18 @@ int main(int argc, char* argv[])
}
}
else if (!strcmp(argv[argi], "-l")) {
#if mxMetering
argi++;
if (argi < argc)
gxCrankMeteringLimit = atoi(argv[argi]);
else {
fxPrintUsage();
return 1;
}
#else
fprintf(stderr, "%s flag not implemented; mxMetering is not enabled\n", argv[argi]);
return 1;
#endif
}
else if (!strcmp(argv[argi], "-p"))
gxMeteringPrint = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/src/xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function xsnap(options) {
let compute = NaN;
const semi = message.indexOf(SEMI, 1);
if (semi >= 0) {
// The message is `.938586;`.
// The message is `.938586;reply`.
const computeBuf = message.slice(1, semi);
const computeStr = decoder.decode(computeBuf);
compute = JSON.parse(computeStr);
Expand Down

0 comments on commit 857d4ba

Please sign in to comment.