Compile the trampolines used to implement late-binding.

See opt_trampoline_call.

Property definitions

nitc $ SeparateRuntimeFunction :: compile_trampolines
	# Compile the trampolines used to implement late-binding.
	#
	# See `opt_trampoline_call`.
	fun compile_trampolines(compiler: SeparateCompiler)
	do
		var recv = self.mmethoddef.mclassdef.bound_mtype
		var selfvar = new RuntimeVariable("self", called_recv, recv)
		var ret = called_signature.return_mtype
		var arguments = ["self"]
		for i in [0..called_signature.arity[ do arguments.add "p{i}"

		if mmethoddef.is_intro and not recv.is_c_primitive then
			var m = mmethoddef.mproperty
			var n2 = "CALL_" + m.const_color
			compiler.provide_declaration(n2, "{c_ret} {n2}{c_sig};")
			var v2 = compiler.new_visitor
			v2.add "{c_ret} {n2}{c_sig} \{"
			v2.require_declaration(m.const_color)
			var call = "(({c_funptrtype})({v2.class_info(selfvar)}->vft[{m.const_color}]))({arguments.join(", ")});"
			if ret != null then
				v2.add "return {call}"
			else
				v2.add call
			end

			v2.add "\}"

		end
		if mmethoddef.has_supercall and not recv.is_c_primitive then
			var m = mmethoddef
			var n2 = "CALL_" + m.const_color
			compiler.provide_declaration(n2, "{c_ret} {n2}{c_sig};")
			var v2 = compiler.new_visitor
			v2.add "{c_ret} {n2}{c_sig} \{"
			v2.require_declaration(m.const_color)
			var call = "(({c_funptrtype})({v2.class_info(selfvar)}->vft[{m.const_color}]))({arguments.join(", ")});"
			if ret != null then
				v2.add "return {call}"
			else
				v2.add call
			end

			v2.add "\}"
		end
	end
src/compiler/separate_compiler.nit:2549,2--2593,4