Skip to content

Commit

Permalink
updates for J & K tmp variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-hodgman1 committed Oct 20, 2018
1 parent 4151cdf commit 4ffdd58
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/match_token.rl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"DRUNK.WRAP" => { MATCH_OP(E_OP_DRUNK_WRAP); };
"FLIP" => { MATCH_OP(E_OP_FLIP); };
"I" => { MATCH_OP(E_OP_I); };
"J" => { MATCH_OP(E_OP_J); };
"K" => { MATCH_OP(E_OP_K); };
"O" => { MATCH_OP(E_OP_O); };
"O.INC" => { MATCH_OP(E_OP_O_INC); };
"O.MAX" => { MATCH_OP(E_OP_O_MAX); };
Expand Down
2 changes: 2 additions & 0 deletions src/ops/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static bool delay_common_add(scene_state_t *ss, exec_state_t *es,
ss->delay.time[i] = delay_time;
ss->delay.origin_script[i] = es_variables(es)->script_number;
ss->delay.origin_i[i] = es_variables(es)->i;
ss->delay.origin_j[i] = es_variables(es)->j;
ss->delay.origin_k[i] = es_variables(es)->k;
copy_command(&ss->delay.commands[i], post_command);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/ops/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
const tele_op_t *tele_ops[E_OP__LENGTH] = {
// variables
&op_A, &op_B, &op_C, &op_D, &op_DRUNK, &op_DRUNK_MAX, &op_DRUNK_MIN,
&op_DRUNK_WRAP, &op_FLIP, &op_I, &op_O, &op_O_INC, &op_O_MAX, &op_O_MIN,
&op_DRUNK_WRAP, &op_FLIP, &op_I, &op_J, &op_K, &op_O, &op_O_INC, &op_O_MAX, &op_O_MIN,
&op_O_WRAP, &op_T, &op_TIME, &op_TIME_ACT, &op_LAST, &op_X, &op_Y, &op_Z,

// init
Expand Down
2 changes: 2 additions & 0 deletions src/ops/op_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ typedef enum {
E_OP_DRUNK_WRAP,
E_OP_FLIP,
E_OP_I,
E_OP_J,
E_OP_K,
E_OP_O,
E_OP_O_INC,
E_OP_O_MAX,
Expand Down
30 changes: 30 additions & 0 deletions src/ops/variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ static void op_I_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_I_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_J_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_J_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_K_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_K_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_TIME_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_TIME_set(const void *data, scene_state_t *ss, exec_state_t *es,
Expand Down Expand Up @@ -59,6 +67,8 @@ const tele_op_t op_DRUNK = MAKE_GET_SET_OP(DRUNK, op_DRUNK_get, op_DRUNK_set, 0,
const tele_op_t op_FLIP = MAKE_GET_SET_OP(FLIP , op_FLIP_get , op_FLIP_set , 0, true);
const tele_op_t op_O = MAKE_GET_SET_OP(O , op_O_get , op_O_set , 0, true);
const tele_op_t op_I = MAKE_GET_SET_OP(I , op_I_get, op_I_set, 0, true);
const tele_op_t op_J = MAKE_GET_SET_OP(J , op_J_get, op_J_set, 0, true);
const tele_op_t op_K = MAKE_GET_SET_OP(K , op_K_get, op_K_set, 0, true);
// clang-format on

static void op_TIME_get(const void *NOTUSED(data), scene_state_t *ss,
Expand Down Expand Up @@ -159,3 +169,23 @@ static void op_I_set(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
exec_state_t *es, command_state_t *cs) {
es_variables(es)->i = cs_pop(cs);
}

static void op_J_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
exec_state_t *es, command_state_t *cs) {
cs_push(cs, es_variables(es)->j);
}

static void op_J_set(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
exec_state_t *es, command_state_t *cs) {
es_variables(es)->j = cs_pop(cs);
}

static void op_K_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
exec_state_t *es, command_state_t *cs) {
cs_push(cs, es_variables(es)->k);
}

static void op_K_set(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
exec_state_t *es, command_state_t *cs) {
es_variables(es)->k = cs_pop(cs);
}
2 changes: 2 additions & 0 deletions src/ops/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern const tele_op_t op_DRUNK_MIN;
extern const tele_op_t op_DRUNK_WRAP;
extern const tele_op_t op_FLIP;
extern const tele_op_t op_I;
extern const tele_op_t op_J;
extern const tele_op_t op_K;
extern const tele_op_t op_O;
extern const tele_op_t op_O_INC;
extern const tele_op_t op_O_MAX;
Expand Down
6 changes: 6 additions & 0 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,16 @@ size_t es_push(exec_state_t *es) {
es->variables[es->exec_depth - 1].if_else_condition;
es->variables[es->exec_depth].i =
es->variables[es->exec_depth - 1].i;
es->variables[es->exec_depth].j =
es->variables[es->exec_depth - 1].j;
es->variables[es->exec_depth].k =
es->variables[es->exec_depth - 1].k;
}
else {
es->variables[es->exec_depth].if_else_condition = true;
es->variables[es->exec_depth].i = 0;
es->variables[es->exec_depth].j = 0;
es->variables[es->exec_depth].k = 0;
}
es->variables[es->exec_depth].breaking = false;
es->exec_depth += 1; // exec_depth = 1 at the root
Expand Down
6 changes: 5 additions & 1 deletion src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ typedef struct {
tele_command_t commands[DELAY_SIZE];
int16_t time[DELAY_SIZE];
uint8_t origin_script[DELAY_SIZE];
int16_t origin_i[DELAY_SIZE];
uint8_t count;
int16_t origin_i[DELAY_SIZE];
int16_t origin_j[DELAY_SIZE];
int16_t origin_k[DELAY_SIZE];
} scene_delay_t;

typedef struct {
Expand Down Expand Up @@ -299,6 +301,8 @@ void ss_reset_param_cal(scene_state_t *);
typedef struct {
bool if_else_condition;
int16_t i;
int16_t j;
int16_t k;
bool while_continue;
uint16_t while_depth;
bool breaking;
Expand Down
2 changes: 2 additions & 0 deletions src/teletype.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ void tele_tick(scene_state_t *ss, uint8_t time) {
es_variables(&es)->delayed = true;
es_variables(&es)->script_number = ss->delay.origin_script[i];
es_variables(&es)->i = ss->delay.origin_i[i];
es_variables(&es)->j = ss->delay.origin_j[i];
es_variables(&es)->k = ss->delay.origin_k[i];

run_script_with_exec_state(ss, &es, TEMP_SCRIPT);

Expand Down

0 comments on commit 4ffdd58

Please sign in to comment.