src: implement unary plus
[nit.git] / src / interpreter / naive_interpreter.nit
index 2950bae..7d7cab9 100644 (file)
@@ -833,6 +833,8 @@ redef class AMethPropdef
                        var recvval = args[0].to_i
                        if pname == "unary -" then
                                return v.int_instance(-args[0].to_i)
+                       else if pname == "unary +" then
+                               return args[0]
                        else if pname == "+" then
                                return v.int_instance(args[0].to_i + args[1].to_i)
                        else if pname == "-" then
@@ -907,6 +909,8 @@ redef class AMethPropdef
                        var recv = args[0].to_f
                        if pname == "unary -" then
                                return v.float_instance(-recv)
+                       else if pname == "unary +" then
+                               return args[0]
                        else if pname == "+" then
                                return v.float_instance(recv + args[1].to_f)
                        else if pname == "-" then
@@ -1001,11 +1005,11 @@ redef class AMethPropdef
                        else if pname == "file_exists" then
                                return v.bool_instance(recvval.to_s.file_exists)
                        else if pname == "file_mkdir" then
-                               recvval.to_s.mkdir
-                               return null
+                               var res = recvval.to_s.mkdir
+                               return v.bool_instance(res == null)
                        else if pname == "file_chdir" then
-                               recvval.to_s.chdir
-                               return null
+                               var res = recvval.to_s.chdir
+                               return v.bool_instance(res == null)
                        else if pname == "file_realpath" then
                                return v.native_string_instance(recvval.to_s.realpath)
                        else if pname == "get_environ" then
@@ -1323,6 +1327,14 @@ redef class ASelfExpr
        end
 end
 
+redef class AImplicitSelfExpr
+       redef fun expr(v)
+       do
+               if not is_sys then return super
+               return v.mainobj
+       end
+end
+
 redef class AEscapeExpr
        redef fun stmt(v)
        do