Evaluate the node as a statement.

NOTE: Do not call this method directly, but use v.stmt This method is here to be implemented by subclasses (no need to return something).

Property definitions

nitc :: naive_interpreter $ AExpr :: stmt
	# Evaluate the node as a statement.
	# NOTE: Do not call this method directly, but use `v.stmt`
	# This method is here to be implemented by subclasses (no need to return something).
	protected fun stmt(v: NaiveInterpreter)
	do
		expr(v)
	end
src/interpreter/naive_interpreter.nit:1680,2--1686,4

nitc :: naive_interpreter $ ABlockExpr :: stmt
	redef fun stmt(v)
	do
		for e in self.n_expr do
			v.stmt(e)
			if v.is_escaping then return
		end
	end
src/interpreter/naive_interpreter.nit:1702,2--1708,4

nitc :: naive_interpreter $ AAbortExpr :: stmt
	redef fun stmt(v)
	do
		fatal(v, "Aborted")
		exit(1)
	end
src/interpreter/naive_interpreter.nit:1786,2--1790,4

nitc :: naive_interpreter $ AIfExpr :: stmt
	redef fun stmt(v)
	do
		var cond = v.expr(self.n_expr)
		if cond == null then return
		if cond.is_true then
			v.stmt(self.n_then)
		else
			v.stmt(self.n_else)
		end
	end
src/interpreter/naive_interpreter.nit:1805,2--1814,4

nitc :: naive_interpreter $ AAssertExpr :: stmt
	redef fun stmt(v)
	do
		var cond = v.expr(self.n_expr)
		if cond == null then return
		if not cond.is_true then
			v.stmt(self.n_else)
			if v.is_escaping then return

			# Explain assert if it fails
			var explain_assert_str = explain_assert_str
			if explain_assert_str != null then
				var i = v.expr(explain_assert_str)
				if i isa MutableInstance then
					var res = v.send(v.force_get_primitive_method("to_cstring", i.mtype), [i])
					if res != null then
						var val = res.val
						if val != null then
							print_error "Runtime assert: {val.to_s}"
						end
					end
				end
			end

			var nid = self.n_id
			if nid != null then
				fatal(v, "Assert '{nid.text}' failed")
			else
				fatal(v, "Assert failed")
			end
			exit(1)
		end
	end
src/interpreter/naive_interpreter.nit:1949,2--1980,4

nitc :: naive_interpreter $ ADebugTypeExpr :: stmt
	redef fun stmt(v)
	do
		# do nothing
	end
src/interpreter/naive_interpreter.nit:2467,2--2470,4

nitc :: naive_interpreter $ AEscapeExpr :: stmt
	redef fun stmt(v)
	do
		var ne = self.n_expr
		if ne != null then
			var i = v.expr(ne)
			if i == null then return
			v.escapevalue = i
		else
			v.escapevalue = null
		end
		v.escapemark = self.escapemark
	end
src/interpreter/naive_interpreter.nit:1771,2--1782,4

nitc :: naive_interpreter $ AWithExpr :: stmt
	redef fun stmt(v)
	do
		var expr = v.expr(self.n_expr)
		if expr == null then return

		v.callsite(method_start, [expr])
		v.stmt(self.n_block)
		v.is_escape(self.break_mark) # Clear the break

		# Execute the finally without an escape
		var old_mark = v.escapemark
		v.escapemark = null
		v.callsite(method_finish, [expr])
		# Restore the escape unless another escape was provided
		if v.escapemark == null then v.escapemark = old_mark
	end
src/interpreter/naive_interpreter.nit:1930,2--1945,4

nitc :: naive_interpreter $ AVarReassignExpr :: stmt
	redef fun stmt(v)
	do
		var variable = self.variable.as(not null)
		var vari = v.read_variable(variable)
		var value = v.expr(self.n_value)
		if value == null then return
		var res = v.callsite(reassign_callsite, [vari, value])
		assert res != null
		v.write_variable(variable, res)
	end
src/interpreter/naive_interpreter.nit:1743,2--1752,4

nitc :: naive_interpreter $ ASendReassignFormExpr :: stmt
	redef fun stmt(v)
	do
		var recv = v.expr(self.n_expr)
		if recv == null then return
		var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.raw_arguments)
		if args == null then return
		var value = v.expr(self.n_value)
		if value == null then return

		var read = v.callsite(callsite, args)
		assert read != null

		var write = v.callsite(reassign_callsite, [read, value])
		assert write != null

		args.add(write)

		v.callsite(write_callsite, args)
	end
src/interpreter/naive_interpreter.nit:2312,2--2330,4

nitc :: naive_interpreter $ AAttrAssignExpr :: stmt
	redef fun stmt(v)
	do
		var recv = v.expr(self.n_expr)
		if recv == null then return
		if recv.is_null then fatal(v, "Receiver is null")
		var i = v.expr(self.n_value)
		if i == null then return
		var mproperty = self.mproperty.as(not null)
		v.write_attribute(mproperty, recv, i)
	end
