Property definitions

nitc $ CallArg :: defaultinit
# Single cell in the list of arguments sent to foreign code (and received)
#
# Each cell can hold all primitive types and pointers to Nit class instances.
#
# Since this is a C pointer, it acts as both a single cell and an array.
private extern class CallArg `{ nit_call_arg* `}

	# Initialize an array of `CallArg` of `length` elements
	new (length: Int) `{ return calloc(length, sizeof(nit_call_arg)); `}

	# Get the element at `index` after `self`
	fun [](index: Int): CallArg `{ return self + index; `}

	# The `Int` held by this cell
	fun int: Int `{ return self->value_Int; `}

	# The `Int` held by this cell
	fun int=(value: Int) `{ self->value_Int = value; `}

	# The `Bool` held by this cell
	fun bool: Bool `{ return self->value_Bool; `}

	# The `Bool` held by this cell
	fun bool=(value: Bool) `{ self->value_Bool = value; `}

	# The `Char` held by this cell
	fun char: Char `{ return self->value_Char; `}

	# The `Char` held by this cell
	fun char=(value: Char) `{ self->value_Char = value; `}

	# The `Byte` held by this cell
	fun byte: Byte `{ return self->value_Byte; `}

	# The `Byte` held by this cell
	fun byte=(value: Byte) `{ self->value_Byte = value; `}

	# The `Int` held by this cell
	fun int8: Int8 `{ return self->value_Int8; `}

	# The `Int` held by this cell
	fun int8=(value: Int8) `{ self->value_Int8 = value; `}

	# The `Int` held by this cell
	fun int16: Int16 `{ return self->value_Int16; `}

	# The `Int` held by this cell
	fun int16=(value: Int16) `{ self->value_Int16 = value; `}

	# The `Int` held by this cell
	fun uint16: UInt16 `{ return self->value_UInt16; `}

	# The `Int` held by this cell
	fun uint16=(value: UInt16) `{ self->value_UInt16 = value; `}

	# The `Int` held by this cell
	fun int32: Int32 `{ return self->value_Int32; `}

	# The `Int` held by this cell
	fun int32=(value: Int32) `{ self->value_Int32 = value; `}

	# The `Int` held by this cell
	fun uint32: UInt32 `{ return self->value_UInt32; `}

	# The `Int` held by this cell
	fun uint32=(value: UInt32) `{ self->value_UInt32 = value; `}

	# The `Float` held by this cell
	fun float: Float `{ return self->value_Float; `}

	# The `Float` held by this cell
	fun float=(value: Float) `{ self->value_Float = value; `}

	# The `Pointer` held by this cell
	fun pointer: Pointer `{ return self->value_Pointer; `}

	# The `Pointer` held by this cell
	fun pointer=(value: Pointer) `{ self->value_Pointer = value; `}

	# The `Instance` held by this cell
	fun instance: Instance is light_ffi `{ return (Instance)self->value_Pointer; `}

	# The `Instance` held by this cell
	fun instance=(value: Instance) is light_ffi `{ self->value_Pointer = value; `}

	# The `CString` held by this cell
	fun c_string: CString `{ return (char*)self->value_Pointer; `}

	# Set the content of this cell according to `static_type`
	#
	# Opposite of `to_instance`.
	fun from_static_type(value: Instance, static_type: MType)
	do
		if static_type.name == "Int" then
			assert value isa PrimitiveInstance[Int]
			self.int = value.val
		else if static_type.name == "Bool" then
			assert value isa PrimitiveInstance[Bool]
			self.bool = value.val
		else if static_type.name == "Char" then
			assert value isa PrimitiveInstance[Char]
			self.char = value.val
		else if static_type.name == "Byte" then
			assert value isa PrimitiveInstance[Byte]
			self.byte = value.val
		else if static_type.name == "Int8" then
			assert value isa PrimitiveInstance[Int8]
			self.int8 = value.val
		else if static_type.name == "Int16" then
			assert value isa PrimitiveInstance[Int16]
			self.int16 = value.val
		else if static_type.name == "UInt16" then
			assert value isa PrimitiveInstance[UInt16]
			self.uint16 = value.val
		else if static_type.name == "Int32" then
			assert value isa PrimitiveInstance[Int32]
			self.int32 = value.val
		else if static_type.name == "UInt32" then
			assert value isa PrimitiveInstance[UInt32]
			self.uint32 = value.val
		else if static_type.name == "Float" then
			assert value isa PrimitiveInstance[Float]
			self.float = value.val
		else if static_type.name == "CString" then
			assert value isa PrimitiveInstance[CString]
			self.pointer = value.val
		else if static_type isa MClassType and static_type.mclass.kind == extern_kind then
			assert value isa PrimitiveInstance[Pointer] else print value.class_name
			self.pointer = value.val
		else
			self.instance = value
		end
	end

	# Get the content of this cell as an `Instance` of the `static_type`
	#
	# Opposite of `from_static_type`.
	fun to_instance(static_type: MType, v: NaiveInterpreter): Instance
	do
		var name = static_type.name
		if name == "Int" then
			return v.int_instance(self.int)
		else if name == "Bool" then
			return if self.bool then
				v.true_instance
			else v.false_instance
		else if name == "Char" then
			return v.char_instance(self.char)
		else if name == "Byte" then
			return v.byte_instance(self.byte)
		else if name == "Int8" then
			return v.int8_instance(self.int8)
		else if name == "Int16" then
			return v.int16_instance(self.int16)
		else if name == "UInt16" then
			return v.uint16_instance(self.uint16)
		else if name == "Int32" then
			return v.int32_instance(self.int32)
		else if name == "UInt32" then
			return v.uint32_instance(self.uint32)
		else if name == "Float" then
			return v.float_instance(self.float)
		else if name == "CString" then
			var instance = new PrimitiveInstance[CString](static_type, self.c_string)
			v.init_instance_primitive instance
			return instance
		else if static_type isa MClassType and static_type.mclass.kind == extern_kind then
			# We tag it with the most precise known type
			var instance = new PrimitiveInstance[Pointer](static_type, self.pointer)
			v.init_instance_primitive instance
			return instance
		else
			return self.instance
		end
	end
end
src/interpreter/dynamic_loading_ffi/dynamic_loading_ffi.nit:48,1--223,3