Skip to content

Commit

Permalink
Merge pull request #2708 from ruby/simplify
Browse files Browse the repository at this point in the history
Inline pm_state_stack
  • Loading branch information
kddnewton authored Apr 17, 2024
2 parents f9a1abb + 7aadaa5 commit bf02281
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 70 deletions.
6 changes: 5 additions & 1 deletion include/prism/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "prism/util/pm_constant_pool.h"
#include "prism/util/pm_list.h"
#include "prism/util/pm_newline_list.h"
#include "prism/util/pm_state_stack.h"
#include "prism/util/pm_string.h"

#include <stdbool.h>
Expand Down Expand Up @@ -612,6 +611,11 @@ static const uint8_t PM_SCOPE_PARAMETERS_FORWARDING_ALL = 0x40;
static const int8_t PM_SCOPE_NUMBERED_PARAMETERS_DISALLOWED = -1;
static const int8_t PM_SCOPE_NUMBERED_PARAMETERS_NONE = 0;

/**
* A struct that represents a stack of boolean values.
*/
typedef uint32_t pm_state_stack_t;

/**
* This struct represents the overall parser. It contains a reference to the
* source file, as well as pointers that indicate where in the source it's
Expand Down
42 changes: 0 additions & 42 deletions include/prism/util/pm_state_stack.h

This file was deleted.

2 changes: 0 additions & 2 deletions prism.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Gem::Specification.new do |spec|
"include/prism/util/pm_list.h",
"include/prism/util/pm_memchr.h",
"include/prism/util/pm_newline_list.h",
"include/prism/util/pm_state_stack.h",
"include/prism/util/pm_strncasecmp.h",
"include/prism/util/pm_string.h",
"include/prism/util/pm_string_list.h",
Expand Down Expand Up @@ -117,7 +116,6 @@ Gem::Specification.new do |spec|
"src/util/pm_list.c",
"src/util/pm_memchr.c",
"src/util/pm_newline_list.c",
"src/util/pm_state_stack.c",
"src/util/pm_string.c",
"src/util/pm_string_list.c",
"src/util/pm_strncasecmp.c",
Expand Down
24 changes: 24 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -7632,6 +7632,30 @@ pm_parser_scope_pop(pm_parser_t *parser) {
/* Stack helpers */
/******************************************************************************/

/**
* Pushes a value onto the stack.
*/
static inline void
pm_state_stack_push(pm_state_stack_t *stack, bool value) {
*stack = (*stack << 1) | (value & 1);
}

/**
* Pops a value off the stack.
*/
static inline void
pm_state_stack_pop(pm_state_stack_t *stack) {
*stack >>= 1;
}

/**
* Returns the value at the top of the stack.
*/
static inline bool
pm_state_stack_p(const pm_state_stack_t *stack) {
return *stack & 1;
}

static inline void
pm_accepts_block_stack_push(pm_parser_t *parser, bool value) {
// Use the negation of the value to prevent stack overflow.
Expand Down
25 changes: 0 additions & 25 deletions src/util/pm_state_stack.c

This file was deleted.

0 comments on commit bf02281

Please sign in to comment.