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

The trick is just to encapsulate the “real” value.

Introduced properties

private var _val: E

nitc :: PrimitiveInstance :: _val

The real value encapsulated
init defaultinit(mtype: MType, val: E)

nitc :: PrimitiveInstance :: defaultinit

protected fun val=(val: E)

nitc :: PrimitiveInstance :: val=

The real value encapsulated

Redefined properties

redef fun ==(o: nullable Object): Bool

nitc $ PrimitiveInstance :: ==

Have self and other the same value?
redef type SELF: PrimitiveInstance[E]

nitc $ PrimitiveInstance :: SELF

Type of this instance, automatically specialized in every class
redef fun eq_is(o: Instance): Bool

nitc $ PrimitiveInstance :: eq_is

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

nitc $ PrimitiveInstance :: is_true

Return true if the instance is the true value.
redef fun to_b: Byte

nitc $ PrimitiveInstance :: to_b

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

nitc $ PrimitiveInstance :: to_f

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

nitc $ PrimitiveInstance :: to_i

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

nitc $ PrimitiveInstance :: to_i16

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

nitc $ PrimitiveInstance :: to_i32

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

nitc $ PrimitiveInstance :: to_i8

Return the integer value if the instance is a int8.
redef fun to_s: String

nitc $ PrimitiveInstance :: to_s

User readable representation of self.
redef fun to_u16: UInt16

nitc $ PrimitiveInstance :: to_u16

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

nitc $ PrimitiveInstance :: to_u32

Return the integer value if the instance is a uint32.
redef fun val: E

nitc $ PrimitiveInstance :: val

The real value encapsulated

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 _val: E

nitc :: PrimitiveInstance :: _val

The real value encapsulated
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

init defaultinit(mtype: MType, val: E)

nitc :: PrimitiveInstance :: 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.
protected fun val=(val: E)

nitc :: PrimitiveInstance :: val=

The real value encapsulated
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::PrimitiveInstance PrimitiveInstance nitc::Instance Instance nitc::PrimitiveInstance->nitc::Instance core::Object Object nitc::Instance->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class Instance

nitc :: Instance

An instance represents a value of the executed program.

Class definitions

nitc $ PrimitiveInstance
# Special instance to handle primitives values (int, bool, etc.)
# The trick is just to encapsulate the “real” value.
class PrimitiveInstance[E]
	super Instance

	# The real value encapsulated
	redef var val: E

	redef fun is_true
	do
		if val == true then return true
		if val == false then return false
		abort
	end

	redef fun ==(o)
	do
		if not o isa PrimitiveInstance[nullable Object] then return false
		return self.val == o.val
	end

	redef fun eq_is(o)
	do
		if not o isa PrimitiveInstance[nullable Object] then return false
		return self.val.is_same_instance(o.val)
	end

	redef fun to_s do return "{mtype}#{val.object_id}({val or else "null"})"

	redef fun to_i do return val.as(Int)

	redef fun to_f do return val.as(Float)

	redef fun to_b do return val.as(Byte)

	redef fun to_i8 do return val.as(Int8)

	redef fun to_i16 do return val.as(Int16)

	redef fun to_u16 do return val.as(UInt16)

	redef fun to_i32 do return val.as(Int32)

	redef fun to_u32 do return val.as(UInt32)
end
src/interpreter/naive_interpreter.nit:799,1--843,3