summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-07-22 16:49:08 +0900
committerYusuke Endoh <mame@ruby-lang.org>2022-07-22 23:10:24 +0900
commite763b1118ba1fada81d37da558f9d8e4da99f144 (patch)
tree2e1c85e7879eccbe211169a8510bc916ecba83f1
parentc7fd015d83740b3e758796f8c7d85cc64602f371 (diff)
Move enum definitions out of struct definition
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6169
-rw-r--r--include/ruby/io.h59
-rw-r--r--iseq.h43
-rw-r--r--ractor_core.h81
-rw-r--r--vm_core.h25
4 files changed, 107 insertions, 101 deletions
diff --git a/include/ruby/io.h b/include/ruby/io.h
index b5e33c1cf9..dc4c8becf6 100644
--- a/include/ruby/io.h
+++ b/include/ruby/io.h
@@ -98,6 +98,34 @@ PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t {
/** @alias{rb_io_buffer_t} */
typedef struct rb_io_buffer_t rb_io_buffer_t;
+/** Decomposed encoding flags (e.g. `"enc:enc2""`). */
+/*
+ * enc enc2 read action write action
+ * NULL NULL force_encoding(default_external) write the byte sequence of str
+ * e1 NULL force_encoding(e1) convert str.encoding to e1
+ * e1 e2 convert from e2 to e1 convert str.encoding to e2
+ */
+struct rb_io_enc_t {
+ /** Internal encoding. */
+ rb_encoding *enc;
+ /** External encoding. */
+ rb_encoding *enc2;
+ /**
+ * Flags.
+ *
+ * @see enum ::ruby_econv_flag_type
+ */
+ int ecflags;
+ /**
+ * Flags as Ruby hash.
+ *
+ * @internal
+ *
+ * This is set. But used from nowhere maybe?
+ */
+ VALUE ecopts;
+};
+
/** Ruby's IO, metadata and buffers. */
typedef struct rb_io_t {
@@ -141,36 +169,7 @@ typedef struct rb_io_t {
*/
VALUE tied_io_for_writing;
- /** Decomposed encoding flags (e.g. `"enc:enc2""`). */
- /*
- * enc enc2 read action write action
- * NULL NULL force_encoding(default_external) write the byte sequence of str
- * e1 NULL force_encoding(e1) convert str.encoding to e1
- * e1 e2 convert from e2 to e1 convert str.encoding to e2
- */
- struct rb_io_enc_t {
- /** Internal encoding. */
- rb_encoding *enc;
-
- /** External encoding. */
- rb_encoding *enc2;
-
- /**
- * Flags.
- *
- * @see enum ::ruby_econv_flag_type
- */
- int ecflags;
-
- /**
- * Flags as Ruby hash.
- *
- * @internal
- *
- * This is set. But used from nowhere maybe?
- */
- VALUE ecopts;
- } encs; /**< Decomposed encoding flags. */
+ struct rb_io_enc_t encs; /**< Decomposed encoding flags. */
/** Encoding converter used when reading from this IO. */
rb_econv_t *readconv;
diff --git a/iseq.h b/iseq.h
index 63991d95ff..062ed33d86 100644
--- a/iseq.h
+++ b/iseq.h
@@ -241,28 +241,29 @@ struct iseq_insn_info_entry {
rb_event_flag_t events;
};
+/*
+ * iseq type:
+ * CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
+ * use iseq as continuation.
+ *
+ * CATCH_TYPE_BREAK (iter):
+ * use iseq as key.
+ *
+ * CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
+ * CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
+ * NULL.
+ */
+enum catch_type {
+ CATCH_TYPE_RESCUE = INT2FIX(1),
+ CATCH_TYPE_ENSURE = INT2FIX(2),
+ CATCH_TYPE_RETRY = INT2FIX(3),
+ CATCH_TYPE_BREAK = INT2FIX(4),
+ CATCH_TYPE_REDO = INT2FIX(5),
+ CATCH_TYPE_NEXT = INT2FIX(6)
+};
+
struct iseq_catch_table_entry {
- enum catch_type {
- CATCH_TYPE_RESCUE = INT2FIX(1),
- CATCH_TYPE_ENSURE = INT2FIX(2),
- CATCH_TYPE_RETRY = INT2FIX(3),
- CATCH_TYPE_BREAK = INT2FIX(4),
- CATCH_TYPE_REDO = INT2FIX(5),
- CATCH_TYPE_NEXT = INT2FIX(6)
- } type;
-
- /*
- * iseq type:
- * CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
- * use iseq as continuation.
- *
- * CATCH_TYPE_BREAK (iter):
- * use iseq as key.
- *
- * CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
- * CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
- * NULL.
- */
+ enum catch_type type;
rb_iseq_t *iseq;
unsigned int start;
diff --git a/ractor_core.h b/ractor_core.h
index dd1b73b331..b35a59e9c5 100644
--- a/ractor_core.h
+++ b/ractor_core.h
@@ -40,6 +40,24 @@ struct rb_ractor_waiting_list {
rb_ractor_t **ractors;
};
+enum ractor_wait_status {
+ wait_none = 0x00,
+ wait_receiving = 0x01,
+ wait_taking = 0x02,
+ wait_yielding = 0x04,
+ wait_moving = 0x08,
+};
+
+enum ractor_wakeup_status {
+ wakeup_none,
+ wakeup_by_send,
+ wakeup_by_yield,
+ wakeup_by_take,
+ wakeup_by_close,
+ wakeup_by_interrupt,
+ wakeup_by_retry,
+};
+
struct rb_ractor_sync {
// ractor lock
rb_nativethread_lock_t lock;
@@ -56,29 +74,34 @@ struct rb_ractor_sync {
bool outgoing_port_closed;
struct ractor_wait {
- enum ractor_wait_status {
- wait_none = 0x00,
- wait_receiving = 0x01,
- wait_taking = 0x02,
- wait_yielding = 0x04,
- wait_moving = 0x08,
- } status;
-
- enum ractor_wakeup_status {
- wakeup_none,
- wakeup_by_send,
- wakeup_by_yield,
- wakeup_by_take,
- wakeup_by_close,
- wakeup_by_interrupt,
- wakeup_by_retry,
- } wakeup_status;
-
+ enum ractor_wait_status status;
+ enum ractor_wakeup_status wakeup_status;
struct rb_ractor_basket yielded_basket;
struct rb_ractor_basket taken_basket;
} wait;
};
+// created
+// | ready to run
+// ====================== inserted to vm->ractor
+// v
+// blocking <---+ all threads are blocking
+// | |
+// v |
+// running -----+
+// | all threads are terminated.
+// ====================== removed from vm->ractor
+// v
+// terminated
+//
+// status is protected by VM lock (global state)
+enum ractor_status {
+ ractor_created,
+ ractor_running,
+ ractor_blocking,
+ ractor_terminated,
+};
+
struct rb_ractor_struct {
struct rb_ractor_pub pub;
@@ -104,27 +127,7 @@ struct rb_ractor_struct {
VALUE name;
VALUE loc;
- // created
- // | ready to run
- // ====================== inserted to vm->ractor
- // v
- // blocking <---+ all threads are blocking
- // | |
- // v |
- // running -----+
- // | all threads are terminated.
- // ====================== removed from vm->ractor
- // v
- // terminated
- //
- // status is protected by VM lock (global state)
-
- enum ractor_status {
- ractor_created,
- ractor_running,
- ractor_blocking,
- ractor_terminated,
- } status_;
+ enum ractor_status status_;
struct ccan_list_node vmlr_node;
diff --git a/vm_core.h b/vm_core.h
index 025dc76798..82a4af0e5c 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -339,18 +339,21 @@ typedef uintptr_t iseq_bits_t;
#define ISEQ_IS_SIZE(body) (body->ic_size + body->ivc_size + body->ise_size + body->icvarc_size)
+/* instruction sequence type */
+enum iseq_type {
+ ISEQ_TYPE_TOP,
+ ISEQ_TYPE_METHOD,
+ ISEQ_TYPE_BLOCK,
+ ISEQ_TYPE_CLASS,
+ ISEQ_TYPE_RESCUE,
+ ISEQ_TYPE_ENSURE,
+ ISEQ_TYPE_EVAL,
+ ISEQ_TYPE_MAIN,
+ ISEQ_TYPE_PLAIN
+};
+
struct rb_iseq_constant_body {
- enum iseq_type {
- ISEQ_TYPE_TOP,
- ISEQ_TYPE_METHOD,
- ISEQ_TYPE_BLOCK,
- ISEQ_TYPE_CLASS,
- ISEQ_TYPE_RESCUE,
- ISEQ_TYPE_ENSURE,
- ISEQ_TYPE_EVAL,
- ISEQ_TYPE_MAIN,
- ISEQ_TYPE_PLAIN
- } type; /* instruction sequence type */
+ enum iseq_type type;
unsigned int iseq_size;
VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */