Merge: PNaCl : Added threading to pnacl.nit
authorJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 21:56:12 +0000 (17:56 -0400)
committerJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 21:56:12 +0000 (17:56 -0400)
Added threading to pnacl.nit in order to launch Nit on a new thread and still be capable of handling messages.

Pull-Request: #492
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

15 files changed:
lib/mnit_android/android_app.nit
lib/standard/file.nit
src/model/model.nit
src/modelize_property.nit
tests/error_defs2.nit [new file with mode: 0644]
tests/sav/base_error_doubledef.res
tests/sav/error_attr_2def.res
tests/sav/error_defs2.res [new file with mode: 0644]
tests/sav/error_defs2_alt1.res [new file with mode: 0644]
tests/sav/error_defs2_alt2.res [new file with mode: 0644]
tests/sav/error_defs_alt2.res
tests/sav/error_defs_alt4.res
tests/sav/error_defs_alt5.res
tests/sav/error_meth_2def.res
tests/sav/error_meth_2def2.res

index c25e56a..3819c25 100644 (file)
@@ -159,7 +159,7 @@ class AndroidPointerEvent
 
        redef fun y: Float do return extern_y(motion_event.inner_event, pointer_id)
        private fun extern_y(motion_event: InnerAndroidMotionEvent, pointer_id: Int): Float is extern `{
-               return ((int) AMotionEvent_getY(motion_event, pointer_id) * mnit_zoom) + 32;
+               return ((int) AMotionEvent_getY(motion_event, pointer_id) * mnit_zoom);
        `}
 
        fun pressure: Float do return extern_pressure(motion_event.inner_event, pointer_id)
index f82a1fd..b797da1 100644 (file)
@@ -28,39 +28,6 @@ in "C Header" `{
        #include <unistd.h>
 `}
 
-redef class Object
-# Simple I/O
-
-       # Print `objects` on the standard output (`stdout`).
-       protected fun printn(objects: Object...)
-       do
-               sys.stdout.write(objects.to_s)
-       end
-
-       # Print an `object` on the standard output (`stdout`) and add a newline.
-       protected fun print(object: Object)
-       do
-               sys.stdout.write(object.to_s)
-               sys.stdout.write("\n")
-       end
-
-       # Read a character from the standard input (`stdin`).
-       protected fun getc: Char
-       do
-               return sys.stdin.read_char.ascii
-       end
-
-       # Read a line from the standard input (`stdin`).
-       protected fun gets: String
-       do
-               return sys.stdin.read_line
-       end
-
-       # Return the working (current) directory
-       protected fun getcwd: String do return file_getcwd.to_s
-       private fun file_getcwd: NativeString is extern "string_NativeString_NativeString_file_getcwd_0"
-end
-
 # File Abstract Stream
 abstract class FStream
        super IOS
@@ -540,3 +507,32 @@ redef class Sys
        var stderr: OStream protected writable = new Stderr
 
 end
+
+# Print `objects` on the standard output (`stdout`).
+protected fun printn(objects: Object...)
+do
+       sys.stdout.write(objects.to_s)
+end
+
+# Print an `object` on the standard output (`stdout`) and add a newline.
+protected fun print(object: Object)
+do
+       sys.stdout.write(object.to_s)
+       sys.stdout.write("\n")
+end
+
+# Read a character from the standard input (`stdin`).
+protected fun getc: Char
+do
+       return sys.stdin.read_char.ascii
+end
+
+# Read a line from the standard input (`stdin`).
+protected fun gets: String
+do
+       return sys.stdin.read_line
+end
+
+# Return the working (current) directory
+protected fun getcwd: String do return file_getcwd.to_s
+private fun file_getcwd: NativeString is extern "string_NativeString_NativeString_file_getcwd_0"
index 629dadb..6732a16 100644 (file)
@@ -1718,6 +1718,10 @@ class MMethod
                super
        end
 
+       # Is the property defined at the top_level of the module?
+       # Currently such a property are stored in `Object`
+       var is_toplevel: Bool writable = false
+
        # Is the property a constructor?
        # Warning, this property can be inherited by subclasses with or without being a constructor
        # therefore, you should use `is_init_for` the verify if the property is a legal constructor for a given class
index 5a4ec42..e24541e 100644 (file)
@@ -211,10 +211,6 @@ redef class MClass
        var inherit_init_from: nullable MClass = null
 end
 
-redef class MClassDef
-       private var propdef_names = new HashSet[String]
-end
-
 redef class MPropDef
        # Does the MPropDef contains a call to super or a call of a super-constructor?
        # Subsequent phases of the frontend (esp. typing) set it if required
@@ -313,8 +309,17 @@ redef class APropdef
        private fun check_redef_keyword(modelbuilder: ModelBuilder, nclassdef: AClassdef, kwredef: nullable Token, need_redef: Bool, mprop: MProperty): Bool
        do
                if nclassdef.mprop2npropdef.has_key(mprop) then
-                       modelbuilder.error(self, "Error: A property {mprop} is already defined in class {nclassdef.mclassdef.mclass}.")
+                       modelbuilder.error(self, "Error: A property {mprop} is already defined in class {nclassdef.mclassdef.mclass} at line {nclassdef.mprop2npropdef[mprop].location.line_start}.")
+                       return false
+               end
+               if mprop isa MMethod and mprop.is_toplevel != (nclassdef isa ATopClassdef) then
+                       if mprop.is_toplevel then
+                               modelbuilder.error(self, "Error: {mprop} is a top level method.")
+                       else
+                               modelbuilder.error(self, "Error: {mprop} is not a top level method.")
+                       end
                        return false
