calculator.c
branchcalculator-experiment
changeset 826 59a6a8aa7d87
parent 825 1ec9b7cc9434
equal deleted inserted replaced
825:1ec9b7cc9434 826:59a6a8aa7d87
   223     retval->center = center;
   223     retval->center = center;
   224     retval->right = right;
   224     retval->right = right;
   225     return (Expression *) retval;
   225     return (Expression *) retval;
   226 } // new_ternary_expr
   226 } // new_ternary_expr
   227 
   227 
   228 static Expression *new_identifier_expr(Context *ctx, const TokenData *data)
   228 static Expression *new_identifier_expr(Context *ctx, const char *string)
   229 {
   229 {
   230     NEW_EXPR(ExpressionIdentifier);
   230     NEW_EXPR(ExpressionIdentifier);
   231     retval->op = OP_IDENTIFIER;
   231     retval->op = OP_IDENTIFIER;
   232     retval->identifier = data->string;  // cached; don't copy string.
   232     retval->identifier = string;  // cached; don't copy string!
   233     return (Expression *) retval;
   233     return (Expression *) retval;
   234 } // new_identifier_expr
   234 } // new_identifier_expr
   235 
   235 
   236 static inline int64 strtoi64(const char *str, unsigned int len)
   236 static inline int64 strtoi64(const char *str, unsigned int len)
   237 {
   237 {
   268     } // while
   268     } // while
   269 
   269 
   270     return retval;
   270     return retval;
   271 } // strtoi64
   271 } // strtoi64
   272 
   272 
   273 static Expression *new_literal_int_expr(Context *ctx, const TokenData *data)
   273 static Expression *new_literal_int_expr(Context *ctx, const int64 value)
   274 {
   274 {
   275     NEW_EXPR(ExpressionIntLiteral);
   275     NEW_EXPR(ExpressionIntLiteral);
   276     retval->op = OP_INT_LITERAL;
   276     retval->op = OP_INT_LITERAL;
   277     retval->value = data->i64;
   277     retval->value = value;
   278     return (Expression *) retval;
   278     return (Expression *) retval;
   279 } // new_literal_int_expr
   279 } // new_literal_int_expr
   280 
   280 
   281 static inline double strtodouble(const char *_str, unsigned int len)
   281 static inline double strtodouble(const char *_str, unsigned int len)
   282 {
   282 {
   285     memcpy(str, _str, len);
   285     memcpy(str, _str, len);
   286     str[len] = '\0';
   286     str[len] = '\0';
   287     return strtod(str, NULL);
   287     return strtod(str, NULL);
   288 } // strtodouble
   288 } // strtodouble
   289 
   289 
   290 static Expression *new_literal_float_expr(Context *ctx, const TokenData *data)
   290 static Expression *new_literal_float_expr(Context *ctx, const double value)
   291 {
   291 {
   292     NEW_EXPR(ExpressionFloatLiteral);
   292     NEW_EXPR(ExpressionFloatLiteral);
   293     retval->op = OP_FLOAT_LITERAL;
   293     retval->op = OP_FLOAT_LITERAL;
   294     retval->value = data->dbl;
   294     retval->value = value;
   295     return (Expression *) retval;
   295     return (Expression *) retval;
   296 } // new_literal_float_expr
   296 } // new_literal_float_expr
   297 
   297 
   298 static Expression *new_literal_string_expr(Context *ctx, const TokenData *data)
   298 static Expression *new_literal_string_expr(Context *ctx, const char *string)
   299 {
   299 {
   300     NEW_EXPR(ExpressionStringLiteral);
   300     NEW_EXPR(ExpressionStringLiteral);
   301     retval->op = OP_STRING_LITERAL;
   301     retval->op = OP_STRING_LITERAL;
   302     retval->string = data->string;  // cached; don't copy string.
   302     retval->string = string;  // cached; don't copy string!
   303     return (Expression *) retval;
   303     return (Expression *) retval;
   304 } // new_string_literal_expr
   304 } // new_string_literal_expr
   305 
   305 
   306 static void print_expr(const Expression *expr, const int depth)
   306 static void print_expr(const Expression *expr, const int depth)
   307 {
   307 {