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>
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)
#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
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"
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
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
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
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
--- /dev/null
+# 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
-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.
-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.
--- /dev/null
+4
+14
+124
--- /dev/null
+alt/error_defs2_alt1.nit:20,11--13: Error: bar is not a top level method.
--- /dev/null
+alt/error_defs2_alt2.nit:21,11--13: Error: No property Object::foo is inherited. Remove the redef keyword to define a new property.
-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.
-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.
-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.
-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.
-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.