Skip to content

Commit

Permalink
vm: implement <= and >= in parser, fix vm implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Dec 15, 2024
1 parent ac993fb commit bf76d13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/vm/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ static gboolean parser_value ( GScanner *scanner, GByteArray *code )
static gboolean parser_ops ( GScanner *scanner, GByteArray *code, gint l )
{
static gchar *expr_ops_list[] = { "&|", "!<>=", "+-", "*/%", NULL };
static const gchar *ne = "=!";
static const guchar *ne = (guchar *)"=!", equal = '=';
gboolean or_equal;
guchar op;

if(!expr_ops_list[l])
Expand All @@ -237,6 +238,7 @@ static gboolean parser_ops ( GScanner *scanner, GByteArray *code, gint l )
return FALSE;
while(strchr(expr_ops_list[l], g_scanner_peek_next_token(scanner)))
{
or_equal = FALSE;
if(g_scanner_eof(scanner))
return TRUE;
if( !(op = g_scanner_get_next_token(scanner)) )
Expand All @@ -247,13 +249,21 @@ static gboolean parser_ops ( GScanner *scanner, GByteArray *code, gint l )
else if(op=='!')
g_scanner_get_next_token(scanner);

if((op=='>' || op=='<') && g_scanner_peek_next_token(scanner)=='=')
{
or_equal = TRUE;
g_scanner_get_next_token(scanner);
}
if(!parser_ops(scanner, code, l+1))
return FALSE;

if(op!='!')
g_byte_array_append(code, &op, 1);
else
g_byte_array_append(code, (guchar *)ne, 2);
g_byte_array_append(code, ne, 2);

if(or_equal)
g_byte_array_append(code, &equal, 1);
}
return TRUE;
}
Expand Down
5 changes: 3 additions & 2 deletions src/vm/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ static gboolean vm_op_binary ( vm_t *vm )
else
result= value_na;

if(!value_get_numeric(result) && (op=='<' || op=='>') && *(vm->ip+1)=='=')
if((op=='<' || op=='>') && *(vm->ip+1)=='=')
{
result = value_new_numeric(value_get_numeric(v1)==value_get_numeric(v2));
vm->ip++;
result.value.numeric = value_get_numeric(result) ||
(value_get_numeric(v1)==value_get_numeric(v2));
}
}

Expand Down

0 comments on commit bf76d13

Please sign in to comment.