Skip to content

Commit

Permalink
vm: keep constate state throughout the function
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Dec 21, 2024
1 parent 608c9cf commit 53cb1e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void action_exec ( GtkWidget *widget, action_t *action,
action_t *caction;*/

if(action && action->code)
vm_run_action(action->code, widget, event);
vm_run_action(action->code, widget, event, istate);
// vm_run_action((gchar *)action->id, action->addr->definition,
// action->command->definition, widget, event, action->cond, action->ncond);

Expand Down
25 changes: 10 additions & 15 deletions src/actionlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,24 @@ static value_t action_exec_impl ( vm_t *vm, value_t p[], gint np )

static value_t action_function ( vm_t *vm, value_t p[], gint np )
{
GtkWidget *widget, *saved_widget = vm->widget;
window_t *saved_window = vm->win;
guint16 saved_state = vm->wstate;
GtkWidget *widget = NULL;
window_t *win;
guint16 state;

vm_param_check_np_range(vm, np, 1, 2, "Function");
vm_param_check_string(vm, p, 0, "Function");

if(np==2)
{
vm_param_check_string(vm, p, 1, "Function");
if( (widget = base_widget_from_id(value_get_string(p[0]))) )
{
vm->widget = widget;
if(IS_TASKBAR_ITEM(widget))
vm->win = flow_item_get_source(widget);
vm->wstate = action_state_build(vm->widget, vm->win);
}
widget = base_widget_from_id(value_get_string(p[0]));
}

action_function_exec(value_get_string(p[np-1]), vm->widget, vm->event, vm->win, &vm->wstate);
widget = widget? widget : vm->widget;
win = IS_TASKBAR_ITEM(widget)? flow_item_get_source(widget) : vm->win;
state = action_state_build(vm->widget, vm->win);

vm->widget = saved_widget;
vm->win = saved_window;
vm->wstate = saved_state;
action_function_exec(value_get_string(p[np-1]), widget, vm->event, win, &state);

return value_na;
}
Expand Down Expand Up @@ -571,7 +566,7 @@ static value_t action_check_state ( vm_t *vm, value_t p[], gint np )

cond = (guint16)value_get_numeric(p[0]) & ~WS_CHILDREN;
ncond = (guint16)value_get_numeric(p[1]) & ~WS_CHILDREN;

if(((cond & 0x0f) || (ncond & 0x0f)) && !vm->win)
return value_new_numeric(FALSE);
if(((cond & 0xf0) || (ncond & 0xf0)) && !vm->widget )
Expand Down
6 changes: 4 additions & 2 deletions src/vm/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ static value_t vm_run ( vm_t *vm )
return value_na;
if(IS_TASKBAR_ITEM(vm->widget))
vm->win = flow_item_get_source(vm->widget);
vm->wstate = action_state_build(vm->widget, vm->win);

if(!vm->stack)
vm->stack = g_array_sized_new(FALSE, FALSE, sizeof(value_t),
Expand Down Expand Up @@ -279,13 +278,15 @@ value_t vm_expr_eval ( expr_cache_t *expr )
vm->widget = expr->widget;
vm->event = expr->event;
vm->expr = expr;
vm->wstate = action_state_build(vm->widget, vm->win);

vm_run(vm);

return vm_free(vm);
}

void vm_run_action ( GBytes *code, GtkWidget *widget, GdkEvent *event )
void vm_run_action ( GBytes *code, GtkWidget *widget, GdkEvent *event,
guint16 *state )
{
value_t v1;
vm_t *vm;
Expand All @@ -294,6 +295,7 @@ void vm_run_action ( GBytes *code, GtkWidget *widget, GdkEvent *event )
vm->code = (gpointer)g_bytes_get_data(code, &vm->len);
vm->widget = widget;
vm->event = event;
vm->wstate = state? *state : action_state_build(vm->widget, vm->win);

vm_run(vm);
v1 = vm_free(vm);
Expand Down
2 changes: 1 addition & 1 deletion src/vm/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gboolean parser_expr_parse ( GScanner *scanner, GByteArray *code );
gboolean parser_macro_add ( GScanner *scanner );
const gchar *parser_identifier_lookup ( gchar *identifier );
value_t vm_expr_eval ( expr_cache_t *expr );
void vm_run_action ( GBytes *code, GtkWidget *widget, GdkEvent *event );
void vm_run_action ( GBytes *code, GtkWidget *w, GdkEvent *e, guint16 *s);
gchar *expr_vm_result_to_string ( vm_t *vm );
gint expr_vm_get_func_params ( vm_t *vm, value_t *params[] );

Expand Down

0 comments on commit 53cb1e0

Please sign in to comment.