An instance represents a value of the executed program.

Introduced properties

private var _mtype: MType

nitc :: Instance :: _mtype

The dynamic type of the instance
private var _vtable: nullable VTable

nitc :: Instance :: _vtable

Associate a runtime instance to its virtual table which contains methods, types etc.
init defaultinit(mtype: MType)

nitc :: Instance :: defaultinit

fun eq_is(o: Instance): Bool

nitc :: Instance :: eq_is

Return true if self IS o (using the Nit semantic of is)
fun is_null: Bool

nitc :: Instance :: is_null

Return true if the instance is null.
fun is_true: Bool

nitc :: Instance :: is_true

Return true if the instance is the true value.
fun mtype: MType

nitc :: Instance :: mtype

The dynamic type of the instance
protected fun mtype=(mtype: MType)

nitc :: Instance :: mtype=

The dynamic type of the instance
fun to_b: Byte

nitc :: Instance :: to_b

Return the integer value if the instance is a byte.
fun to_f: Float

nitc :: Instance :: to_f

Return the integer value if the instance is a float.
fun to_i: Int

nitc :: Instance :: to_i

Return the integer value if the instance is an integer.
fun to_i16: Int16

nitc :: Instance :: to_i16

Return the integer value if the instance is a int16.
fun to_i32: Int32

nitc :: Instance :: to_i32

Return the integer value if the instance is a int32.
fun to_i8: Int8

nitc :: Instance :: to_i8

Return the integer value if the instance is a int8.
fun to_u16: UInt16

nitc :: Instance :: to_u16

Return the integer value if the instance is a uint16.
fun to_u32: UInt32

nitc :: Instance :: to_u32

Return the integer value if the instance is a uint32.
fun val: nullable Object

nitc :: Instance :: val

The real value encapsulated if the instance is primitive.
fun vtable: nullable VTable

nitc :: Instance :: vtable

Associate a runtime instance to its virtual table which contains methods, types etc.
protected fun vtable=(vtable: nullable VTable)

nitc :: Instance :: vtable=

Associate a runtime instance to its virtual table which contains methods, types etc.

Redefined properties

redef type SELF: Instance

nitc $ Instance :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

nitc $ Instance :: to_s

Human readable object identity "Type#number"

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _mtype: MType

nitc :: Instance :: _mtype

The dynamic type of the instance
private var _vtable: nullable VTable

nitc :: Instance :: _vtable

Associate a runtime instance to its virtual table which contains methods, types etc.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(mtype: MType)

nitc :: Instance :: defaultinit

fun eq_is(o: Instance): Bool

nitc :: Instance :: eq_is

Return true if self IS o (using the Nit semantic of is)
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_null: Bool

nitc :: Instance :: is_null

Return true if the instance is null.
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun is_true: Bool

nitc :: Instance :: is_true

Return true if the instance is the true value.
fun mtype: MType

nitc :: Instance :: mtype

The dynamic type of the instance
protected fun mtype=(mtype: MType)

nitc :: Instance :: mtype=

The dynamic type of the instance
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_b: Byte

nitc :: Instance :: to_b

Return the integer value if the instance is a byte.
fun to_f: Float

nitc :: Instance :: to_f

Return the integer value if the instance is a float.
fun to_i: Int

nitc :: Instance :: to_i

Return the integer value if the instance is an integer.
fun to_i16: Int16

nitc :: Instance :: to_i16

Return the integer value if the instance is a int16.
fun to_i32: Int32

nitc :: Instance :: to_i32

Return the integer value if the instance is a int32.
fun to_i8: Int8

nitc :: Instance :: to_i8

Return the integer value if the instance is a int8.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun to_u16: UInt16

nitc :: Instance :: to_u16

Return the integer value if the instance is a uint16.
fun to_u32: UInt32

nitc :: Instance :: to_u32

Return the integer value if the instance is a uint32.
fun val: nullable Object

nitc :: Instance :: val

The real value encapsulated if the instance is primitive.
fun vtable: nullable VTable

nitc :: Instance :: vtable

Associate a runtime instance to its virtual table which contains methods, types etc.
protected fun vtable=(vtable: nullable VTable)

nitc :: Instance :: vtable=

Associate a runtime instance to its virtual table which contains methods, types etc.
package_diagram nitc::Instance Instance core::Object Object nitc::Instance->core::Object nitc::MutableInstance MutableInstance nitc::MutableInstance->nitc::Instance nitc::CallrefInstance CallrefInstance nitc::CallrefInstance->nitc::Instance nitc::PrimitiveInstance PrimitiveInstance nitc::PrimitiveInstance->nitc::Instance

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class CallrefInstance

nitc :: CallrefInstance

An instance with the original receiver and callsite (for function reference)
class MutableInstance

nitc :: MutableInstance

A instance with attribute (standards objects)
class PrimitiveInstance[E: nullable Object]

nitc :: PrimitiveInstance

Special instance to handle primitives values (int, bool, etc.)

Class definitions

nitc $ Instance
# An instance represents a value of the executed program.
abstract class Instance
	# The dynamic type of the instance
	# ASSERT: not self.mtype.is_anchored
	var mtype: MType

	# Return `true` if the instance is the `true` value.
	#
	# Return `false` if the instance is the `false` value.
	# Abort if the instance is not a boolean value.
	fun is_true: Bool do abort

	# Return `true` if the instance is null.
	# Return `false` otherwise.
	fun is_null: Bool do return mtype isa MNullType

	# Return true if `self` IS `o` (using the Nit semantic of is)
	fun eq_is(o: Instance): Bool do return self.is_same_instance(o)

	# Human readable object identity "Type#number"
	redef fun to_s do return "{mtype}"

	# Return the integer value if the instance is an integer.
	# else aborts
	fun to_i: Int do abort

	# Return the integer value if the instance is a float.
	# else aborts
	fun to_f: Float do abort

	# Return the integer value if the instance is a byte.
	# else aborts
	fun to_b: Byte do abort

	# Return the integer value if the instance is a int8.
	# else aborts
	fun to_i8: Int8 do abort

	# Return the integer value if the instance is a int16.
	# else aborts
	fun to_i16: Int16 do abort

	# Return the integer value if the instance is a uint16.
	# else aborts
	fun to_u16: UInt16 do abort

	# Return the integer value if the instance is a int32.
	# else aborts
	fun to_i32: Int32 do abort

	# Return the integer value if the instance is a uint32.
	# else aborts
	fun to_u32: UInt32 do abort

	# The real value encapsulated if the instance is primitive.
	# Else aborts.
	fun val: nullable Object do abort
end
src/interpreter/naive_interpreter.nit:711,1--768,3

nitc :: virtual_machine $ Instance
# Redef to associate an `Instance` to its `VTable`
redef class Instance

	# Associate a runtime instance to its virtual table which contains methods, types etc.
	var vtable: nullable VTable
end
src/vm/virtual_machine.nit:884,1--889,3