diff --git a/src/actionlib.c b/src/actionlib.c index b106ab4..840a1a6 100644 --- a/src/actionlib.c +++ b/src/actionlib.c @@ -298,15 +298,18 @@ static value_t action_setbarvisibility ( vm_t *vm, value_t p[], gint np ) static value_t action_setvalue ( vm_t *vm, value_t p[], gint np ) { GtkWidget *widget; + guint8 *mark; vm_param_check_np_range(vm, np, 1, 2, "SetValue"); vm_param_check_string(vm, p, 0, "SetValue"); - if(!vm->mark) + if(!vm->pstack->len) return value_na; + mark = vm->pstack->pdata[vm->pstack->len-1]; + if( (widget = np==2?base_widget_from_id(value_get_string(p[0])):vm->widget) ) - base_widget_set_value(widget, vm->mark+1, vm->ip-vm->mark-1); + base_widget_set_value(widget, mark, vm->ip - mark); return value_na; } @@ -314,15 +317,18 @@ static value_t action_setvalue ( vm_t *vm, value_t p[], gint np ) static value_t action_setstyle ( vm_t *vm, value_t p[], gint np ) { GtkWidget *widget; + guint8 *mark; vm_param_check_np_range(vm, np, 1, 2, "SetValue"); vm_param_check_string(vm, p, 0, "SetValue"); - if(!vm->mark) + if(!vm->pstack->len) return value_na; + mark = vm->pstack->pdata[vm->pstack->len-1]; + if( (widget = np==2?base_widget_from_id(value_get_string(p[0])):vm->widget) ) - base_widget_set_style(widget, vm->mark+1, vm->ip-vm->mark-1); + base_widget_set_style(widget, mark, vm->ip - mark); return value_na; } @@ -330,15 +336,18 @@ static value_t action_setstyle ( vm_t *vm, value_t p[], gint np ) static value_t action_settooltip ( vm_t *vm, value_t p[], gint np ) { GtkWidget *widget; + guint8 *mark; vm_param_check_np_range(vm, np, 1, 2, "SetValue"); vm_param_check_string(vm, p, 0, "SetValue"); - if(!vm->mark) + if(!vm->pstack->len) return value_na; + mark = vm->pstack->pdata[vm->pstack->len-1]; + if( (widget = np==2?base_widget_from_id(value_get_string(p[0])):vm->widget) ) - base_widget_set_style(widget, vm->mark+1, vm->ip-vm->mark-1); + base_widget_set_tooltip(widget, mark, vm->ip - mark); return value_na; } diff --git a/src/vm/parser.c b/src/vm/parser.c index d0357f1..ee6a721 100644 --- a/src/vm/parser.c +++ b/src/vm/parser.c @@ -2,7 +2,6 @@ #include "util/string.h" #include "vm/vm.h" -static guint8 mark = EXPR_OP_MARK; static GHashTable *macros; static gint parser_emit_jump ( GByteArray *code, guint8 op ) @@ -135,7 +134,6 @@ static gboolean parser_function ( GScanner *scanner, GByteArray *code ) if(g_scanner_peek_next_token(scanner)!=')') do { - g_byte_array_append(code, &mark, 1); if(!parser_expr_parse(scanner, code)) return FALSE; np++; @@ -402,7 +400,6 @@ GByteArray *parser_action_compat ( gchar *action, gchar *expr1, gchar *expr2, { scanner = parser_scanner_new(); g_scanner_input_text(scanner, expr1, strlen(expr1)); - g_byte_array_append(code, &mark, 1); if(!parser_expr_parse(scanner, code)) { g_byte_array_free(code, TRUE); @@ -415,7 +412,6 @@ GByteArray *parser_action_compat ( gchar *action, gchar *expr1, gchar *expr2, { scanner = parser_scanner_new(); g_scanner_input_text(scanner, expr2, strlen(expr2)); - g_byte_array_append(code, &mark, 1); if(!parser_expr_parse(scanner, code)) { g_byte_array_free(code, TRUE); diff --git a/src/vm/vm.c b/src/vm/vm.c index d15962d..05d6e18 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -93,6 +93,7 @@ static gboolean vm_op_binary ( vm_t *vm ) vm_push(vm, result); value_free(v1); value_free(v2); + g_ptr_array_remove_index(vm->pstack, vm->pstack->len-1); return TRUE; } @@ -191,6 +192,10 @@ static gboolean vm_function ( vm_t *vm ) vm->expr->vstate = TRUE; } expr_dep_add(name, vm->expr); + if(np>1) + g_ptr_array_remove_range(vm->pstack, vm->pstack->len-np+1, np-1); + else if(!np) + g_ptr_array_add(vm->pstack, vm->ip); vm->ip += sizeof(gpointer)+1; for(i=0; iexpr); vm_push(vm, value); + g_ptr_array_add(vm->pstack, vm->ip); vm->ip += sizeof(gpointer); } @@ -220,6 +226,7 @@ static void vm_immediate ( vm_t *vm ) { value_t v1; + g_ptr_array_add(vm->pstack, vm->ip); if(*(vm->ip+1) != EXPR_TYPE_STRING) { memcpy(&v1, vm->ip+1, sizeof(value_t)); @@ -247,7 +254,10 @@ static value_t vm_run ( vm_t *vm ) if(!vm->stack) vm->stack = g_array_sized_new(FALSE, FALSE, sizeof(value_t), - MAX(1, vm->expr?vm->expr->stack_depth:1)); + MAX(1, vm->expr? vm->expr->stack_depth : 1)); + if(!vm->pstack) + vm->pstack = g_ptr_array_sized_new( + MAX(1, vm->expr? vm->expr->stack_depth: 1)); for(vm->ip = vm->code; (vm->ip-vm->code)len; vm->ip++) { @@ -260,8 +270,6 @@ static value_t vm_run ( vm_t *vm ) vm_variable(vm); else if(*vm->ip == EXPR_OP_FUNCTION) vm_function(vm); - else if(*vm->ip == EXPR_OP_MARK) - vm->mark = vm->ip; else if(*vm->ip == EXPR_OP_JMP) { memcpy(&jmp, vm->ip+1, sizeof(gint)); @@ -269,6 +277,7 @@ static value_t vm_run ( vm_t *vm ) } else if(*vm->ip == EXPR_OP_JZ) { + g_ptr_array_remove_index(vm->pstack, vm->pstack->len-1); v1 = vm_pop(vm); if(!value_is_numeric(v1) || !v1.value.numeric) { @@ -320,6 +329,7 @@ static value_t vm_free ( vm_t *vm ) vm->expr->stack_depth = MAX(vm->expr->stack_depth, vm->max_stack); g_array_unref(vm->stack); + g_ptr_array_free(vm->pstack, TRUE); g_free(vm); return v1; diff --git a/src/vm/vm.h b/src/vm/vm.h index 89790d8..f0c501b 100644 --- a/src/vm/vm.h +++ b/src/vm/vm.h @@ -12,16 +12,15 @@ enum expr_instruction_t { EXPR_OP_JMP, EXPR_OP_CACHED, EXPR_OP_VARIABLE, - EXPR_OP_FUNCTION, - EXPR_OP_MARK + EXPR_OP_FUNCTION }; typedef struct { guint8 *ip; guint8 *code; - guint8 *mark; gsize len; GArray *stack; + GPtrArray *pstack; gint max_stack; gboolean use_cached; guint16 wstate;