Merge: Light FFI for the interpreter
[nit.git] / src / interpreter / naive_interpreter.nit
index 3626d33..e36de7a 100644 (file)
@@ -800,13 +800,21 @@ redef class AMethPropdef
                if mpropdef.is_intern then
                        fatal(v, "NOT YET IMPLEMENTED intern {mpropdef}")
                else if mpropdef.is_extern then
-                       fatal(v, "NOT YET IMPLEMENTED extern {mpropdef}")
+                       var res = call_extern(v, mpropdef, arguments, f)
+                       if res != v.error_instance then return res
                else
                        fatal(v, "NOT YET IMPLEMENTED <wat?> {mpropdef}")
                end
                abort
        end
 
+       # Call this extern method
+       protected fun call_extern(v: NaiveInterpreter, mpropdef: MMethodDef, arguments: Array[Instance], f: Frame): nullable Instance
+       do
+               fatal(v, "NOT YET IMPLEMENTED extern {mpropdef}")
+               return v.error_instance
+       end
+
        # Interprets a intern or a shortcut extern method.
        # Returns the result for a function, `null` for a procedure, or `error_instance` if the method is unknown.
        private fun intern_call(v: NaiveInterpreter, mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
@@ -1245,13 +1253,13 @@ redef class AAttrPropdef
        do
                if is_lazy then return
                if has_value then
-                       var f = v.new_frame(self, mpropdef.as(not null), [recv])
+                       var f = v.new_frame(self, mreadpropdef.as(not null), [recv])
                        evaluate_expr(v, recv, f)
                        return
                end
                var mpropdef = self.mpropdef
                if mpropdef == null then return
-               var mtype = mpropdef.static_mtype.as(not null)
+               var mtype = self.mtype.as(not null)
                mtype = mtype.anchor_to(v.mainmodule, recv.mtype.as(MClassType))
                if mtype isa MNullableType then
                        v.write_attribute(self.mpropdef.mproperty, recv, v.null_instance)
@@ -1638,6 +1646,13 @@ redef class AIntExpr
        end
 end
 
+redef class AByteExpr
+       redef fun expr(v)
+       do
+               return v.byte_instance(self.value.as(not null))
+       end
+end
+
 redef class AFloatExpr
        redef fun expr(v)
        do