Class: JIT::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/jit/value.rb,
ext/jit_ext.c

Direct Known Subclasses

Array::Instance, Pointer::Instance

Defined Under Namespace

Modules: UNINITIALIZED

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(function, type, value = UNINITIALIZED) ⇒ Object

Create a new JIT::Value. If value is specified, the value will be variable, otherwise it will be a constant with the given value.

function

The function to which this value will belong.

type

The type of the new value.

value: The value to use, if this is a constant.



14
15
16
17
18
19
20
21
# File 'lib/jit/value.rb', line 14

def self.new(function, type, value=UNINITIALIZED)
  # TODO: Not sure if I like this...
  if value == UNINITIALIZED then
    return function.value(type)
  else
    return function.const(type, value)
  end
end

.new_value(function, type) ⇒ Object


Value




1166
1167
1168
1169
# File 'ext/jit_ext.c', line 1166

static VALUE value_s_new_value(VALUE klass, VALUE function, VALUE type)
{
  return function_value_klass(function, type, klass);
}

Instance Method Details

#%(rhs) ⇒ Object

Divide this value by another and return the remainder.

rhs

The right hand side of the modulus operator.



83
84
85
86
# File 'lib/jit/value.rb', line 83

def %(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_rem(lhs, rhs)
end

#&(rhs) ⇒ Object

Perform a bitwise and between this value and another.

rhs

The right hand side of the operator.



92
93
94
95
# File 'lib/jit/value.rb', line 92

def &(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_and(lhs, rhs)
end

#*(rhs) ⇒ Object

Multiply this value by another and return the result.

rhs

The right hand side of the multiplication operator.



59
60
61
62
# File 'lib/jit/value.rb', line 59

def *(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_mul(lhs, rhs)
end

#+(rhs) ⇒ Object

Add this value to another and return the result.

rhs

The right hand side of the addition operator.



41
42
43
44
# File 'lib/jit/value.rb', line 41

def +(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_add(lhs, rhs)
end

#-(rhs) ⇒ Object

Subtract another value from this one and return the result.

rhs

The right hand side of the subtraction operator.



50
51
52
53
# File 'lib/jit/value.rb', line 50

def -(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_sub(lhs, rhs)
end

#-@Object

Return the additive inverse (negation) of this value.



74
75
76
77
# File 'lib/jit/value.rb', line 74

def -@()
  rhs, lhs = coerce(0) # inverted, since we are subtracting from 0
  return lhs - rhs
end

#/(rhs) ⇒ Object

Divide this value by another and return the quotient.

rhs

The right hand side of the division operator.



68
69
70
71
# File 'lib/jit/value.rb', line 68

def /(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_div(lhs, rhs)
end

#<(rhs) ⇒ Object

Compare this value to another, returning 1 if the left hand is less than the right hand side or 0 otherwise.

rhs

The right hand side of the comparison.



120
121
122
123
# File 'lib/jit/value.rb', line 120

def <(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_lt(lhs, rhs)
end

#<<(rhs) ⇒ Object

Shift this value left by the given number of bits.

rhs

The number of bits to shift by.



179
180
181
182
# File 'lib/jit/value.rb', line 179

def <<(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_shl(lhs, rhs)
end

#<=(rhs) ⇒ Object

Compare this value to another, returning 1 if the left hand is less than or equal to the right hand side or 0 otherwise.

rhs

The right hand side of the comparison.



160
161
162
163
# File 'lib/jit/value.rb', line 160

def <=(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_le(lhs, rhs)
end

#==(rhs) ⇒ Object

Compare this value to another, returning 1 if the left hand is equal to the right hand side or 0 otherwise.

rhs

The right hand side of the comparison.



140
141
142
143
# File 'lib/jit/value.rb', line 140

def ==(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_eq(lhs, rhs)
end

#>(rhs) ⇒ Object

Compare this value to another, returning 1 if the left hand is greater than the right hand side or 0 otherwise.

rhs

The right hand side of the comparison.



130
131
132
133
# File 'lib/jit/value.rb', line 130

def >(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_gt(lhs, rhs)
end

#>=(rhs) ⇒ Object

Compare this value to another, returning 1 if the left hand is greater than or equal to the right hand side or 0 otherwise.

rhs

The right hand side of the comparison.



170
171
172
173
# File 'lib/jit/value.rb', line 170

def >=(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_ge(lhs, rhs)
end

#>>(rhs) ⇒ Object

Shift this value right by the given number of bits.

rhs

The number of bits to shift by.



188
189
190
191
# File 'lib/jit/value.rb', line 188

def >>(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_shr(lhs, rhs)
end

#^(rhs) ⇒ Object

Perform a bitwise xor between this value and another.

rhs

The right hand side of the operator.



110
111
112
113
# File 'lib/jit/value.rb', line 110

def ^(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_xor(lhs, rhs)
end

#addressObject

Return the address of this value.



33
34
35
# File 'lib/jit/value.rb', line 33

def address
  return self.function.insn_address_of(self)
end

#addressable=(is_addressable) ⇒ Object

Make a value addressable.



1318
1319
1320
1321
1322
1323
1324
# File 'ext/jit_ext.c', line 1318

static VALUE value_set_addressable(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  jit_value_set_addressable(value);
  return Qnil;
}

#is_addressable=(value) ⇒ Boolean

Determine if a value is addressable.

Returns:

  • (Boolean)


1305
1306
1307
1308
1309
1310
# File 'ext/jit_ext.c', line 1305

static VALUE value_is_addressable(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  return jit_value_is_addressable(value) ? Qtrue : Qfalse;
}

#value1Object

If the given value is a JIT::Value, return an [ self, value ], otherwise coerce the value to the same type as self and return [ self, coerced_value ].



1365
1366
1367
1368
1369
1370
1371
1372
1373
# File 'ext/jit_ext.c', line 1365

static VALUE value_coerce(VALUE self, VALUE value)
{
  return rb_assoc_new(
      self,
      coerce_to_jit(
          value_function(self),
          value_type(self),
          value));
}

#is_local=(value) ⇒ Boolean

Determine if a value represents a constant.

Returns:

  • (Boolean)


1263
1264
1265
1266
1267
1268
# File 'ext/jit_ext.c', line 1263

static VALUE value_is_constant(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  return jit_value_is_constant(value) ? Qtrue : Qfalse;
}

#function=(value) ⇒ Object

Get a value’s function.



1332
1333
1334
1335
1336
1337
1338
1339
# File 'ext/jit_ext.c', line 1332

static VALUE value_function(VALUE self)
{
  jit_value_t value;
  jit_function_t function;
  Data_Get_Struct(self, struct _jit_value, value);
  function = jit_value_get_function(value);
  return Data_Wrap_Struct(rb_cFunction, mark_function, 0, function);
}

#str=(value) ⇒ Object

Return a string representation of a value with additional information about the value.



1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'ext/jit_ext.c', line 1201

static VALUE value_inspect(VALUE self)
{
  jit_value_t value;
  jit_type_t type;
  char const * cname = rb_obj_classname(self);
  VALUE args[6];
  Data_Get_Struct(self, struct _jit_value, value);
  type = jit_value_get_type(value);
  args[0] = rb_str_new2("#<%s:0x%x %s ptr=0x%x type=0x%x>");
  args[1] = rb_str_new2(cname);
  args[2] = ULONG2NUM((unsigned long)self);
  args[3] = value_to_s(self);
  args[4] = ULONG2NUM((unsigned long)value);
  args[5] = ULONG2NUM((unsigned long)type);
  return rb_f_sprintf(sizeof(args)/sizeof(args[0]), args);
}

#is_local=(value) ⇒ Boolean

Determine if a value represents a local.

Returns:

  • (Boolean)


1250
1251
1252
1253
1254
1255
# File 'ext/jit_ext.c', line 1250

static VALUE value_is_local(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  return jit_value_is_local(value) ? Qtrue : Qfalse;
}

#neq(rhs) ⇒ Object

Compare this value to another, returning 1 if the left hand is not equal to the right hand side or 0 otherwise.

rhs

The right hand side of the comparison.



150
151
152
153
# File 'lib/jit/value.rb', line 150

def neq(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_ne(lhs, rhs)
end

#volatile=(is_volatile) ⇒ Object

Make a value volatile (that is, ensure that its contents are reloaded from memory each time it is used).



1291
1292
1293
1294
1295
1296
1297
# File 'ext/jit_ext.c', line 1291

static VALUE value_set_volatile(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  jit_value_set_volatile(value);
  return Qnil;
}

#store(value) ⇒ Object

Assign value to this JIT::Value.

value

The value to assign.



27
28
29
30
# File 'lib/jit/value.rb', line 27

def store(value)
  lhs, rhs = coerce(value)
  self.function.insn_store(lhs, rhs)
end

#is_temporary=(value) ⇒ Boolean

Determine if a value represents a temporary.

Returns:

  • (Boolean)


1237
1238
1239
1240
1241
1242
# File 'ext/jit_ext.c', line 1237

static VALUE value_is_temporary(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  return jit_value_is_temporary(value) ? Qtrue : Qfalse;
}

#str=(value) ⇒ Object

Return a string representation of the value.



1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
# File 'ext/jit_ext.c', line 1177

static VALUE value_to_s(VALUE self)
{
#ifdef HAVE_FMEMOPEN
  char buf[1024];
  FILE * fp = fmemopen(buf, sizeof(buf), "w");
  jit_value_t value;
  jit_function_t function;
  Data_Get_Struct(self, struct _jit_value, value);
  function = jit_value_get_function(value);
  jit_dump_value(fp, function, value, 0);
  fclose(fp);
  return rb_str_new2(buf);
#else
  rb_raise(rb_eNotImpError, "Not implemented: missing fmemopen");
#endif
}

#function=(value) ⇒ Object

Get a value’s type.



1347
1348
1349
1350
1351
1352
1353
1354
1355
# File 'ext/jit_ext.c', line 1347

static VALUE value_type(VALUE self)
{
  jit_value_t value;
  jit_type_t type;
  Data_Get_Struct(self, struct _jit_value, value);
  type = jit_value_get_type(value);
  type = jit_type_copy(type);
  return wrap_type(type);
}

#is_valid=(value) ⇒ Boolean

Determine if a value is valid (non-zero).

Returns:

  • (Boolean)


1224
1225
1226
1227
1228
1229
# File 'ext/jit_ext.c', line 1224

static VALUE value_is_valid(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  return (value != 0) ? Qtrue : Qfalse;
}

#volatile=(is_volatile) ⇒ Object

Make a value volatile (that is, ensure that its contents are reloaded from memory each time it is used).



1291
1292
1293
1294
1295
1296
1297
# File 'ext/jit_ext.c', line 1291

static VALUE value_set_volatile(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  jit_value_set_volatile(value);
  return Qnil;
}

#is_volatile=(value) ⇒ Boolean

Determine if a value is volatile (that is, the contents must be reloaded from memory each time it is used).

Returns:

  • (Boolean)


1277
1278
1279
1280
1281
1282
# File 'ext/jit_ext.c', line 1277

static VALUE value_is_volatile(VALUE self)
{
  jit_value_t value;
  Data_Get_Struct(self, struct _jit_value, value);
  return jit_value_is_volatile(value) ? Qtrue : Qfalse;
}

#|(rhs) ⇒ Object

Perform a bitwise or between this value and another.

rhs

The right hand side of the operator.



101
102
103
104
# File 'lib/jit/value.rb', line 101

def |(rhs)
  lhs, rhs = coerce(rhs)
  return self.function.insn_or(lhs, rhs)
end

#~Object

Return the logical inverse of this value.



194
195
196
# File 'lib/jit/value.rb', line 194

def ~()
  return self.function.insn_not(self)
end