From 7884e4621084df5624f61194ad90b96ad1d86a30 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 26 Feb 2015 19:55:12 +0700 Subject: [PATCH] engines: move compilation of `abstract` method to MMethodDef Model things are better than AST things. Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 16 +++++++++------- src/interpreter/naive_interpreter.nit | 13 ++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 01de936..58b4b38 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1834,6 +1834,15 @@ redef class MMethodDef var modelbuilder = v.compiler.modelbuilder var val = constant_value var node = modelbuilder.mpropdef2node(self) + + if is_abstract then + var cn = v.class_name_string(arguments.first) + v.current_node = node + v.add("PRINT_ERROR(\"Runtime error: Abstract method `%s` called on `%s`\", \"{mproperty.name.escape_to_c}\", {cn});") + v.add_raw_abort + return null + end + if node isa APropdef then var oldnode = v.current_node v.current_node = node @@ -1893,13 +1902,6 @@ end redef class AMethPropdef redef fun compile_to_c(v, mpropdef, arguments) do - if mpropdef.is_abstract then - var cn = v.class_name_string(arguments.first) - v.add("PRINT_ERROR(\"Runtime error: Abstract method `%s` called on `%s`\", \"{mpropdef.mproperty.name.escape_to_c}\", {cn});") - v.add_raw_abort - return - end - # Call the implicit super-init var auto_super_inits = self.auto_super_inits if auto_super_inits != null then diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index bb0b3b3..47b02cd 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -413,6 +413,14 @@ class NaiveInterpreter var val = mpropdef.constant_value var node = modelbuilder.mpropdef2node(mpropdef) + if mpropdef.is_abstract then + if node != null then + self.frames.unshift new Frame(node, mpropdef, args) + end + fatal("Abstract method `{mpropdef.mproperty.name}` called on `{args.first.mtype}`") + abort + end + if node isa APropdef then self.parameter_check(node, mpropdef, args) return node.call(self, mpropdef, args) @@ -725,11 +733,6 @@ redef class AMethPropdef v.write_variable(variable, arguments[i+1]) end - if mpropdef.is_abstract then - v.fatal("Abstract method `{mpropdef.mproperty.name}` called on `{arguments.first.mtype}`") - abort - end - # Call the implicit super-init var auto_super_inits = self.auto_super_inits if auto_super_inits != null then -- 1.7.9.5