diff options
author | John Hawthorn <[email protected]> | 2021-08-04 15:18:37 -0700 |
---|---|---|
committer | Alan Wu <[email protected]> | 2021-10-20 18:19:38 -0400 |
commit | 48dca3348ae47fec5f2fa39ae899cbf62f2fae44 (patch) | |
tree | 5d3f24d21579374da13b9a95ee4778ecc6b6cadd /yjit_core.c | |
parent | d78ea4abec1d030af2c5d99b03b3b4d959bd138c (diff) |
Move yjit_type_of_value into yjit_core.c
Diffstat (limited to 'yjit_core.c')
-rw-r--r-- | yjit_core.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/yjit_core.c b/yjit_core.c index 0d43129f01..a08be3cc74 100644 --- a/yjit_core.c +++ b/yjit_core.c @@ -284,6 +284,43 @@ void ctx_clear_local_types(ctx_t* ctx) memset(&ctx->local_types, 0, sizeof(ctx->local_types)); } + +/* This returns an appropriate val_type_t based on a known value */ +val_type_t +yjit_type_of_value(VALUE val) +{ + if (SPECIAL_CONST_P(val)) { + if (FIXNUM_P(val)) { + return TYPE_FIXNUM; + } else if (NIL_P(val)) { + return TYPE_NIL; + } else if (val == Qtrue) { + return TYPE_TRUE; + } else if (val == Qfalse) { + return TYPE_FALSE; + } else if (STATIC_SYM_P(val)) { + return TYPE_STATIC_SYMBOL; + } else if (FLONUM_P(val)) { + return TYPE_FLONUM; + } else { + RUBY_ASSERT(false); + UNREACHABLE_RETURN(TYPE_IMM); + } + } else { + switch (BUILTIN_TYPE(val)) { + case T_ARRAY: + return TYPE_ARRAY; + case T_HASH: + return TYPE_HASH; + case T_STRING: + return TYPE_STRING; + default: + // generic heap object + return TYPE_HEAP; + } + } +} + /* The name of a type, for debugging */ const char * yjit_type_name(val_type_t type) |