[ruby/prism] Inline pm_state_stack

This commit is contained in:
Kevin Newton 2024-04-16 10:30:50 -04:00
parent 209e2f277e
commit f72436f835
5 changed files with 29 additions and 70 deletions

View File

@ -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",
@ -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",

View File

@ -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>
@ -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

View File

@ -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.

View File

@ -1,25 +0,0 @@
#include "prism/util/pm_state_stack.h"
/**
* Pushes a value onto the stack.
*/
void
pm_state_stack_push(pm_state_stack_t *stack, bool value) {
*stack = (*stack << 1) | (value & 1);
}
/**
* Pops a value off the stack.
*/
void
pm_state_stack_pop(pm_state_stack_t *stack) {
*stack >>= 1;
}
/**
* Returns the value at the top of the stack.
*/
bool
pm_state_stack_p(pm_state_stack_t *stack) {
return *stack & 1;
}

View File

@ -1,42 +0,0 @@
/**
* @file pm_state_stack.h
*
* A stack of boolean values.
*/
#ifndef PRISM_STATE_STACK_H
#define PRISM_STATE_STACK_H
#include "prism/defines.h"
#include <stdbool.h>
#include <stdint.h>
/**
* A struct that represents a stack of boolean values.
*/
typedef uint32_t pm_state_stack_t;
/**
* Pushes a value onto the stack.
*
* @param stack The stack to push the value onto.
* @param value The value to push onto the stack.
*/
void pm_state_stack_push(pm_state_stack_t *stack, bool value);
/**
* Pops a value off the stack.
*
* @param stack The stack to pop the value off of.
*/
void pm_state_stack_pop(pm_state_stack_t *stack);
/**
* Returns the value at the top of the stack.
*
* @param stack The stack to get the value from.
* @return The value at the top of the stack.
*/
bool pm_state_stack_p(pm_state_stack_t *stack);
#endif