+
                end
                if kwredef == null then
                        if need_redef then
@@ -453,35 +458,16 @@ redef class AMethPropdef
                        mprop = new MMethod(mclassdef, name, mvisibility)
                        mprop.is_init = is_init
                        mprop.is_new = n_kwnew != null
+                       if nclassdef isa ATopClassdef then mprop.is_toplevel = true
                        if not self.check_redef_keyword(modelbuilder, nclassdef, n_kwredef, false, mprop) then return
                else
-                       if n_kwredef == null then
-                               if self isa AMainMethPropdef then
-                                       # no warning
-                               else
-                                       if not self.check_redef_keyword(modelbuilder, nclassdef, n_kwredef, true, mprop) then return
-                               end
-                       end
+                       if not self.check_redef_keyword(modelbuilder, nclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return
                        check_redef_property_visibility(modelbuilder, self.n_visibility, mprop)
                end
                nclassdef.mprop2npropdef[mprop] = self
 
                var mpropdef = new MMethodDef(mclassdef, mprop, self.location)
 
-               if mclassdef.propdef_names.has(mprop.name) then
-                       var loc: nullable Location = null
-                       for i in mclassdef.mpropdefs do
-                               if i.mproperty.name == mprop.name then
-                                       loc = i.location
-                                       break
-                               end
-                       end
-                       if loc == null then abort
-                       modelbuilder.error(self, "Error: a property {mprop} is already defined in class {mclassdef.mclass} at {loc}")
-               end
-
-               mclassdef.propdef_names.add(mpropdef.mproperty.name)
-
                set_doc(mpropdef)
 
                self.mpropdef = mpropdef
diff --git a/tests/error_defs2.nit b/tests/error_defs2.nit
new file mode 100644 (file)
index 0000000..aa28df4
--- /dev/null
@@ -0,0 +1,21 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2008 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import error_defs
+
+redef fun baz: Int do return 4
+#alt1# redef fun bar: Int do return 40
+#alt2# redef fun foo: Int do return 400
index ed17cab..fc1f645 100644 (file)
@@ -1 +1 @@
-base_error_doubledef.nit:26,12--14: Error: a property foo is already defined in class B at base_error_doubledef.nit:24,2--21
+base_error_doubledef.nit:26,12--14: Error: A property foo is already defined in class B at line 24.
index 7f848b8..0ee41fd 100644 (file)
@@ -1 +1 @@
-error_attr_2def.nit:19,6--10: Error: A property _toto is already defined in class A.
+error_attr_2def.nit:19,6--10: Error: A property _toto is already defined in class A at line 18.
diff --git a/tests/sav/error_defs2.res b/tests/sav/error_defs2.res
new file mode 100644 (file)
index 0000000..354a0e6
--- /dev/null
@@ -0,0 +1,3 @@
+4
+14
+124
diff --git a/tests/sav/error_defs2_alt1.res b/tests/sav/error_defs2_alt1.res
new file mode 100644 (file)
index 0000000..c79fb13
--- /dev/null
@@ -0,0 +1 @@
+alt/error_defs2_alt1.nit:20,11--13: Error: bar is not a top level method.
diff --git a/tests/sav/error_defs2_alt2.res b/tests/sav/error_defs2_alt2.res
new file mode 100644 (file)
index 0000000..8b01fd5
--- /dev/null
@@ -0,0 +1 @@
+alt/error_defs2_alt2.nit:21,11--13: Error: No property Object::foo is inherited. Remove the redef keyword to define a new property.
index bb671c5..2059476 100644 (file)
@@ -1 +1 @@
-alt/error_defs_alt2.nit:26,5--7: Error: A property foo is already defined in class A.
+alt/error_defs_alt2.nit:26,5--7: Error: A property foo is already defined in class A at line 25.
index 2e24837..80e2677 100644 (file)
@@ -1 +1 @@
-alt/error_defs_alt4.nit:29,5--7: Redef error: A::baz is an inherited property. To redefine it, add the redef keyword.
+alt/error_defs_alt4.nit:29,5--7: Error: baz is a top level method.
index 7732d68..fec299a 100644 (file)
@@ -1 +1 @@
-alt/error_defs_alt5.nit:30,14--22: Redef error: error_defs_alt5#A#baz redefines error_defs_alt5#Object#baz with 1 parameter(s), 0 expected. Signature is error_defs_alt5#A#baz: Int
+alt/error_defs_alt5.nit:30,11--13: Error: baz is a top level method.
index 1957edb..8a5607c 100644 (file)
@@ -1 +1 @@
-error_meth_2def.nit:19,6--9: Error: A property toto is already defined in class A.
+error_meth_2def.nit:19,6--9: Error: A property toto is already defined in class A at line 18.
index df69e17..6bac25c 100644 (file)
@@ -1 +1 @@
-error_meth_2def2.nit:19,6--9: Error: A property toto is already defined in class A.
+error_meth_2def2.nit:19,6--9: Error: A property toto is already defined in class A at line 18.