src/interpreter/naive_interpreter.nit:2406,2--2415,4

nitc :: vm_optimizations $ AAttrAssignExpr :: stmt
	redef fun stmt(v)
	do
		# TODO : a workaround for now
		if not v isa VirtualMachine then
			super
			return
		end

		var recv = v.expr(self.n_expr)
		if recv == null then return
		if recv.mtype isa MNullType then fatal(v, "Receiver is null")
		var i = v.expr(self.n_value)
		if i == null then return
		var mproperty = self.mproperty.as(not null)

		assert recv isa MutableInstance
		if status == 0 then optimize(mproperty, recv)

		if status == 1 then
			v.write_attribute_sst(recv.internal_attributes, offset, i)
		else
			v.write_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
					recv.vtable.mask, id, offset, i)
		end

		#TODO : we need recompilations here
		status = 0
	end
src/vm/vm_optimizations.nit:127,2--154,4

nitc :: naive_interpreter $ AAttrReassignExpr :: stmt
	redef fun stmt(v)
	do
		var recv = v.expr(self.n_expr)
		if recv == null then return
		if recv.is_null then fatal(v, "Receiver is null")
		var value = v.expr(self.n_value)
		if value == null then return
		var mproperty = self.mproperty.as(not null)
		var attr = v.read_attribute(mproperty, recv)
		var res = v.callsite(reassign_callsite, [attr, value])
		assert res != null
		v.write_attribute(mproperty, recv, res)
	end
src/interpreter/naive_interpreter.nit:2419,2--2431,4

nitc :: naive_interpreter $ ADoExpr :: stmt
	redef fun stmt(v)
	do
		# If this bloc has a catch, handle it with a do ... catch ... end
		if self.n_catch != null then
			var frame = v.frame
			v.catch_count += 1
			do
				v.stmt(self.n_block)
				v.is_escape(self.break_mark) # Clear the break (if any)
				v.catch_count -= 1
			catch
				# Restore the current frame if needed
				while v.frame != frame do v.frames.shift
				v.catch_count -= 1
				v.stmt(self.n_catch)
			end
		else
			v.stmt(self.n_block)
			v.is_escape(self.break_mark)
		end
	end
src/interpreter/naive_interpreter.nit:1831,2--1851,4

nitc :: naive_interpreter $ AWhileExpr :: stmt
	redef fun stmt(v)
	do
		loop
			var cond = v.expr(self.n_expr)
			if cond == null then return
			if not cond.is_true then return
			v.stmt(self.n_block)
			if v.is_escape(self.break_mark) then return
			v.is_escape(self.continue_mark) # Clear the break
			if v.is_escaping then return
		end
	end
src/interpreter/naive_interpreter.nit:1855,2--1866,4

nitc :: naive_interpreter $ ALoopExpr :: stmt
	redef fun stmt(v)
	do
		loop
			v.stmt(self.n_block)
			if v.is_escape(self.break_mark) then return
			v.is_escape(self.continue_mark) # Clear the break
			if v.is_escaping then return
		end
	end
src/interpreter/naive_interpreter.nit:1870,2--1878,4

nitc :: naive_interpreter $ AForExpr :: stmt
	redef fun stmt(v)
	do
		var iters = new Array[Instance]

		for g in n_groups do
			var col = v.expr(g.n_expr)
			if col == null then return
			if col.is_null then fatal(v, "Receiver is null")

			var iter = v.callsite(g.method_iterator, [col]).as(not null)
			iters.add iter
		end

		loop
			for g in n_groups, iter in iters do
				var isok = v.callsite(g.method_is_ok, [iter]).as(not null)
				if not isok.is_true then break label
				if g.variables.length == 1 then
					var item = v.callsite(g.method_item, [iter]).as(not null)
					#self.debug("item {item}")
					v.write_variable(g.variables.first, item)
				else if g.variables.length == 2 then
					var key = v.callsite(g.method_key, [iter]).as(not null)
					v.write_variable(g.variables[0], key)
					var item = v.callsite(g.method_item, [iter]).as(not null)
					v.write_variable(g.variables[1], item)
				else
					abort
				end
			end
			v.stmt(self.n_block)
			if v.is_escape(self.break_mark) then break
			v.is_escape(self.continue_mark) # Clear the break
			if v.is_escaping then break
			for g in n_groups, iter in iters do
				v.callsite(g.method_next, [iter])
			end
		end label
		for g in n_groups, iter in iters do
			var method_finish = g.method_finish
			if method_finish != null then
				v.callsite(method_finish, [iter])
			end
		end
	end
src/interpreter/naive_interpreter.nit:1882,2--1926,4