mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-24 12:44:59 -07:00
eval expressions: unary +, correctly lex exponentiated numerics
This commit is contained in:
@@ -696,27 +696,28 @@ f64_from_str8(String8 string)
|
||||
{
|
||||
// rjf: find starting pos of numeric string, as well as sign
|
||||
F64 sign = +1.0;
|
||||
//U64 first_numeric = 0;
|
||||
if(string.str[0] == '-')
|
||||
{
|
||||
//first_numeric = 1;
|
||||
sign = -1.0;
|
||||
}
|
||||
else if(string.str[0] == '+')
|
||||
{
|
||||
//first_numeric = 1;
|
||||
sign = 1.0;
|
||||
}
|
||||
|
||||
// rjf: gather numerics
|
||||
U64 num_valid_chars = 0;
|
||||
char buffer[64];
|
||||
B32 exp = 0;
|
||||
for(U64 idx = 0; idx < string.size && num_valid_chars < sizeof(buffer)-1; idx += 1)
|
||||
{
|
||||
if(char_is_digit(string.str[idx], 10) || string.str[idx] == '.')
|
||||
if(char_is_digit(string.str[idx], 10) || string.str[idx] == '.' || string.str[idx] == 'e' ||
|
||||
(exp && (string.str[idx] == '+' || string.str[idx] == '-')))
|
||||
{
|
||||
buffer[num_valid_chars] = string.str[idx];
|
||||
num_valid_chars += 1;
|
||||
exp = 0;
|
||||
exp = (string.str[idx] == 'e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ E_ExprKindTable:
|
||||
{ Typeof UnaryPrefix 1 "typeof" "typeof" "(" ")"}
|
||||
{ ByteSwap UnaryPrefix 1 "bswap" "bswap" "(" ")"}
|
||||
|
||||
{ Pos UnaryPrefix 2 "+" "+" "" "" }
|
||||
{ Neg UnaryPrefix 2 "-" "-" "" "" }
|
||||
{ LogNot UnaryPrefix 2 "!" "!" "" "" }
|
||||
{ BitNot UnaryPrefix 2 "~" "~" "" "" }
|
||||
|
||||
@@ -846,6 +846,10 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
|
||||
}break;
|
||||
|
||||
//- rjf: unary operations
|
||||
case E_ExprKind_Pos:
|
||||
{
|
||||
result = e_irtree_and_type_from_expr(arena, expr->first);
|
||||
}break;
|
||||
case E_ExprKind_Neg:
|
||||
case E_ExprKind_LogNot:
|
||||
case E_ExprKind_BitNot:
|
||||
|
||||
@@ -389,6 +389,7 @@ e_token_array_from_text(Arena *arena, String8 text)
|
||||
E_TokenKind active_token_kind = E_TokenKind_Null;
|
||||
B32 active_token_kind_started_with_tick = 0;
|
||||
B32 escaped = 0;
|
||||
B32 exp = 0;
|
||||
for(U64 idx = 0, advance = 0; idx <= text.size; idx += advance)
|
||||
{
|
||||
U8 byte = (idx+0 < text.size) ? text.str[idx+0] : 0;
|
||||
@@ -486,11 +487,17 @@ e_token_array_from_text(Arena *arena, String8 text)
|
||||
}break;
|
||||
case E_TokenKind_Numeric:
|
||||
{
|
||||
if(!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '.' && byte != ':')
|
||||
if(exp && byte == '+' || byte == '-'){}
|
||||
else if(!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '.' && byte != ':')
|
||||
{
|
||||
advance = 0;
|
||||
token_formed = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
exp = 0;
|
||||
exp = (byte == 'e');
|
||||
}
|
||||
}break;
|
||||
case E_TokenKind_StringLiteral:
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ str8_lit_comp("CharLiteral"),
|
||||
str8_lit_comp("Symbol"),
|
||||
};
|
||||
|
||||
String8 e_expr_kind_strings[47] =
|
||||
String8 e_expr_kind_strings[48] =
|
||||
{
|
||||
str8_lit_comp("Nil"),
|
||||
str8_lit_comp("Ref"),
|
||||
@@ -26,6 +26,7 @@ str8_lit_comp("Cast"),
|
||||
str8_lit_comp("Sizeof"),
|
||||
str8_lit_comp("Typeof"),
|
||||
str8_lit_comp("ByteSwap"),
|
||||
str8_lit_comp("Pos"),
|
||||
str8_lit_comp("Neg"),
|
||||
str8_lit_comp("LogNot"),
|
||||
str8_lit_comp("BitNot"),
|
||||
@@ -80,7 +81,7 @@ str8_lit_comp("Insufficient evaluation machine stack space."),
|
||||
str8_lit_comp("Malformed bytecode."),
|
||||
};
|
||||
|
||||
E_OpInfo e_expr_kind_op_info_table[47] =
|
||||
E_OpInfo e_expr_kind_op_info_table[48] =
|
||||
{
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("") },
|
||||
@@ -92,6 +93,7 @@ E_OpInfo e_expr_kind_op_info_table[47] =
|
||||
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("sizeof"), str8_lit_comp("("), str8_lit_comp(")") },
|
||||
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("typeof"), str8_lit_comp("("), str8_lit_comp(")") },
|
||||
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("bswap"), str8_lit_comp("("), str8_lit_comp(")") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp("") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp("") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp("") },
|
||||
|
||||
@@ -101,6 +101,7 @@ E_ExprKind_Cast,
|
||||
E_ExprKind_Sizeof,
|
||||
E_ExprKind_Typeof,
|
||||
E_ExprKind_ByteSwap,
|
||||
E_ExprKind_Pos,
|
||||
E_ExprKind_Neg,
|
||||
E_ExprKind_LogNot,
|
||||
E_ExprKind_BitNot,
|
||||
@@ -159,9 +160,9 @@ E_InterpretationCode_COUNT,
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
extern String8 e_token_kind_strings[6];
|
||||
extern String8 e_expr_kind_strings[47];
|
||||
extern String8 e_expr_kind_strings[48];
|
||||
extern String8 e_interpretation_code_display_strings[11];
|
||||
extern E_OpInfo e_expr_kind_op_info_table[47];
|
||||
extern E_OpInfo e_expr_kind_op_info_table[48];
|
||||
extern U8 e_kind_basic_byte_size_table[56];
|
||||
extern String8 e_kind_basic_string_table[56];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user