A small short PR that enables a `new`-factory to instantiate itself.
previously there was no way to do that. The following code will stack-overflow:
~~~nit
class A
new do
var res = new A
res.do_thigns
return res
end
end
var a = new A # infinite recursion of `new A`
~~~
Note: this is a very bad example as what is done in the previous `new` should be done in an `init` instead since it is related to the initialization of the object. A `new` factory should be exclusively used for some factory-concern like returning a more specialized object or returning an already existing object.
With this PR, the primitive constructor is available and is called `intern`, as the annotation that indicates things that cannot be programmed in Nit but are provided by the execution engine.
So in the previous example, just use this primitive constructor instead of doing a recursive call:
~~~
var res = new A.intern
~~~
This intern constructor just do the allocation and the initialization of attributes with default values.
`init` is not called.
Maybe it should not do the initialization of attributes neither but if I skip them, there is no way for the programmer to ask for them manually. whereas `init` in not automatically called but can be called manually.
note: this PR is a small step toward the conclusion of the constructor saga, more will come soon (I hope)
Pull-Request: #1252
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
#ifdef WITH_LIBGC
case gc_opt_boehm: GC_gcollect(); break;
#endif
+ default: break; /* nothing can be done */
}
}
else
full_path.file_delete
end
- stat.free
end
mpi.finalize
exit 0
end
end
-protected fun manager: AnalysisManager do return once new AnalysisManager
+fun manager: AnalysisManager do return once new AnalysisManager
end
# Allows user to get values with enum-like syntax : `intent_action.main`
-protected fun intent_action: Action do return once new Action
+fun intent_action: Action do return once new Action
# Allows user to get values with enum-like syntax : `intent_category.home`
-protected fun intent_category: Category do return once new Category
+fun intent_category: Category do return once new Category
# Allows user to get values with enum-like syntax : `intent_flag.activity_brought_to_front`
-protected fun intent_flag: Flag do return once new Flag
+fun intent_flag: Flag do return once new Flag
private class StringCopyArray
var collection = new Array[String]
`}
# Default Android log priority
-protected fun priority_default: Int do return 1
+fun priority_default: Int do return 1
# Verbose Android log priority
-protected fun priority_verbose: Int do return 2
+fun priority_verbose: Int do return 2
# Debug Android log priority
-protected fun priority_debug: Int do return 3
+fun priority_debug: Int do return 3
# Info Android log priority
-protected fun priority_info: Int do return 4
+fun priority_info: Int do return 4
# Warn Android log priority
-protected fun priority_warn: Int do return 5
+fun priority_warn: Int do return 5
# Error Android log priority
-protected fun priority_error: Int do return 6
+fun priority_error: Int do return 6
# Fatal Android log priority
-protected fun priority_fatal: Int do return 7
+fun priority_fatal: Int do return 7
# Silent Android log priority
-protected fun priority_silent: Int do return 8
+fun priority_silent: Int do return 8
# Write `text` to Android log at priority `level` with tag `tag`
-protected fun log_write(level: Int, tag, text: NativeString) `{
+fun log_write(level: Int, tag, text: NativeString) `{
__android_log_write(level, tag, text);
`}
fun window_closing do end
end
-protected fun app: App do return once new App
+fun app: App do return once new App
app.setup
app.run
end
end
-protected fun egl_bind_opengl_api: Bool `{ return eglBindAPI(EGL_OPENGL_API); `}
-protected fun egl_bind_opengl_es_api: Bool `{ return eglBindAPI(EGL_OPENGL_ES_API); `}
-protected fun egl_bind_openvg_api: Bool `{ return eglBindAPI(EGL_OPENVG_API); `}
+fun egl_bind_opengl_api: Bool `{ return eglBindAPI(EGL_OPENGL_API); `}
+fun egl_bind_opengl_es_api: Bool `{ return eglBindAPI(EGL_OPENGL_ES_API); `}
+fun egl_bind_openvg_api: Bool `{ return eglBindAPI(EGL_OPENVG_API); `}
abstract class QuadTree[E: Boxed[Numeric]]
super BoxedCollection[E]
- protected var center: nullable Point[Numeric]
+ protected var center: nullable Point[Numeric] = null
var data: Array[E] = new Array[E]
# ________________
# | 0 | 3 |
# |_______|_______|
- protected var child0: nullable QuadTree[E]
- protected var child1: nullable QuadTree[E]
- protected var child2: nullable QuadTree[E]
- protected var child3: nullable QuadTree[E]
+ protected var child0: nullable QuadTree[E] = null
+ protected var child1: nullable QuadTree[E] = null
+ protected var child2: nullable QuadTree[E] = null
+ protected var child3: nullable QuadTree[E] = null
# represent the threshold before subdividing the node
- protected var item_limit = 4
- protected var parent_node: nullable QuadTree[E]
-
- # create the quadtree and set the item limit for each node
- init(limit: Int)
- do
- self.item_limit = limit
- end
+ protected var item_limit: Int
+ protected var parent_node: nullable QuadTree[E] = null
# create a node, giving him self as a parent. Used to create children nodes
init with_parent(limit: Int, parent: QuadTree[E])
end
redef fun items_overlapping(region :Boxed[Numeric]): SimpleCollection[E] do
- var res = new Array[E]
- items_overlapping_in(region,res)
- return res
- end
+ var res = new Array[E]
+ items_overlapping_in(region,res)
+ return res
+ end
# add the item to the tree, create children if the limit is reached
redef fun add(item: E) do if self.is_leaf then self.data.add(item) else add_to_children(item)
else if self.center.y > item.top then
self.data.add(item)
else if self.center.y < item.bottom then
- self.data.add(item)
+ self.data.add(item)
else
self.data.add(item)
end
# the center of the parent node
class SQuadTree[E: Boxed[Numeric]]
super QuadTree[E]
-
+
# the width of the current node of the QuadTree
var width: Numeric
# the height of the current node of the QuadTree
var height: Numeric
- init(l: Int, c: Point[Numeric], w: Numeric, h: Numeric)
- do
- self.item_limit = l
- self.center = c
- self.width = w
- self.height = h
- end
-
init with_parent(l: Int, c: Point[Numeric], w: Numeric, h: Numeric, p: QuadTree[E])
do
- init(l, c, w, h)
+ init(l, w, h)
+ center = c
self.parent_node = p
end
end
end
-protected fun assert_no_gl_error
+fun assert_no_gl_error
do
var error = gl.error
if not error.is_ok then
redef class String
# returns the md5 digest of the receiver string
# algorithm implemented by L. Peter Deutsch <ghost@aladdin.com>
- fun md5: String import String.to_cstring, NativeString.to_s, String.print `{
+ fun md5: String import String.to_cstring, NativeString.to_s `{
md5_state_t state;
md5_byte_t digest[16]; /* result */
char *hex_output = malloc(33*sizeof(char));
Theses services are implemented using the POSIX threads.
+You can also use the `is threaded` annotation on methods, which makes them run on their own thread.
+Methods with return value or self calls are not supported.
+
## Known limitations:
* Most services from the Nit library are not thread-safe. You must manage
import pthreads
-# the "is threaded" annotation makes this fun run on an other thread
+# the `is threaded` annotation makes this method run on an other thread
fun foo is threaded do
sys.nanosleep(1,0)
print "threaded"
end
+# Parameterized `threaded` method, same as foo, but with parameters
+fun bar(i : Int, s : String) is threaded do
+ sys.nanosleep(2, 0)
+ print i
+ print s
+end
+
foo
+bar(10, "parameterized and threaded")
print "main"
-sys.nanosleep(2,0)
+sys.nanosleep(5,0)
end
# Hang up detected on controlling terminal or death of controlling process
-protected fun sighup: Int do return 1
+fun sighup: Int do return 1
# Issued if the user sends an interrupt signal
-protected fun sigint: Int do return 2
+fun sigint: Int do return 2
# Issued if the user sends a quit signal
-protected fun sigquit: Int do return 3
+fun sigquit: Int do return 3
# Issued if the user attempts to execute an illegal, malformed, unknown, or privileged instruction
-protected fun sigill: Int do return 4
+fun sigill: Int do return 4
# Issued when an exception occurs: a condition that a debugger has requested to be informed of
-protected fun sigtrap: Int do return 5
+fun sigtrap: Int do return 5
# This signal is sent to a process to tell it to abort, i. e. to terminate
-protected fun sigabrt: Int do return 6
+fun sigabrt: Int do return 6
# This signal is sent to a process when it causes a bus error
-protected fun sigbus: Int do return 7
+fun sigbus: Int do return 7
# Issued if an illegal mathematical operation is attempted
-protected fun sigfpe: Int do return 8
+fun sigfpe: Int do return 8
# If a process gets this signal it must quit immediately and will not perform any clean-up operations
-protected fun sigkill: Int do return 9
+fun sigkill: Int do return 9
# Sent to a process to indicate user-defined conditions
-protected fun sigusr1: Int do return 10
+fun sigusr1: Int do return 10
# Sent to a process when it makes an invalid virtual memory reference, or segmentation fault
-protected fun sigsegv: Int do return 11
+fun sigsegv: Int do return 11
# Sent to a process to indicate user-defined conditions
-protected fun sigusr2: Int do return 12
+fun sigusr2: Int do return 12
# Sent to a process when it attempts to write to a pipe without a process connected to the other end
-protected fun sigpipe: Int do return 13
+fun sigpipe: Int do return 13
# Alarm Clock signal
-protected fun sigalarm: Int do return 14
+fun sigalarm: Int do return 14
# Software termination signal
-protected fun sigterm: Int do return 15
+fun sigterm: Int do return 15
# Sent to a process when a child process terminates or is interrupted
-protected fun sigchild: Int do return 17
+fun sigchild: Int do return 17
# Tell the operating system to continue (restart) a process previously paused by the SIGSTOP or SIGTSTP signal
-protected fun sigcont: Int do return 18
+fun sigcont: Int do return 18
# Tell the operating system to stop a process
-protected fun sigstop: Int do return 19
+fun sigstop: Int do return 19
# Sent to a process by its terminal to request it to stop temporarily
-protected fun sigtstp: Int do return 20
+fun sigtstp: Int do return 20
# Sent to a process when a socket has urgent or out-of-band data available to read
-protected fun sigurg: Int do return 23
+fun sigurg: Int do return 23
# Sent to a process when it has used the CPU for a duration that exceeds a user-settable value
-protected fun sigxcpu: Int do return 24
+fun sigxcpu: Int do return 24
# Sent to a process when it grows a file larger than the maximum allowed size
-protected fun sigxfsz: Int do return 25
+fun sigxfsz: Int do return 25
# Virtual timer expired
-protected fun sigvtalrm: Int do return 26
+fun sigvtalrm: Int do return 26
# Profiling timer expired
-protected fun sigprof: Int do return 27
+fun sigprof: Int do return 27
# Sent to a process when its controlling terminal changes its window size
-protected fun sigwinch: Int do return 28
+fun sigwinch: Int do return 28
# Sent to a process when the system experiences a power failure
-protected fun sigpwr: Int do return 30
+fun sigpwr: Int do return 30
# Sent to a process when it passes a bad argument to a system call
-protected fun sigsys: Int do return 31
+fun sigsys: Int do return 31
private var file: nullable NativeFile = null
# The status of a file. see POSIX stat(2).
- fun file_stat: NativeFileStat do return _file.file_stat
+ #
+ # var f = new FileReader.open("/etc/issue")
+ # assert f.file_stat.is_file
+ #
+ # Return null in case of error
+ fun file_stat: nullable FileStat
+ do
+ var stat = _file.file_stat
+ if stat.address_is_null then return null
+ return new FileStat(stat)
+ end
# File descriptor of this file
fun fd: Int do return _file.fileno
# Open the same file again.
# The original path is reused, therefore the reopened file can be a different file.
+ #
+ # var f = new FileReader.open("/etc/issue")
+ # var l = f.read_line
+ # f.reopen
+ # assert l == f.read_line
fun reopen
do
if not eof and not _file.address_is_null then close
redef var end_reached: Bool = false
# Open the file at `path` for reading.
+ #
+ # var f = new FileReader.open("/etc/issue")
+ # assert not f.end_reached
+ # f.close
+ #
+ # In case of error, `last_error` is set
+ #
+ # f = new FileReader.open("/fail/does not/exist")
+ # assert f.end_reached
+ # assert f.last_error != null
init open(path: String)
do
self.path = path
end
# Creates a new File stream from a file descriptor
+ #
+ # This is a low-level method.
init from_fd(fd: Int) do
self.path = ""
prepare_buffer(1)
end
# Constant for read-only file streams
-private fun read_only: NativeString do return "r".to_cstring
+private fun read_only: NativeString do return once "r".to_cstring
# Constant for write-only file streams
#
# If a stream is opened on a file with this method,
# it will wipe the previous file if any.
# Else, it will create the file.
-private fun wipe_write: NativeString do return "w".to_cstring
+private fun wipe_write: NativeString do return once "w".to_cstring
###############################################################################
# Standard input stream.
+#
+# The class of the default value of `sys.stdin`.
class Stdin
super FileReader
end
# Standard output stream.
+#
+# The class of the default value of `sys.stdout`.
class Stdout
super FileWriter
init do
end
# Standard error stream.
+#
+# The class of the default value of `sys.stderr`.
class Stderr
super FileWriter
init do
#
# Returns `null` if there is no file at `self`.
#
+ # assert "/etc/".to_path.stat.is_dir
+ # assert "/etc/issue".to_path.stat.is_file
+ # assert "/fail/does not/exist".to_path.stat == null
+ #
# ~~~
# var p = "/tmp/".to_path
# var stat = p.stat
end
# Delete a file from the file system, return `true` on success
- #
- # Require: `exists`
fun delete: Bool do return path.to_cstring.file_delete
# Copy content of file at `path` to `dest`
end
# Delete the directory itself
- if ok then path.to_cstring.rmdir
+ if ok then ok = path.to_cstring.rmdir and ok
return ok
end
return stat.atime
end
+ # Returns the last access time
+ #
+ # alias for `last_access_time`
+ fun atime: Int do return last_access_time
+
# Returns the last modification time in seconds since Epoch
fun last_modification_time: Int
do
return stat.mtime
end
+ # Returns the last modification time
+ #
+ # alias for `last_modification_time`
+ fun mtime: Int do return last_modification_time
+
+
# Size of the file at `path`
fun size: Int
do
return stat.size
end
- # Is this a regular file and not a device file, pipe, socket, etc.?
+ # Is self a regular file and not a device file, pipe, socket, etc.?
fun is_file: Bool
do
assert not finalized
return stat.is_reg
end
+ # Alias for `is_file`
+ fun is_reg: Bool do return is_file
+
# Is this a directory?
fun is_dir: Bool
do
return stat.ctime
end
+ # Returns the last status change time
+ #
+ # alias for `last_status_change_time`
+ fun ctime: Int do return last_status_change_time
+
# Returns the permission bits of file
fun mode: Int
do
fun file_exists: Bool do return to_cstring.file_exists
# The status of a file. see POSIX stat(2).
- fun file_stat: NativeFileStat do return to_cstring.file_stat
+ fun file_stat: nullable FileStat
+ do
+ var stat = to_cstring.file_stat
+ if stat.address_is_null then return null
+ return new FileStat(stat)
+ end
# The status of a file or of a symlink. see POSIX lstat(2).
- fun file_lstat: NativeFileStat do return to_cstring.file_lstat
+ fun file_lstat: nullable FileStat
+ do
+ var stat = to_cstring.file_lstat
+ if stat.address_is_null then return null
+ return new FileStat(stat)
+ end
# Remove a file, return true if success
fun file_delete: Bool do return to_cstring.file_delete
end
# Simplify a file path by remove useless ".", removing "//", and resolving ".."
- # ".." are not resolved if they start the path
- # starting "/" is not removed
- # trainling "/" is removed
#
- # Note that the method only wonrk on the string:
+ # * ".." are not resolved if they start the path
+ # * starting "/" is not removed
+ # * trailing "/" is removed
+ #
+ # Note that the method only work on the string:
#
# * no I/O access is performed
# * the validity of the path is not checked
# Using a standard "{self}/{path}" does not work in the following cases:
#
# * `self` is empty.
- # * `path` ends with `'/'`.
# * `path` starts with `'/'`.
#
# This method ensures that the join is valid.
end
# Create a directory (and all intermediate directories if needed)
- fun mkdir
+ #
+ # Return an error object in case of error.
+ #
+ # assert "/etc/".mkdir != null
+ fun mkdir: nullable Error
do
var dirs = self.split_with("/")
var path = new FlatBuffer
- if dirs.is_empty then return
+ if dirs.is_empty then return null
if dirs[0].is_empty then
# it was a starting /
path.add('/')
end
+ var error: nullable Error = null
for d in dirs do
if d.is_empty then continue
path.append(d)
path.add('/')
- path.to_s.to_cstring.file_mkdir
+ var res = path.to_s.to_cstring.file_mkdir
+ if not res and error == null then
+ error = new IOError("Cannot create directory `{path}`: {sys.errno.strerror}")
+ end
end
+ return error
end
# Delete a directory and all of its content, return `true` on success
#
# Does not go through symbolic links and may get stuck in a cycle if there
# is a cycle in the filesystem.
- fun rmdir: Bool do return to_path.rmdir
+ #
+ # Return an error object in case of error.
+ #
+ # assert "/fail/does not/exist".rmdir != null
+ fun rmdir: nullable Error
+ do
+ var res = to_path.rmdir
+ if res then return null
+ var error = new IOError("Cannot change remove `{self}`: {sys.errno.strerror}")
+ return error
+ end
# Change the current working directory
#
# "..".chdir
# assert getcwd == "/"
#
- # TODO: errno
- fun chdir do to_cstring.file_chdir
+ # Return an error object in case of error.
+ #
+ # assert "/etc".chdir == null
+ # assert "/fail/does no/exist".chdir != null
+ # assert getcwd == "/etc" # unchanger
+ fun chdir: nullable Error
+ do
+ var res = to_cstring.file_chdir
+ if res then return null
+ var error = new IOError("Cannot change directory to `{self}`: {sys.errno.strerror}")
+ return error
+ end
# Return right-most extension (without the dot)
#
end
end
- # returns files contained within the directory represented by self
+ # Returns entries contained within the directory represented by self.
+ #
+ # var files = "/etc".files
+ # assert files.has("issue")
+ #
+ # Returns an empty array in case of error
+ #
+ # files = "/etc/issue".files
+ # assert files.is_empty
+ #
+ # TODO find a better way to handle errors and to give them back to the user.
fun files: Array[String] is extern import Array[String], Array[String].add, NativeString.to_s, String.to_cstring `{
char *dir_path;
DIR *dir;
dir_path = String_to_cstring( recv );
if ((dir = opendir(dir_path)) == NULL)
{
- perror( dir_path );
- exit( 1 );
+ //perror( dir_path );
+ //exit( 1 );
+ Array_of_String results;
+ results = new_Array_of_String();
+ return results;
}
else
{
return stat_element;
`}
private fun file_mkdir: Bool is extern "string_NativeString_NativeString_file_mkdir_0"
- private fun rmdir: Bool `{ return rmdir(recv); `}
+ private fun rmdir: Bool `{ return !rmdir(recv); `}
private fun file_delete: Bool is extern "string_NativeString_NativeString_file_delete_0"
- private fun file_chdir is extern "string_NativeString_NativeString_file_chdir_0"
+ private fun file_chdir: Bool is extern "string_NativeString_NativeString_file_chdir_0"
private fun file_realpath: NativeString is extern "file_NativeString_realpath"
end
# This class is system dependent ... must reify the vfs
-extern class NativeFileStat `{ struct stat * `}
+private extern class NativeFileStat `{ struct stat * `}
# Returns the permission bits of file
fun mode: Int is extern "file_FileStat_FileStat_mode_0"
# Returns the last access time
end
# Print `objects` on the standard output (`stdout`).
-protected fun printn(objects: Object...)
+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)
+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
+fun getc: Char
do
return sys.stdin.read_char.ascii
end
# Read a line from the standard input (`stdin`).
-protected fun gets: String
+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
+fun getcwd: String do return file_getcwd.to_s
private fun file_getcwd: NativeString is extern "string_NativeString_NativeString_file_getcwd_0"
#define file_Sys_Sys_buffer_mode_line_0(self) _IOLBF
#define file_Sys_Sys_buffer_mode_none_0(self) _IONBF
-#define string_NativeString_NativeString_file_mkdir_0(p) (mkdir(p, 0777))
+#define string_NativeString_NativeString_file_mkdir_0(p) (!mkdir(p, 0777))
#define string_NativeString_NativeString_file_getcwd_0(p) (getcwd(NULL, 0))
-#define string_NativeString_NativeString_file_chdir_0(p) (chdir(p)?-1:0) /* hack to avoid warn_unused_result */
+#define string_NativeString_NativeString_file_chdir_0(p) (!chdir(p))
#define file_NativeString_realpath(p) (realpath(p, NULL))
#define file_stdin_poll_in(self) file_stdin_poll_in_()
import end # Mark this module is a top level one. (must be only one)
-`{
-#include <errno.h>
-`}
-
###############################################################################
# System Classes #
###############################################################################
fun run do main
# Number of the last error
- fun errno: Int is extern `{
- return errno;
- `}
+ fun errno: Int is extern "sys_errno"
end
# Quit the program with a specific return code
*/
#include <stdlib.h>
+#include <errno.h>
#define address_is_null(x) ((x)==NULL)
+#define sys_errno(x) (errno)
#endif
redef class Int
# Wrapper of strerror C function
- private fun strerror_ext: NativeString is extern `{
- return strerror(recv);
- `}
+ private fun strerror_ext: NativeString is extern "strerror"
# Returns a string describing error number
fun strerror: String do return strerror_ext.to_s
## Documentation in preview window
-You can display the documentation for the entity under the cursor with `:call Nitdoc()`.
-It will use the same metadata files as the omnifunc and the preview window.
+The command `:Nitdoc` searches the documentation for the word under the cursor.
+The results are displayed in the preview window in order of relevance.
+You can search for any word by passing it as an argument, as in `:Nitdoc modulo`.
+The Nitdoc command uses the same metadata files as the omnifunc.
You may want to map the function to a shortcut by adding the following code to `~/.vimrc`.
~~~
" Map displaying Nitdoc to Ctrl-D
-map <C-d> :call Nitdoc()<enter>
+map <C-d> :Nitdoc<enter>
~~~
## Search declarations and usages of the word under the cursor
" Get path to the best metadata file named `name`
"
" Returns an empty string if not found.
-fun NitMetadataFile(name)
+fun s:NitMetadataFile(name)
" Where are the generated metadata files?
if empty($NIT_VIM_DIR)
let metadata_dir = $HOME . '/.vim/nit'
let synopsis_matches = []
let doc_matches = []
- let path = NitMetadataFile(a:path)
+ let path = s:NitMetadataFile(a:path)
if empty(path)
return
endif
" Add?
if name == a:base
" Exact match
- call NitOmnifuncAddAMatch(a:matches, words, name)
+ call s:NitOmnifuncAddAMatch(a:matches, words, name)
elseif name =~? '^'.a:base
" Common-prefix match
- call NitOmnifuncAddAMatch(prefix_matches, words, name)
+ call s:NitOmnifuncAddAMatch(prefix_matches, words, name)
elseif name =~? a:base
" Substring match
- call NitOmnifuncAddAMatch(substring_matches, words, name)
+ call s:NitOmnifuncAddAMatch(substring_matches, words, name)
elseif get(words, 2, '') =~? a:base
" Match in the synopsis
- call NitOmnifuncAddAMatch(synopsis_matches, words, name)
+ call s:NitOmnifuncAddAMatch(synopsis_matches, words, name)
elseif get(words, 3, '') =~? a:base
" Match in the longer doc
- call NitOmnifuncAddAMatch(synopsis_matches, words, name)
+ call s:NitOmnifuncAddAMatch(doc_matches, words, name)
endif
endfor
endfun
" Internal function to search parse the information from a metadata line
-fun NitOmnifuncAddAMatch(matches, words, name)
+fun s:NitOmnifuncAddAMatch(matches, words, name)
let pretty = get(a:words, 1, '')
let synopsis = get(a:words, 2, '')
let desc = get(a:words, 3, '')
endfun
" Show doc for the entity under the cursor in the preview window
-fun Nitdoc()
- " Word under cursor
- let word = expand("<cword>")
+fun Nitdoc(...)
+ if a:0 == 0 || empty(a:1)
+ " Word under cursor
+ let word = expand("<cword>")
+ else
+ let word = join(a:000, ' ')
+ endif
" All possible docs (there may be more than one entity with the same name)
let docs = []
+ let prefix_matches = []
+ let substring_matches = []
+ let synopsis_matches = []
+ let doc_matches = []
" Search in all metadata files
for file in ['modules', 'classes', 'properties']
- let path = NitMetadataFile(file.'.txt')
+ let path = s:NitMetadataFile(file.'.txt')
if empty(path)
continue
endif
for line in readfile(path)
let words = split(line, '#====#', 1)
let name = get(words, 0, '')
- if name =~ '^' . word . '\>'
- " It fits our word, get long doc
- let desc = get(words,3,'')
- let desc = join(split(desc, '#nnnn#', 1), "\n")
- call add(docs, desc)
+ if name =~ '^'.word.'\>'
+ " Exact match
+ call s:NitdocAdd(docs, words)
+ elseif name =~? '^'.word
+ " Common-prefix match
+ call s:NitdocAdd(prefix_matches, words)
+ elseif name =~? word
+ " Substring match
+ call s:NitdocAdd(substring_matches, words)
+ elseif get(words, 2, '') =~? word
+ " Match in the synopsis
+ call s:NitdocAdd(synopsis_matches, words)
+ elseif get(words, 3, '') =~? word
+ " Match in the longer doc
+ call s:NitdocAdd(doc_matches, words)
endif
endfor
endfor
+ " Unite all results in prefered order
+ call extend(docs, sort(prefix_matches))
+ call extend(docs, sort(substring_matches))
+ call extend(docs, sort(synopsis_matches))
+ call extend(docs, sort(doc_matches))
+
" Found no doc, give up
if empty(docs) || !(join(docs, '') =~ '\w')
+ echo 'Nitdoc found nothing for "' . word . '"'
return
endif
silent put = ''
endif
endfor
+ execute 0
+ delete " the first empty line
" Set options
setlocal buftype=nofile
redraw!
endfun
+" Internal function to search parse the information from a metadata line
+fun s:NitdocAdd(matches, words)
+ let desc = get(a:words, 3, '')
+ let desc = join(split(desc, '#nnnn#', 1), "\n")
+ call add(a:matches, desc)
+endfun
+
" Call `git grep` on the word under the cursor
"
" Shows declarations first, then all matches, in the preview window.
" Activate the omnifunc on Nit files
autocmd FileType nit set omnifunc=NitOmnifunc
+" Define the user command Nitdoc for ease of use
+command -nargs=* Nitdoc call Nitdoc("<args>")
+
let s:script_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h')
redef fun expr(v) do return v.frame.arguments.first
end
+redef class AImplicitSelfExpr
+ redef fun expr(v) do
+ if not is_sys then return super
+ return v.new_expr("glob_sys", mtype.as(not null))
+ end
+end
+
redef class AEscapeExpr
redef fun stmt(v) do v.add("goto BREAK_{v.escapemark_name(self.escapemark)};")
end
private fun get_recvtype(m: MMethodDef, recvtype: MClassType, args: Array[RuntimeVariable]): MClassType
do
check_valid_reciever(recvtype)
- #debug("call {m} on {recvtype} on {args.first}:{args.first.mtype}")
- if m.mproperty.is_toplevel then
- # Do not customize top-level methods
- recvtype = m.mclassdef.bound_mtype
- end
return recvtype
end
toolcontext.error(nmethdef.location, "Syntax error: only a method can be threaded.")
return
end
- if nmethdef.n_signature.n_params.length != 0 then
- toolcontext.error(nmethdef.location, "Syntax error: parametrized method not supported yet.")
- return
- end
+
+ #TODO: check for self calls
+
if nmethdef.n_signature.n_type != null then
toolcontext.error(nmethdef.location, "Syntax error: method with a return value not supported yet.")
return
classname += nmethdef.n_methid.as(AIdMethid).n_id.text
end
- # Create a string corresponding to the threaded class
- var s ="""
+
+ var params = new Array[String]
+ # case if the method has parameters
+ if nmethdef.n_signature.n_params.not_empty then
+ for param in nmethdef.n_signature.n_params do
+ params.add("""
+var {{{param.n_id.text}}} : {{{param.n_type.n_id.text}}}
+
+""")
+ end
+ end
+
+ # String corresponding to the generated class
+ var s="""
class {{{classname}}}
super Thread
+ {{{params.join("\n")}}}
redef fun main do
end
end
assert nullreturn isa AExpr
mainfun.n_block.as(ABlockExpr).n_expr.add(nullreturn)
+
# Create new body for the annotated fun
- var s_newbody ="""
+ var s_newbody : String
+ if nmethdef.n_signature.n_params.not_empty then
+ var init_params = new Array[String]
+ for param in nmethdef.n_signature.n_params do
+ init_params.add(param.n_id.text)
+ end
+ s_newbody ="""
+var thread = new {{{classname}}}({{{init_params.join(",")}}})
+thread.start
+"""
+ else
+ s_newbody = """
var thread = new {{{classname}}}
thread.start
"""
+ end
var newbody = toolcontext.parse_something(s_newbody)
nmethdef.n_block = newbody.as(ABlockExpr)
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
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
mainmodule.is_fictive = true
end
- var recv = mainmodule.object_type
+ var recv = mainmodule.sys_type
+ assert recv != null
var mclassdef = new MClassDef(mainmodule, recv, location)
mclassdef.add_in_hierarchy
names.add(ptname)
end
- else if nclassdef isa ATopClassdef then
+ else if nclassdef isa ATopClassdef and nclassdef.n_propdefs.first.as(AMethPropdef).n_methid.collect_text == "sys" then
+ # Special case to keep `sys` in object.
+ # Needed to keep working bootstrap and a working java FFI together.
+ # TODO: remove once safe to remove
name = "Object"
nkind = null
mkind = interface_kind
nvisibility = null
mvisibility = public_visibility
- else if nclassdef isa AMainClassdef then
+ else
name = "Sys"
nkind = null
mkind = concrete_kind
nvisibility = null
mvisibility = public_visibility
- else
- abort
end
var mclass = try_get_mclass_by_name(nclassdef, mmodule, name)
if errcount != toolcontext.error_count then return
# Create all classes
+ # process AStdClassdef before so that non-AStdClassdef classes can be attached to existing ones, if any
+ for nclassdef in nmodule.n_classdefs do
+ if not nclassdef isa AStdClassdef then continue
+ self.build_a_mclass(nmodule, nclassdef)
+ end
for nclassdef in nmodule.n_classdefs do
+ if nclassdef isa AStdClassdef then continue
self.build_a_mclass(nmodule, nclassdef)
end
# Create all classdefs
for nclassdef in nmodule.n_classdefs do
+ if not nclassdef isa AStdClassdef then continue
+ self.build_a_mclassdef(nmodule, nclassdef)
+ end
+ for nclassdef in nmodule.n_classdefs do
+ if nclassdef isa AStdClassdef then continue
self.build_a_mclassdef(nmodule, nclassdef)
end
modelbuilder.error(self, "Error: A property {mprop} is already defined in class {mclassdef.mclass} at line {mclassdef.mprop2npropdef[mprop].location.line_start}.")
return false
end
- if mprop isa MMethod and mprop.is_toplevel != (parent 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 mprop isa MMethod and mprop.is_root_init then return true
if kwredef == null then
if need_redef then
mprop.is_init = is_init
mprop.is_new = n_kwnew != null
if mprop.is_new then mclassdef.mclass.has_new_factory = true
- if parent isa ATopClassdef then mprop.is_toplevel = true
+ if name == "sys" then mprop.is_toplevel = true # special case for sys allowed in `new` factories
self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mprop)
else
if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return
redef fun toolchain(toolcontext, compiler) do return new IOSToolchain(toolcontext, compiler)
end
+private class IosProject
+ super AppProject
+
+ redef fun namespace do return super.to_camel_case
+end
+
private class IOSToolchain
super MakefileToolchain
var ios_project_root: String is noinit
# `app.nit` project for the current compilation target
- var app_project = new AppProject(compiler.modelbuilder, compiler.mainmodule) is lazy
+ var app_project = new IosProject(compiler.modelbuilder, compiler.mainmodule) is lazy
redef fun default_outname do return "{super}.app"
path = Base.lproj/LaunchScreen.xib;
sourceTree = "<group>";
};
- AF9F83E91A5F0D21004B62C0 /* {{{name}}}Tests.xctest */ = {
- isa = PBXFileReference;
- explicitFileType = wrapper.cfbundle;
- includeInIndex = 0;
- path = {{{name}}}Tests.xctest;
- sourceTree = BUILT_PRODUCTS_DIR;
- };
- AF9F83EE1A5F0D21004B62C0 /* Info.plist */ = {
- isa = PBXFileReference;
- lastKnownFileType = text.plist.xml;
- path = Info.plist;
- sourceTree = "<group>";
- };
- AF9F83EF1A5F0D21004B62C0 /* {{{name}}}Tests.m */ = {
- isa = PBXFileReference;
- lastKnownFileType = sourcecode.c.objc;
- path = {{{name}}}Tests.m;
- sourceTree = "<group>";
- };
/* Changing generated files */
"""
);
runOnlyForDeploymentPostprocessing = 0;
};
- AF9F83E61A5F0D21004B62C0 /* Frameworks */ = {
- isa = PBXFrameworksBuildPhase;
- buildActionMask = 2147483647;
- files = (
- );
- runOnlyForDeploymentPostprocessing = 0;
- };
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
isa = PBXGroup;
children = (
AF9F83CE1A5F0D21004B62C0 /* {{{name}}} */,
- AF9F83EC1A5F0D21004B62C0 /* {{{name}}}Tests */,
AF9F83CD1A5F0D21004B62C0 /* Products */,
);
sourceTree = "<group>";
isa = PBXGroup;
children = (
AF9F83CC1A5F0D21004B62C0 /* {{{name}}}.app */,
- AF9F83E91A5F0D21004B62C0 /* {{{name}}}Tests.xctest */,
);
name = Products;
sourceTree = "<group>";
name = "Supporting Files";
sourceTree = "<group>";
};
- AF9F83EC1A5F0D21004B62C0 /* {{{name}}}Tests */ = {
- isa = PBXGroup;
- children = (
- AF9F83EF1A5F0D21004B62C0 /* {{{name}}}Tests.m */,
- AF9F83ED1A5F0D21004B62C0 /* Supporting Files */,
- );
- path = {{{name}}}Tests;
- sourceTree = "<group>";
- };
- AF9F83ED1A5F0D21004B62C0 /* Supporting Files */ = {
- isa = PBXGroup;
- children = (
- AF9F83EE1A5F0D21004B62C0 /* Info.plist */,
- );
- name = "Supporting Files";
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
productReference = AF9F83CC1A5F0D21004B62C0 /* {{{name}}}.app */;
productType = "com.apple.product-type.application";
};
- AF9F83E81A5F0D21004B62C0 /* {{{name}}}Tests */ = {
- isa = PBXNativeTarget;
- buildConfigurationList = AF9F83F61A5F0D21004B62C0 /* Build configuration list for PBXNativeTarget "{{{name}}}Tests" */;
- buildPhases = (
- AF9F83E51A5F0D21004B62C0 /* Sources */,
- AF9F83E61A5F0D21004B62C0 /* Frameworks */,
- AF9F83E71A5F0D21004B62C0 /* Resources */,
- );
- buildRules = (
- );
- dependencies = (
- AF9F83EB1A5F0D21004B62C0 /* PBXTargetDependency */,
- );
- name = {{{name}}}Tests;
- productName = {{{name}}}Tests;
- productReference = AF9F83E91A5F0D21004B62C0 /* {{{name}}}Tests.xctest */;
- productType = "com.apple.product-type.bundle.unit-test";
- };
/* End PBXNativeTarget section */
/* Begin PBXProject section */
AF9F83CB1A5F0D21004B62C0 = {
CreatedOnToolsVersion = 6.1.1;
};
- AF9F83E81A5F0D21004B62C0 = {
- CreatedOnToolsVersion = 6.1.1;
- TestTargetID = AF9F83CB1A5F0D21004B62C0;
- };
};
};
buildConfigurationList = AF9F83C71A5F0D21004B62C0 /* Build configuration list for PBXProject "{{{name}}}" */;
projectRoot = "";
targets = (
AF9F83CB1A5F0D21004B62C0 /* {{{name}}} */,
- AF9F83E81A5F0D21004B62C0 /* {{{name}}}Tests */,
);
};
/* End PBXProject section */
);
runOnlyForDeploymentPostprocessing = 0;
};
- AF9F83E71A5F0D21004B62C0 /* Resources */ = {
- isa = PBXResourcesBuildPhase;
- buildActionMask = 2147483647;
- files = (
- );
- runOnlyForDeploymentPostprocessing = 0;
- };
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
);
runOnlyForDeploymentPostprocessing = 0;
};
- AF9F83E51A5F0D21004B62C0 /* Sources */ = {
- isa = PBXSourcesBuildPhase;
- buildActionMask = 2147483647;
- files = (
- AF9F83F01A5F0D21004B62C0 /* {{{name}}}Tests.m in Sources */,
- );
- runOnlyForDeploymentPostprocessing = 0;
- };
/* End PBXSourcesBuildPhase section */
-/* Begin PBXTargetDependency section */
- AF9F83EB1A5F0D21004B62C0 /* PBXTargetDependency */ = {
- isa = PBXTargetDependency;
- target = AF9F83CB1A5F0D21004B62C0 /* {{{name}}} */;
- targetProxy = AF9F83EA1A5F0D21004B62C0 /* PBXContainerItemProxy */;
- };
-/* End PBXTargetDependency section */
-
/* Begin PBXVariantGroup section */
AF9F83DD1A5F0D21004B62C0 /* Main.storyboard */ = {
isa = PBXVariantGroup;
};
name = Release;
};
- AF9F83F71A5F0D21004B62C0 /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- BUNDLE_LOADER = "$(TEST_HOST)";
- FRAMEWORK_SEARCH_PATHS = (
- "$(SDKROOT)/Developer/Library/Frameworks",
- "$(inherited)",
- );
- GCC_PREPROCESSOR_DEFINITIONS = (
- "DEBUG=1",
- "$(inherited)",
- );
- INFOPLIST_FILE = {{{name}}}Tests/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
- PRODUCT_NAME = "$(TARGET_NAME)";
- TEST_HOST = "$(BUILT_PRODUCTS_DIR)/{{{name}}}.app/{{{name}}}";
- };
- name = Debug;
- };
- AF9F83F81A5F0D21004B62C0 /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- BUNDLE_LOADER = "$(TEST_HOST)";
- FRAMEWORK_SEARCH_PATHS = (
- "$(SDKROOT)/Developer/Library/Frameworks",
- "$(inherited)",
- );
- INFOPLIST_FILE = {{{name}}}Tests/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
- PRODUCT_NAME = "$(TARGET_NAME)";
- TEST_HOST = "$(BUILT_PRODUCTS_DIR)/{{{name}}}.app/{{{name}}}";
- };
- name = Release;
- };
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
);
defaultConfigurationIsVisible = 0;
};
- AF9F83F61A5F0D21004B62C0 /* Build configuration list for PBXNativeTarget "{{{name}}}Tests" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- AF9F83F71A5F0D21004B62C0 /* Debug */,
- AF9F83F81A5F0D21004B62C0 /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- };
/* End XCConfigurationList section */
};
rootObject = AF9F83C41A5F0D21004B62C0 /* Project object */;
# Is `self` use restricted?
# * no explicit `self`
# * method called on the implicit self must be top-level
+ # Currently only used for `new` factory since there is no valid receiver inside
var is_toplevel_context = false
init
selfvariable.declared_type = mclass.mclass_type
var mprop = mpropdef.mproperty
- if mprop isa MMethod and (mprop.is_toplevel or mprop.is_new) then
+ if mprop isa MMethod and mprop.is_new then
is_toplevel_context = true
end
end
end
end
+redef class AImplicitSelfExpr
+ # Is the implicit receiver `sys`?
+ #
+ # By default, the implicit receiver is `self`.
+ # But when there is not method for `self`, `sys` is used as a fall-back.
+ # Is this case this flag is set to `true`.
+ var is_sys = false
+end
+
## MESSAGE SENDING AND PROPERTY
redef class ASendExpr
redef fun accept_typing(v)
do
- var recvtype = v.visit_expr(self.n_expr)
+ var nrecv = self.n_expr
+ var recvtype = v.visit_expr(nrecv)
var name = self.property_name
if recvtype == null then return # Forward error
- var callsite = v.get_method(self, recvtype, name, self.n_expr isa ASelfExpr)
- if callsite == null then return
+ var callsite = null
+ var unsafe_type = v.anchor_to(recvtype)
+ var mproperty = v.try_get_mproperty_by_name2(self, unsafe_type, name)
+ if mproperty == null and nrecv isa AImplicitSelfExpr then
+ # Special fall-back search in `sys` when noting found in the implicit receiver.
+ var sysclass = v.try_get_mclass(self, "Sys")
+ if sysclass != null then
+ var systype = sysclass.mclass_type
+ mproperty = v.try_get_mproperty_by_name2(self, systype, name)
+ if mproperty != null then
+ callsite = v.get_method(self, systype, name, false)
+ if callsite == null then return # Forward error
+ # Update information, we are looking at `sys` now, not `self`
+ nrecv.is_sys = true
+ nrecv.its_variable = null
+ nrecv.mtype = systype
+ recvtype = systype
+ end
+ end
+ end
+ if callsite == null then
+ # If still nothing, just exit
+ callsite = v.get_method(self, recvtype, name, nrecv isa ASelfExpr)
+ if callsite == null then return
+ end
+
self.callsite = callsite
var msignature = callsite.msignature
o.output
end
+redef class Sys
+ redef fun output do 'S'.output
+end
+
0.foo1
foo2
-../lib/standard/kernel.nit:101,1--117,3: Error: kernel#Sys does not specialize module_0#Object. Possible duplication of the root class `Object`?
+../lib/standard/kernel.nit:97,1--111,3: Error: kernel#Sys does not specialize module_0#Object. Possible duplication of the root class `Object`?
-alt/error_defs2_alt1.nit:20,11--13: Error: bar is not a top level method.
+4
+40
+124
-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_defs2_alt2.nit:21,11--13: Error: No property Sys::foo is inherited. Remove the redef keyword to define a new property.
-alt/error_defs_alt4.nit:29,5--7: Error: baz is a top level method.
+alt/error_defs_alt4.nit:27,36--38: Error: Incorrect number of parameters. Got 0, expected 1. Signature is (c: Char)
+alt/error_defs_alt4.nit:27,36--38: Type error: expected expression.
-alt/error_defs_alt5.nit:30,11--13: Error: baz is a top level method.
+alt/error_defs_alt5.nit:30,11--13: Error: No property A::baz is inherited. Remove the redef keyword to define a new property.
-alt/error_defs_alt9.nit:46,5--7: Error: A property baz is already defined in class Object at line 45.
+alt/error_defs_alt9.nit:46,5--7: Error: A property baz is already defined in class Sys at line 45.
alt/error_expr_not_ok_alt4.nit:45,7--10: Type error: expected A, got Object
alt/error_expr_not_ok_alt4.nit:46,1--9: Error: Method 'fail' doesn't exists in Object.
alt/error_expr_not_ok_alt4.nit:49,7--10: Type error: expected A, got Object
-alt/error_expr_not_ok_alt4.nit:50,1--10: Error: cannot call 'trash', a top-level method, with a receiver.
-alt/error_expr_not_ok_alt4.nit:50,1--10: Error: Incorrect number of parameters. Got 0, expected 1. Signature is (x: A)
+alt/error_expr_not_ok_alt4.nit:50,1--10: Error: Method 'trash' doesn't exists in Object.
alt/error_expr_not_ok_alt4.nit:60,4--7: Type error: expected Bool, got Int
alt/error_expr_not_ok_alt4.nit:60,20: Type error: expected A, got Int
alt/error_expr_not_ok_alt4.nit:62,10--13: Type error: expected Bool, got Int
-alt/error_toplevel_alt1.nit:25,3--10: Error: cannot call 'bar', a top-level method, with a receiver.
+alt/error_toplevel_alt1.nit:25,3--10: Error: Method 'bar' doesn't exists in Int.
-alt/error_toplevel_alt2.nit:35,2--5: Error: self cannot be used in top-level method.
+1
+0
+5
+0
+10
+20
+50
-alt/error_toplevel_alt3.nit:36,6--9: Error: self cannot be used in top-level method.
+1
+0
+5
+0
+10
+S50
-alt/error_toplevel_alt4.nit:37,2--10: Error: cannot call 'bar', a top-level method, with a receiver.
+alt/error_toplevel_alt4.nit:37,2--10: Error: Method 'bar' doesn't exists in Int.
-alt/error_toplevel_alt5.nit:40,2--4: Error: 'baz' is not a top-level method, thus need a receiver.
+1
+0
+5
+0
+10
+50
+S
\ No newline at end of file
-Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/standard/kernel.nit:432)
+Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/standard/kernel.nit:426)
11
21
31
-Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/standard/kernel.nit:432)
+Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/standard/kernel.nit:426)
11
21
31
-Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/standard/kernel.nit:432)
+Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/standard/kernel.nit:426)
11
21
31
+++ /dev/null
-<A i: <Int> s: <FlatString>>
-i=5 s=Hello
-<A>
-
-true
-true
-true
-
-<B i: <Int> s: <FlatString> a: <A i: <Int> s: <FlatString>>>
-i=100 s=World a=<A>
-<B>
-
-true
-true
-true
</span></span><span class="nc_pdef foldable" id="base_simple3#C#_val2"><a id="base_simple3#C#val2"></a><a id="base_simple3#C#val2="></a><span class="line" id="L46"> <span class="nc_k">var</span> <span class="nc_def nc_i">val2</span><span>:</span> <span class="nc_t">Int</span> <span>=</span> <span class="nc_l">10</span>
</span></span><span class="line" id="L47"><span class="nc_k">end</span>
</span></span><span class="line" id="L48">
-</span><span class="nc_pdef foldable" id="base_simple3#Object#foo"><span class="line" id="L49"><span class="nc_k">fun</span> <span class="nc_def popupable" title="base_simple3#Object#foo" data-title="<a href="base_simple3.html#base_simple3#Object#foo">base_simple3#Object#foo</a>" data-content="<div><b>fun</b> <span>foo<span></span></span><br/></div>" data-toggle="popover"><span class="nc_i">foo</span></span> <span class="nc_k">do</span> <span class="nc_l">2</span><span>.</span><span class="nc_i">output</span>
-</span></span><span class="nc_pdef foldable" id="base_simple3#Object#bar"><span class="line" id="L50"><span class="nc_k">fun</span> <span class="nc_def popupable" title="base_simple3#Object#bar" data-title="<a href="base_simple3.html#base_simple3#Object#bar">base_simple3#Object#bar</a>" data-content="<div><b>fun</b> <span>bar<span>(i: <a href="base_simple3.html#base_simple3#Int">Int</a>)</span></span><br/></div>" data-toggle="popover"><span class="nc_i">bar</span></span><span>(</span><span class="nc_v nc_i">i</span><span>:</span> <span class="nc_t">Int</span><span>)</span> <span class="nc_k">do</span> <span class="nc_v nc_i">i</span><span>.</span><span class="nc_i">output</span>
-</span></span><span class="nc_pdef foldable" id="base_simple3#Object#baz"><span class="line" id="L51"><span class="nc_k">fun</span> <span class="nc_def popupable" title="base_simple3#Object#baz" data-title="<a href="base_simple3.html#base_simple3#Object#baz">base_simple3#Object#baz</a>" data-content="<div><b>fun</b> <span>baz<span>: <a href="base_simple3.html#base_simple3#Int">Int</a></span></span><br/></div>" data-toggle="popover"><span class="nc_i">baz</span></span><span>:</span> <span class="nc_t">Int</span> <span class="nc_k">do</span> <span class="nc_k">return</span> <span class="nc_l">4</span>
+</span><span class="nc_pdef foldable" id="base_simple3#Sys#foo"><span class="line" id="L49"><span class="nc_k">fun</span> <span class="nc_def popupable" title="base_simple3#Sys#foo" data-title="<a href="base_simple3.html#base_simple3#Sys#foo">base_simple3#Sys#foo</a>" data-content="<div><b>fun</b> <span>foo<span></span></span><br/></div>" data-toggle="popover"><span class="nc_i">foo</span></span> <span class="nc_k">do</span> <span class="nc_l">2</span><span>.</span><span class="nc_i">output</span>
+</span></span><span class="nc_pdef foldable" id="base_simple3#Sys#bar"><span class="line" id="L50"><span class="nc_k">fun</span> <span class="nc_def popupable" title="base_simple3#Sys#bar" data-title="<a href="base_simple3.html#base_simple3#Sys#bar">base_simple3#Sys#bar</a>" data-content="<div><b>fun</b> <span>bar<span>(i: <a href="base_simple3.html#base_simple3#Int">Int</a>)</span></span><br/></div>" data-toggle="popover"><span class="nc_i">bar</span></span><span>(</span><span class="nc_v nc_i">i</span><span>:</span> <span class="nc_t">Int</span><span>)</span> <span class="nc_k">do</span> <span class="nc_v nc_i">i</span><span>.</span><span class="nc_i">output</span>
+</span></span><span class="nc_pdef foldable" id="base_simple3#Sys#baz"><span class="line" id="L51"><span class="nc_k">fun</span> <span class="nc_def popupable" title="base_simple3#Sys#baz" data-title="<a href="base_simple3.html#base_simple3#Sys#baz">base_simple3#Sys#baz</a>" data-content="<div><b>fun</b> <span>baz<span>: <a href="base_simple3.html#base_simple3#Int">Int</a></span></span><br/></div>" data-toggle="popover"><span class="nc_i">baz</span></span><span>:</span> <span class="nc_t">Int</span> <span class="nc_k">do</span> <span class="nc_k">return</span> <span class="nc_l">4</span>
</span></span><span class="line" id="L52">
</span><span class="nc_pdef foldable" id="base_simple3#Sys#main"><span class="line" id="L53"><span class="nc_l">1</span><span>.</span><span class="nc_i">output</span>
</span><span class="line" id="L54"><span class="nc_i">foo</span>
std: 0.926
sum: 6
cnbp: number of accessible properties (inherited + local)
- avg: 6.0
- max: C (10)
- min: Object (4)
- std: 2.268
- sum: 42
+ avg: 3.0
+ max: C (7)
+ min: Object (1)
+ std: 2.36
+ sum: 24
cnba: number of accessible attributes (inherited + local)
avg: 0.0
max: C (2)
std: 0.535
sum: 2
cnbhp: number of inherited properties
- avg: 3.0
- max: Bool (4)
+ avg: 0.0
+ max: Bool (1)
min: Object (0)
- std: 1.464
- sum: 24
+ std: 0.926
+ sum: 6
## global metrics
cnoa: number of ancestor classes
std: 0.926
sum: 6
cnbp: number of accessible properties (inherited + local)
- avg: 6.0
- max: C (10)
- min: Object (4)
- std: 2.268
- sum: 42
+ avg: 3.0
+ max: C (7)
+ min: Object (1)
+ std: 2.36
+ sum: 24
cnba: number of accessible attributes (inherited + local)
avg: 0.0
max: C (2)
std: 0.535
sum: 2
cnbhp: number of inherited properties
- avg: 3.0
- max: Bool (4)
+ avg: 0.0
+ max: Bool (1)
min: Object (0)
- std: 1.464
- sum: 24
+ std: 0.926
+ sum: 6
+--- Metrics of refinement usage ---
+Number of modules: 1
+
+Number of classes: 7
+ Number of interface kind: 1 (14.28%)
+ Number of enum kind: 2 (28.57%)
+ Number of class kind: 4 (57.14%)
+
+Number of class definitions: 7
+Number of refined classes: 0 (0.00%)
+Average number of class refinments by classes: 0.00
+Average number of class refinments by refined classes: na
+
+Number of properties: 18
+ Number of MAttribute: 3 (16.66%)
+ Number of MMethod: 15 (83.33%)
+
+Number of property definitions: 20
+Number of redefined properties: 1 (5.55%)
+Average number of property redefinitions by property: 0.11
+Average number of property redefinitions by redefined property: 2.00
+--- Explicit vs. Implicit Self ---
+Total number of self: 5
+Total number of implicit self: 4 (80.00%)
+--- Construction of tables ---
+Number of runtime classes: 6 (excluding interfaces and abstract classes)
+Average number of composing class definition by runtime class: 2.00
+Total size of tables (classes and instances): 23 (not including stuff like info for subtyping or call-next-method)
+Average size of table by runtime class: 3.83
+Values never redefined: 17 (73.91%)
--- Poset metrics ---
## Module importation hierarchy
Number of nodes: 1
bivariants: 0 (na%)
invariants: 0 (na%)
total: 0
---- Metrics of refinement usage ---
-Number of modules: 1
-
-Number of classes: 7
- Number of interface kind: 1 (14.28%)
- Number of enum kind: 2 (28.57%)
- Number of class kind: 4 (57.14%)
-
-Number of class definitions: 7
-Number of refined classes: 0 (0.00%)
-Average number of class refinments by classes: 0.00
-Average number of class refinments by refined classes: na
-
-Number of properties: 18
- Number of MAttribute: 3 (16.66%)
- Number of MMethod: 15 (83.33%)
-
-Number of property definitions: 20
-Number of redefined properties: 1 (5.55%)
-Average number of property redefinitions by property: 0.11
-Average number of property redefinitions by redefined property: 2.00
---- Explicit vs. Implicit Self ---
-Total number of self: 5
-Total number of implicit self: 4 (80.00%)
---- Construction of tables ---
-Number of runtime classes: 6 (excluding interfaces and abstract classes)
-Average number of composing class definition by runtime class: 2.00
-Total size of tables (classes and instances): 38 (not including stuff like info for subtyping or call-next-method)
-Average size of table by runtime class: 6.33
-Values never redefined: 32 (84.21%)
generating project_hierarchy.dot
generating module_hierarchy.dot
A: 1 (11.11%)
# Mendel metrics
- large mclasses (threshold: 2.291)
- B: 3
- C: 3
- budding mclasses (threshold: 0.693)
- B: 0.75
- C: 0.75
- blooming mclasses (threshold: 1.935)
- B: 2.25
- C: 2.25
- blooming mclasses (threshold: 1.935)
- B: 2.25
- C: 2.25
+ large mclasses (threshold: 3.354)
+ Sys: 4
+ budding mclasses (threshold: 3.51)
+ Sys: 4.0
+ blooming mclasses (threshold: 12.0)
+ Sys: 16.0
+ blooming mclasses (threshold: 12.0)
+ Sys: 16.0
--- Detection of the usage of covariance static type conformance ---
-- Total --
- Kinds of the subtype -
base_simple3#C#val1: 1 (4.54%)
...
base_simple3#A#init: 1 (4.54%)
- base_simple3#Object#baz: 1 (4.54%)
- base_simple3#Object#bar: 1 (4.54%)
- base_simple3#Object#foo: 1 (4.54%)
+ base_simple3#Sys#baz: 1 (4.54%)
+ base_simple3#Sys#bar: 1 (4.54%)
+ base_simple3#Sys#foo: 1 (4.54%)
base_simple3#C#init: 1 (4.54%)
MMethodDef possibly invoked at runtime (by number of CallSites)
population: 13
base_simple3#C#val1: 1 (4.54%)
...
base_simple3#A#init: 1 (4.54%)
- base_simple3#Object#baz: 1 (4.54%)
- base_simple3#Object#bar: 1 (4.54%)
- base_simple3#Object#foo: 1 (4.54%)
+ base_simple3#Sys#baz: 1 (4.54%)
+ base_simple3#Sys#bar: 1 (4.54%)
+ base_simple3#Sys#foo: 1 (4.54%)
base_simple3#C#init: 1 (4.54%)
class_hierarchy.dot
classdef_hierarchy.dot
fontsize = 8
]
Object [
- label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ exit(exit_value: Int)\l+ sys(): Sys\l}"
+ label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l}"
]
Sys [
- label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l}"
+ label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l+ exit(exit_value: Int)\l}"
]
Object -> Sys [dir=back arrowtail=open style=dashed];
fontsize = 8
]
Object [
- label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ exit(exit_value: Int)\l+ sys(): Sys\l}"
+ label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l}"
]
Sys [
- label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l}"
+ label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l+ exit(exit_value: Int)\l}"
]
Object -> Sys [dir=back arrowtail=open style=dashed];
TestSuites:
No test cases found
Class suites: 0; Test Cases: 0; Failures: 0
-<testsuites><testsuite package="test_nitunit2"><testcase classname="nitunit.test_nitunit2.standard::Object" name="test_nitunit2::Object::foo1"><system-err></system-err><system-out>if true then
+<testsuites><testsuite package="test_nitunit2"><testcase classname="nitunit.test_nitunit2.standard::Sys" name="test_nitunit2::Sys::foo1"><system-err></system-err><system-out>if true then
assert true
end
-</system-out></testcase><testcase classname="nitunit.test_nitunit2.standard::Object" name="test_nitunit2::Object::bar2"><system-err></system-err><system-out>if true then
+</system-out></testcase><testcase classname="nitunit.test_nitunit2.standard::Sys" name="test_nitunit2::Sys::bar2"><system-err></system-err><system-out>if true then
assert true
end
-</system-out></testcase><testcase classname="nitunit.test_nitunit2.standard::Object" name="test_nitunit2::Object::foo3"><system-err></system-err><system-out>var a = 1
+</system-out></testcase><testcase classname="nitunit.test_nitunit2.standard::Sys" name="test_nitunit2::Sys::foo3"><system-err></system-err><system-out>var a = 1
assert a == 1
assert a == 1
</system-out></testcase></testsuite><testsuite></testsuite></testsuites>
\ No newline at end of file
TestSuites:
No test cases found
Class suites: 0; Test Cases: 0; Failures: 0
-<testsuites><testsuite package="test_doc2"><testcase classname="nitunit.test_doc2.standard::Object" name="test_doc2::Object::foo1"><system-err></system-err><system-out>assert true # tested
-</system-out></testcase><testcase classname="nitunit.test_doc2.standard::Object" name="test_doc2::Object::foo2"><system-err></system-err><system-out>assert true # tested
-</system-out></testcase><testcase classname="nitunit.test_doc2.standard::Object" name="test_doc2::Object::foo3"><system-err></system-err><system-out>assert true # tested
+<testsuites><testsuite package="test_doc2"><testcase classname="nitunit.test_doc2.standard::Sys" name="test_doc2::Sys::foo1"><system-err></system-err><system-out>assert true # tested
+</system-out></testcase><testcase classname="nitunit.test_doc2.standard::Sys" name="test_doc2::Sys::foo2"><system-err></system-err><system-out>assert true # tested
+</system-out></testcase><testcase classname="nitunit.test_doc2.standard::Sys" name="test_doc2::Sys::foo3"><system-err></system-err><system-out>assert true # tested
</system-out></testcase></testsuite><testsuite></testsuite></testsuites>
\ No newline at end of file
\e[1m= result for 'foo'\e[0m
fun \e[1m\e[32mfoo\e[0m\e[0m
- \e[30m\e[1mbase_simple3::Object::foo\e[0m\e[0m\e[30m (lines 49-49)\e[0m
+ \e[30m\e[1mbase_simple3::Sys::foo\e[0m\e[0m\e[30m (lines 49-49)\e[0m
\e[30m\e[1mbase_simple3::Object\e[0m\e[0m\e[30m (lines 19-20)\e[0m
class \e[32m\e[1mSys\e[0m\e[0m
- \e[30m\e[1mbase_simple3::Sys\e[0m\e[0m\e[30m (lines 53-66)\e[0m
+ \e[30m\e[1mbase_simple3::Sys\e[0m\e[0m\e[30m (lines 49-49)\e[0m
.popover { max-width: 800px !important; }
</style>
-</head><body><h3 id='test_doc2'>module test_doc2</h1><h5 id='test_doc2#Object#foo1'>prop test_doc2#Object#foo1</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">true</span> <span># tested
-</span></span><span class="line" id="L2"><span></span></span></span></pre></div><h5 id='test_doc2#Object#foo2'>prop test_doc2#Object#foo2</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">true</span> <span># tested
-</span></span><span class="line" id="L2"><span></span></span></span></pre></div><h5 id='test_doc2#Object#foo3'>prop test_doc2#Object#foo3</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">true</span> <span># tested
-</span></span><span class="line" id="L2"><span></span></span></span></pre></div><h5 id='test_doc2#Object#foo4'>prop test_doc2#Object#foo4</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="rawcode">assert false # not tested (and not highlighted)
-</pre></div><h5 id='test_doc2#Object#foo5'>prop test_doc2#Object#foo5</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">false</span> <span># not tested (but highlighted)
+</head><body><h3 id='test_doc2'>module test_doc2</h1><h5 id='test_doc2#Sys#foo1'>prop test_doc2#Sys#foo1</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">true</span> <span># tested
+</span></span><span class="line" id="L2"><span></span></span></span></pre></div><h5 id='test_doc2#Sys#foo2'>prop test_doc2#Sys#foo2</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">true</span> <span># tested
+</span></span><span class="line" id="L2"><span></span></span></span></pre></div><h5 id='test_doc2#Sys#foo3'>prop test_doc2#Sys#foo3</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">true</span> <span># tested
+</span></span><span class="line" id="L2"><span></span></span></span></pre></div><h5 id='test_doc2#Sys#foo4'>prop test_doc2#Sys#foo4</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="rawcode">assert false # not tested (and not highlighted)
+</pre></div><h5 id='test_doc2#Sys#foo5'>prop test_doc2#Sys#foo5</h3><div class="nitdoc"><p class="synopsys">Test code</p><pre class="nitcode"><span class="nitcode"><span class="line" id="L1"><span class="nc_k">assert</span> <span class="nc_k">false</span> <span># not tested (but highlighted)
</span></span><span class="line" id="L2"><span></span></span></span></pre></div><script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>$(".popupable").popover({html:true, placement:'top'})/*initialize bootstrap popover*/</script></body></html>
\ No newline at end of file
main
threaded
+10
+parameterized and threaded
fun foo do print "foo"
fun call_a_fun import foo `{
- Object_foo(recv);
+ Sys_foo(recv);
`}
fun call_a_constructor import A, A.bar `{
fun out(i: Int, f: Float): Int import in1, in2, A, A.alt, A.to_i `{
printf("From C, beginning out: %ld\n", i);
- Object_in1(recv, i);
+ Sys_in1(recv, i);
A a = new_A();
A b = new_A_alt(10);
printf("From C, a=%ld\n", A_to_i(a));
printf("From Objective-C: %ld %f %s\n", ii, f, cstr);
- Object_bar(recv, ii, f, s);
+ Sys_bar(recv, ii, f, s);
`}
fun bar(i: Int, f: Float, s: String)