Browse Source

Sol Part 18: This Time, it's Personal!

master
csguest 7 years ago
parent
commit
f25e21dc46
  1. 4
      builtins.c
  2. 14
      object.c
  3. 2188
      parser.output
  4. 390
      parser.tab.c
  5. 24
      parser.y
  6. 1
      sol.h
  7. 1
      state.c

4
builtins.c

@ -342,6 +342,10 @@ sol_object_t *sol_f_debug_locals(sol_state_t *state, sol_object_t *args) {
return sol_list_get_index(state, state->scopes, 0);
}
sol_object_t *sol_f_debug_scopes(sol_state_t *state, sol_object_t *args) {
return sol_incref(state->scopes);
}
sol_object_t *sol_f_iter_str(sol_state_t *state, sol_object_t *args) {
sol_object_t *obj = sol_list_get_index(state, args, 0), *local = sol_list_get_index(state, args, 1);
sol_object_t *index = sol_map_get_name(state, local, "idx"), *res;

14
object.c

@ -242,7 +242,7 @@ void sol_list_set_index(sol_state_t *state, sol_object_t *list, int idx, sol_obj
void sol_list_insert(sol_state_t *state, sol_object_t *list, int idx, sol_object_t *obj) {
sol_object_t *next = list, *prev = NULL, *temp = sol_alloc_object(state);
int i = 0;
int i = -1;
if(sol_has_error(state)) return;
if(!sol_is_list(list)) {
sol_obj_free(sol_set_error_string(state, "Insert into non-list"));
@ -255,8 +255,9 @@ void sol_list_insert(sol_state_t *state, sol_object_t *list, int idx, sol_object
temp->type = SOL_LCELL;
temp->ops = &(state->LCellOps);
temp->lvalue = sol_incref(obj);
while(next && i < idx) {
while(next) {
if(next->lvalue) i++;
if(i >= idx) break;
prev = next;
next = next->lnext;
}
@ -290,23 +291,24 @@ void sol_list_insert(sol_state_t *state, sol_object_t *list, int idx, sol_object
sol_object_t *sol_list_remove(sol_state_t *state, sol_object_t *list, int idx) {
sol_object_t *next = list, *prev = NULL, *res;
int i = 0;
int i = -1;
if(sol_has_error(state)) return sol_incref(state->None);
if(idx < 0) {
return sol_set_error_string(state, "Remove from negative index");
}
while(next && i < idx) {
while(next) {
if(next->lvalue) i++;
if(i >= idx) break;
prev = next;
next = next->lnext;
}
if(next) {
if(prev) {
res = next->lvalue;
res = sol_incref(next->lvalue);
prev->lnext = next->lnext;
sol_obj_free(next);
} else {
res = list->lvalue;
res = sol_incref(list->lvalue);
list->lvalue = NULL;
}
assert(!sol_validate_list(state, list));

2188
parser.output
File diff suppressed because it is too large
View File

390
parser.tab.c
File diff suppressed because it is too large
View File

24
parser.y

@ -246,8 +246,8 @@ expr:
;
logic_expr:
logic_expr LAND logic_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LAND; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| logic_expr LOR logic_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LOR; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
logic_expr LAND ulogic_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LAND; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| logic_expr LOR ulogic_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LOR; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| ulogic_expr { $$ = $1; }
;
@ -257,24 +257,24 @@ ulogic_expr:
;
rel_expr:
rel_expr EQUAL rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_EQUAL; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| rel_expr LESS rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LESS; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| rel_expr GREATER rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_GREATER; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| rel_expr LESSEQ rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LESSEQ; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| rel_expr GREATEREQ rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_GREATEREQ; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
term_expr EQUAL rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_EQUAL; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr LESS rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LESS; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr GREATER rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_GREATER; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr LESSEQ rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LESSEQ; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr GREATEREQ rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_GREATEREQ; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr { $$ = $1; }
;
term_expr:
term_expr PLUS term_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_ADD; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr MINUS term_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_SUB; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
term_expr PLUS factor_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_ADD; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| term_expr MINUS factor_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_SUB; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| factor_expr { $$ = $1; }
;
factor_expr:
factor_expr STAR factor_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_MUL; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| factor_expr SLASH factor_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_DIV; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| factor_expr PERCENT factor_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_MOD; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
factor_expr STAR power_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_MUL; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| factor_expr SLASH power_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_DIV; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| factor_expr PERCENT power_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_MOD; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
| power_expr { $$ = $1; }
;

1
sol.h

@ -157,6 +157,7 @@ sol_object_t *sol_f_debug_setref(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_debug_closure(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_debug_globals(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_debug_locals(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_debug_scopes(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_iter_str(sol_state_t *, sol_object_t *);
sol_object_t *sol_f_iter_list(sol_state_t *, sol_object_t *);

1
state.c

@ -131,6 +131,7 @@ int sol_state_init(sol_state_t *state) {
sol_map_set_name(state, debug, "closure", sol_new_cfunc(state, sol_f_debug_closure));
sol_map_set_name(state, debug, "globals", sol_new_cfunc(state, sol_f_debug_globals));
sol_map_set_name(state, debug, "locals", sol_new_cfunc(state, sol_f_debug_locals));
sol_map_set_name(state, debug, "scopes", sol_new_cfunc(state, sol_f_debug_scopes));
sol_map_set_name(state, globals, "debug", debug);
sol_obj_free(debug);

Loading…
Cancel
Save