Skip to content

Commit

Permalink
Move expression implementation to its own folder
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Nov 22, 2024
1 parent 3223fa8 commit dad8d60
Show file tree
Hide file tree
Showing 9 changed files with 12,212 additions and 12,200 deletions.
24,384 changes: 12,195 additions & 12,189 deletions distr/flecs.c

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "flecs.h"

#ifdef FLECS_SCRIPT
#include "script.h"
#include "../script.h"

#define flecs_expr_ast_new(parser, T, kind)\
(T*)flecs_expr_ast_new_(parser, ECS_SIZEOF(T), kind)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @file addons/script/expr.c
* @file addons/script/expr/parser.c
* @brief Script expression parser.
*/

#include "flecs.h"

#ifdef FLECS_SCRIPT
#include "script.h"
#include "parser.h"
#include "../script.h"
#include "../parser.h"

/* From https://en.cppreference.com/w/c/language/operator_precedence */

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "flecs.h"

#ifdef FLECS_SCRIPT
#include "script.h"
#include "../script.h"

#define ECS_VALUE_GET(value, T) (*(T*)((ecs_expr_val_t*)value)->ptr)

Expand Down Expand Up @@ -103,7 +103,7 @@ int flecs_expr_unary_visit_fold(
return 0;
}

if (node->node.type != ecs_id(ecs_bool_t)) {
if (node->expr->type != ecs_id(ecs_bool_t)) {
char *type_str = ecs_get_path(script->world, node->node.type);
flecs_expr_visit_error(script, node,
"! operator cannot be applied to value of type '%s' (must be bool)");
Expand All @@ -117,7 +117,9 @@ int flecs_expr_unary_visit_fold(
result->node.pos = node->node.pos;
result->node.type = ecs_id(ecs_bool_t);
result->ptr = &result->storage.bool_;
*(bool*)result->ptr = !(*(bool*)((ecs_expr_val_t*)node)->ptr);
*(bool*)result->ptr = !*(bool*)(((ecs_expr_val_t*)node->expr)->ptr);

*node_ptr = (ecs_expr_node_t*)result;

return 0;
error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "flecs.h"

#ifdef FLECS_SCRIPT
#include "script.h"
#include "../script.h"

typedef struct ecs_expr_str_visitor_t {
const ecs_world_t *world;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "flecs.h"

#ifdef FLECS_SCRIPT
#include "script.h"
#include "../script.h"

static
bool flecs_expr_operator_is_equality(
Expand Down Expand Up @@ -249,6 +249,10 @@ int flecs_expr_unary_visit_type(
/* The only supported unary expression is not (!) which returns a bool */
node->node.type = ecs_id(ecs_bool_t);

if (node->expr->type != ecs_id(ecs_bool_t)) {
node->expr = flecs_expr_cast(script, node->expr, ecs_id(ecs_bool_t));
}

return 0;
error:
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/addons/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ struct ecs_script_parser_t {
};

#include "ast.h"
#include "expr_ast.h"
#include "expr_visit.h"
#include "expr/ast.h"
#include "expr/visit.h"
#include "visit.h"
#include "visit_eval.h"

Expand Down

0 comments on commit dad8d60

Please sign in to comment.