Skip to content

Commit

Permalink
Tentative fix for issues #129 and #130
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobambini committed Apr 10, 2017
1 parent 05357c2 commit d493524
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/compiler/gravity_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "gravity_ast.h"

typedef marray_t(gravity_lexer_t*) lexer_r;
#define MAX_RECURSION_DEPTH 1000

struct gravity_parser_t {
lexer_r *lexer;
Expand Down Expand Up @@ -81,6 +80,7 @@ typedef struct {
static grammar_rule rules[TOK_END];

// MARK: - Internal macros -
#define MAX_RECURSION_DEPTH 1000
#define SEMICOLON_IS_OPTIONAL 1

#define REPORT_ERROR(_tok,...) report_error(parser, GRAVITY_ERROR_SYNTAX, _tok, __VA_ARGS__)
Expand Down
12 changes: 8 additions & 4 deletions src/runtime/gravity_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ inline gravity_value_t convert_value2int (gravity_vm *vm, gravity_value_t v) {
gravity_closure_t *closure = gravity_vm_fastlookup(vm, gravity_value_getclass(v), GRAVITY_INT_INDEX);

// sanity check (and break recursion)
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_int))) return VALUE_FROM_ERROR(NULL);
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_int)) ||
gravity_vm_getclosure(vm) == closure) return VALUE_FROM_ERROR(NULL);

// execute closure and return its value
if (gravity_vm_runclosure(vm, closure, v, NULL, 0)) return gravity_vm_result(vm);
Expand All @@ -266,7 +267,8 @@ inline gravity_value_t convert_value2float (gravity_vm *vm, gravity_value_t v) {
gravity_closure_t *closure = gravity_vm_fastlookup(vm, gravity_value_getclass(v), GRAVITY_FLOAT_INDEX);

// sanity check (and break recursion)
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_float))) return VALUE_FROM_ERROR(NULL);
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_float)) ||
gravity_vm_getclosure(vm) == closure) return VALUE_FROM_ERROR(NULL);

// execute closure and return its value
if (gravity_vm_runclosure(vm, closure, v, NULL, 0)) return gravity_vm_result(vm);
Expand All @@ -292,7 +294,8 @@ inline gravity_value_t convert_value2bool (gravity_vm *vm, gravity_value_t v) {
gravity_closure_t *closure = gravity_vm_fastlookup(vm, gravity_value_getclass(v), GRAVITY_BOOL_INDEX);

// sanity check (and break recursion)
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_bool))) return VALUE_FROM_BOOL(1);
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_bool)) ||
gravity_vm_getclosure(vm) == closure) return VALUE_FROM_BOOL(1);

// execute closure and return its value
if (gravity_vm_runclosure(vm, closure, v, NULL, 0)) return gravity_vm_result(vm);
Expand Down Expand Up @@ -355,7 +358,8 @@ inline gravity_value_t convert_value2string (gravity_vm *vm, gravity_value_t v)
gravity_closure_t *closure = gravity_vm_fastlookup(vm, gravity_value_getclass(v), GRAVITY_STRING_INDEX);

// sanity check (and break recursion)
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_string))) return VALUE_FROM_ERROR(NULL);
if ((!closure) || ((closure->f->tag == EXEC_TYPE_INTERNAL) && (closure->f->internal == convert_object_string)) ||
gravity_vm_getclosure(vm) == closure) return VALUE_FROM_ERROR(NULL);

// execute closure and return its value
if (gravity_vm_runclosure(vm, closure, v, NULL, 0)) return gravity_vm_result(vm);
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/gravity_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,14 @@ bool gravity_vm_runmain (gravity_vm *vm, gravity_closure_t *closure) {

// MARK: - User -

gravity_closure_t *gravity_vm_getclosure (gravity_vm *vm) {
if (!vm->fiber) return NULL;
if (!vm->fiber->nframes) return NULL;

gravity_callframe_t *frame = &(vm->fiber->frames[vm->fiber->nframes-1]);
return frame->closure;
}

void gravity_vm_setslot (gravity_vm *vm, gravity_value_t value, uint32_t index) {
if (index == GRAVITY_FIBER_REGISTER) {
vm->fiber->result = value;
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/gravity_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ GRAVITY_API bool gravity_vm_ismini (gravity_vm *vm);
GRAVITY_API gravity_value_t gravity_vm_keyindex (gravity_vm *vm, uint32_t index);
GRAVITY_API bool gravity_vm_isaborted (gravity_vm *vm);
GRAVITY_API void gravity_vm_setaborted (gravity_vm *vm);
GRAVITY_API gravity_closure_t *gravity_vm_getclosure (gravity_vm *vm);


GRAVITY_API void gravity_gray_value (gravity_vm* vm, gravity_value_t v);
GRAVITY_API void gravity_gray_object (gravity_vm* vm, gravity_object_t *obj);
Expand Down

0 comments on commit d493524

Please sign in to comment.