remove error from HSVMContext, make svm_stack_ensure_cap return bool instead
This commit is contained in:
parent
759fbe77e5
commit
0fb9d77e40
2 changed files with 5 additions and 6 deletions
|
|
@ -184,13 +184,15 @@ void* h_rvm_run__m(HAllocator *mm__, HRVMProg *prog, const uint8_t* input, size_
|
|||
|
||||
|
||||
|
||||
void svm_stack_ensure_cap(HAllocator *mm__, HSVMContext *ctx, size_t addl) {
|
||||
bool svm_stack_ensure_cap(HAllocator *mm__, HSVMContext *ctx, size_t addl) {
|
||||
if (ctx->stack_count + addl >= ctx->stack_capacity) {
|
||||
ctx->stack = mm__->realloc(mm__, ctx->stack, sizeof(*ctx->stack) * (ctx->stack_capacity *= 2));
|
||||
if (!ctx->stack) {
|
||||
ctx->error = 1;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace, const uint8_t *input, int len) {
|
||||
|
|
@ -199,7 +201,6 @@ HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace,
|
|||
HArena *arena = h_new_arena(mm__, 0);
|
||||
ctx.stack_count = 0;
|
||||
ctx.stack_capacity = 16;
|
||||
ctx.error = 0;
|
||||
ctx.stack = h_new(HParsedToken*, ctx.stack_capacity);
|
||||
|
||||
HParsedToken *tmp_res;
|
||||
|
|
@ -207,8 +208,7 @@ HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace,
|
|||
for (cur = trace; cur; cur = cur->next) {
|
||||
switch (cur->opcode) {
|
||||
case SVM_PUSH:
|
||||
svm_stack_ensure_cap(mm__, &ctx, 1);
|
||||
if (ctx.error) {
|
||||
if (!svm_stack_ensure_cap(mm__, &ctx, 1)) {
|
||||
goto fail;
|
||||
}
|
||||
tmp_res = a_new(HParsedToken, 1);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ typedef struct HSVMContext_ {
|
|||
HParsedToken **stack;
|
||||
size_t stack_count; // number of items on the stack. Thus stack[stack_count] is the first unused item on the stack.
|
||||
size_t stack_capacity;
|
||||
char error;
|
||||
} HSVMContext;
|
||||
|
||||
// These actions all assume that the items on the stack are not
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue