Merge: Manual: rewrite the man for nitg
authorJean Privat <jean@pryen.org>
Tue, 4 Nov 2014 20:07:40 +0000 (15:07 -0500)
committerJean Privat <jean@pryen.org>
Tue, 4 Nov 2014 20:07:40 +0000 (15:07 -0500)
If people like it, I may write the manpage for the other tools.

I generated the markdown to http://nitlanguage.org/tools/nitg/ so you could see the rendered result in HTML.
I plan to have pages for the tools automatically synchonized from the files in /share/man.

Pull-Request: #871
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

README
bin/nitc
c_src/Makefile
c_src/abstract_compiler.sep.1.c
lib/neo4j/curl_json.nit
src/compiler/abstract_compiler.nit
src/neo.nit
src/toolcontext.nit
tests/tests.sh

diff --git a/README b/README
index 2b4e22e..adb80ee 100644 (file)
--- a/README
+++ b/README
@@ -17,6 +17,7 @@ Some Nit features:
 Requirement:
 
        * gcc           http://gcc.gnu.org/
+       * pkg-config    http://www.freedesktop.org/wiki/Software/pkg-config/
        * ccache        http://ccache.samba.org/        to improve recompilation
        * libgc-dev     http://www.hpl.hp.com/personal/Hans_Boehm/gc/
        * graphviz      http://www.graphviz.org/        to enable graphes with the nitdoc tool
@@ -24,7 +25,7 @@ Requirement:
 
 Those are available in most linux distributions
 
-    # sudo apt-get install build-essential ccache libgc-dev graphviz libunwind
+    # sudo apt-get install build-essential ccache libgc-dev graphviz libunwind pkg-config
 
 Important files and directory:
 
index cd4c670..42b4e3a 100755 (executable)
--- a/bin/nitc
+++ b/bin/nitc
@@ -1,4 +1,3 @@
 #!/bin/bash
-self=`readlink /proc/$$/fd/255`
-dir=`dirname "$self"`
+dir=`dirname "$BASH_SOURCE"`
 exec "$dir/nitg" "$@"
index db97fe4..40131db 100644 (file)
@@ -3,7 +3,7 @@ CXX = ccache c++
 CFLAGS = -g -O2 -Wno-unused-value -Wno-switch
 CINCL = 
 LDFLAGS ?= 
-LDLIBS  ?= -lm -lgc 
+LDLIBS  ?= -lm `pkg-config --libs bdw-gc` 
 
 NEED_LIBUNWIND := YesPlease
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
@@ -315,7 +315,7 @@ c_functions_hash.extern.o: c_functions_hash.c
        $(CC) $(CFLAGS)  -c -o c_functions_hash.extern.o c_functions_hash.c
 
 gc_chooser.extern.o: gc_chooser.c
-       $(CC) $(CFLAGS) -DWITH_LIBGC -c -o gc_chooser.extern.o gc_chooser.c
+       $(CC) $(CFLAGS) -DWITH_LIBGC `pkg-config --cflags bdw-gc` -c -o gc_chooser.extern.o gc_chooser.c
 
 string._ffi.extern.o: string._ffi.c
        $(CC) $(CFLAGS)  -c -o string._ffi.extern.o string._ffi.c
index da573c6..e9e6534 100644 (file)
@@ -3498,8 +3498,8 @@ abstract_compiler__AbstractCompiler__build_c_to_nit_bindings(var_compiler); /* D
 if (varonce26) {
 var27 = varonce26;
 } else {
-var28 = "-DWITH_LIBGC";
-var29 = 12;
+var28 = "-DWITH_LIBGC `pkg-config --cflags bdw-gc` ";
+var29 = 42;
 var30 = string__NativeString__to_s_with_length(var28, var29);
 var27 = var30;
 varonce26 = var27;
@@ -5985,8 +5985,8 @@ varonce65 = var66;
 if (varonce70) {
 var71 = varonce70;
 } else {
-var72 = "\nLDFLAGS ?= \nLDLIBS  ?= -lm -lgc ";
-var73 = 33;
+var72 = "\nLDFLAGS ?= \nLDLIBS  ?= -lm `pkg-config --libs bdw-gc`";
+var73 = 55;
 var74 = string__NativeString__to_s_with_length(var72, var73);
 var71 = var74;
 varonce70 = var71;
index f1a1da8..dc5c8ac 100644 (file)
@@ -50,6 +50,7 @@ abstract class JsonCurlRequest
                headers = new HeaderMap
                headers["Accept"] = "application/json; charset=UTF-8"
                headers["Transfer-Encoding"] = "chunked"
+               headers["X-Stream"] = "true"
                if auth != null then
                        headers["Authorization"] = "token {auth.to_s}"
                end
@@ -95,7 +96,7 @@ abstract class JsonCurlRequest
                end
 
                var err_hook = execute_hook
-           if err_hook != null then return err_hook
+               if err_hook != null then return err_hook
 
                var err_resp = perform
                if err_resp != null then return err_resp
index 008e8f1..e3c2fdf 100644 (file)
@@ -225,7 +225,7 @@ class MakefileToolchain
        do
                var platform = compiler.mainmodule.target_platform
                if self.toolcontext.opt_stacktrace.value == "nitstack" and (platform == null or platform.supports_libunwind) then compiler.build_c_to_nit_bindings
-               var cc_opt_with_libgc = "-DWITH_LIBGC"
+               var cc_opt_with_libgc = "-DWITH_LIBGC `pkg-config --cflags bdw-gc`"
                if platform != null and not platform.supports_libgc then cc_opt_with_libgc = ""
 
                # Add gc_choser.h to aditionnal bodies
@@ -363,7 +363,7 @@ class MakefileToolchain
                        if libs != null then linker_options.add_all(libs)
                end
 
-               makefile.write("CC = ccache cc\nCXX = ccache c++\nCFLAGS = -g -O2 -Wno-unused-value -Wno-switch\nCINCL = {cc_includes}\nLDFLAGS ?= \nLDLIBS  ?= -lm -lgc {linker_options.join(" ")}\n\n")
+               makefile.write("CC = ccache cc\nCXX = ccache c++\nCFLAGS = -g -O2 -Wno-unused-value -Wno-switch\nCINCL = {cc_includes}\nLDFLAGS ?= \nLDLIBS  ?= -lm `pkg-config --libs bdw-gc` {linker_options.join(" ")}\n\n")
 
                var ost = toolcontext.opt_stacktrace.value
                if (ost == "libunwind" or ost == "nitstack") and (platform == null or platform.supports_libunwind) then makefile.write("NEED_LIBUNWIND := YesPlease\n")
index df2792c..fe24e72 100644 (file)
@@ -213,27 +213,27 @@ class NeoModel
 
        # Fill `model` using base pointed by `client`.
        fun load(model: Model): Model do
-               toolcontext.info("Locate all mentities...", 1)
-               var nodes = client.nodes_with_label(model_name)
+               var nodes: Array[NeoNode]
 
-               toolcontext.info("Preload nodes...", 1)
-               pull_all_nodes(nodes)
-               toolcontext.info("Preload edges...", 1)
-               pull_all_edges(nodes)
-
-               toolcontext.info("Build model...", 1)
+               toolcontext.info("Loading project node...", 1)
                nodes = client.nodes_with_labels([model_name, "MProject"])
                for node in nodes do to_mproject(model, node)
+               toolcontext.info("Loading groups...", 1)
                nodes = client.nodes_with_labels([model_name, "MGroup"])
                for node in nodes do to_mgroup(model, node)
+               toolcontext.info("Loading modules...", 1)
                nodes = client.nodes_with_labels([model_name, "MModule"])
                for node in nodes do to_mmodule(model, node)
+               toolcontext.info("Loading classes...", 1)
                nodes = client.nodes_with_labels([model_name, "MClass"])
                for node in nodes do to_mclass(model, node)
+               toolcontext.info("Loading class definitions...", 1)
                nodes = client.nodes_with_labels([model_name, "MClassDef"])
                for node in nodes do to_mclassdef(model, node)
+               toolcontext.info("Loading properties...", 1)
                nodes = client.nodes_with_labels([model_name, "MProperty"])
                for node in nodes do to_mproperty(model, node)
+               toolcontext.info("Loading property definitions...", 1)
                nodes = client.nodes_with_labels([model_name, "MPropDef"])
                for node in nodes do to_mpropdef(model, node)
                return model
@@ -270,52 +270,6 @@ class NeoModel
                do_batch(batch)
        end
 
-       # Load content for all `nodes` from base.
-       #
-       # Content corresponds to properties and labels that are loaded in batch mode.
-       private fun pull_all_nodes(nodes: Collection[NeoNode]) do
-               var batch = new NeoBatch(client)
-               var len = nodes.length
-               var sum = 0
-               var i = 1
-               for node in nodes do
-                       batch.load_node(node)
-                       if i == batch_max_size then
-                               do_batch(batch)
-                               sum += batch_max_size
-                               toolcontext.info(" {sum * 100 / len}% done", 1)
-                               batch = new NeoBatch(client)
-                               i = 1
-                       else
-                               i += 1
-                       end
-               end
-               do_batch(batch)
-       end
-
-       # Load all edges from base linked to `nodes`.
-       #
-       # Edges are loaded in batch mode.
-       private fun pull_all_edges(nodes: Collection[NeoNode]) do
-               var batch = new NeoBatch(client)
-               var len = nodes.length
-               var sum = 0
-               var i = 1
-               for node in nodes do
-                       batch.load_node_edges(node)
-                       if i == batch_max_size then
-                               do_batch(batch)
-                               sum += batch_max_size
-                               toolcontext.info(" {sum * 100 / len}% done", 1)
-                               batch = new NeoBatch(client)
-                               i = 1
-                       else
-                               i += 1
-                       end
-               end
-               do_batch(batch)
-       end
-
        # How many operation can be executed in one batch?
        private var batch_max_size = 1000
 
@@ -349,7 +303,9 @@ class NeoModel
        end
 
        # Mentities associated to nodes.
-       private var mentities = new HashMap[NeoNode, MEntity]
+       #
+       # The key is the node’s id.
+       private var mentities = new HashMap[Int, MEntity]
 
        # Nodes associated with MEntities.
        private var nodes = new HashMap[MEntity, NeoNode]
@@ -396,10 +352,12 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MProject")`
        private fun to_mproject(model: Model, node: NeoNode): MProject do
-               if mentities.has_key(node) then return mentities[node].as(MProject)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MProject then return m
+
                assert node.labels.has("MProject")
                var mproject = new MProject(node["name"].to_s, model)
-               mentities[node] = mproject
+               mentities[node.id.as(Int)] = mproject
                set_doc(node, mproject)
                mproject.root = to_mgroup(model, node.out_nodes("ROOT").first)
                return mproject
@@ -428,7 +386,9 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MGroup")`
        private fun to_mgroup(model: Model, node: NeoNode): MGroup do
-               if mentities.has_key(node) then return mentities[node].as(MGroup)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MGroup then return m
+
                assert node.labels.has("MGroup")
                var mproject = to_mproject(model, node.out_nodes("PROJECT").first)
                var parent: nullable MGroup = null
@@ -437,7 +397,7 @@ class NeoModel
                        parent = to_mgroup(model, out.first)
                end
                var mgroup = new MGroup(node["name"].to_s, mproject, parent)
-               mentities[node] = mgroup
+               mentities[node.id.as(Int)] = mgroup
                set_doc(node, mgroup)
                return mgroup
        end
@@ -464,7 +424,9 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MModule")`
        private fun to_mmodule(model: Model, node: NeoNode): MModule do
-               if mentities.has_key(node) then return mentities[node].as(MModule)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MModule then return m
+
                assert node.labels.has("MModule")
                var ins = node.in_nodes("DECLARES")
                var mgroup: nullable MGroup = null
@@ -474,7 +436,7 @@ class NeoModel
                var name = node["name"].to_s
                var location = to_location(node["location"].to_s)
                var mmodule = new MModule(model, mgroup, name, location)
-               mentities[node] = mmodule
+               mentities[node.id.as(Int)] = mmodule
                set_doc(node, mmodule)
                var imported_mmodules = new Array[MModule]
                for smod in node.out_nodes("IMPORTS") do
@@ -504,7 +466,9 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MClass")`
        private fun to_mclass(model: Model, node: NeoNode): MClass do
-               if mentities.has_key(node) then return mentities[node].as(MClass)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MClass then return m
+
                assert node.labels.has("MClass")
                var mmodule = to_mmodule(model, node.in_nodes("INTRODUCES").first)
                var name = node["name"].to_s
@@ -517,7 +481,7 @@ class NeoModel
                        end
                end
                var mclass = new MClass(mmodule, name, parameter_names, kind, visibility)
-               mentities[node] = mclass
+               mentities[node.id.as(Int)] = mclass
                set_doc(node, mclass)
                return mclass
        end
@@ -545,13 +509,15 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MClassDef")`
        private fun to_mclassdef(model: Model, node: NeoNode): MClassDef do
-               if mentities.has_key(node) then return mentities[node].as(MClassDef)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MClassDef then return m
+
                assert node.labels.has("MClassDef")
                var mmodule = to_mmodule(model, node.in_nodes("DEFINES").first)
                var mtype = to_mtype(model, node.out_nodes("BOUNDTYPE").first).as(MClassType)
                var location = to_location(node["location"].to_s)
                var mclassdef = new MClassDef(mmodule, mtype, location)
-               mentities[node] = mclassdef
+               mentities[node.id.as(Int)] = mclassdef
                set_doc(node, mclassdef)
                var supertypes = new Array[MClassType]
                for sup in node.out_nodes("INHERITS") do
@@ -584,7 +550,9 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MProperty")`
        private fun to_mproperty(model: Model, node: NeoNode): MProperty do
-               if mentities.has_key(node) then return mentities[node].as(MProperty)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MProperty then return m
+
                assert node.labels.has("MProperty")
                var intro_mclassdef = to_mclassdef(model, node.out_nodes("INTRO_CLASSDEF").first)
                var name = node["name"].to_s
@@ -602,7 +570,7 @@ class NeoModel
                        print "not yet implemented to_mproperty for {node.labels.join(",")}"
                        abort
                end
-               mentities[node] = mprop
+               mentities[node.id.as(Int)] = mprop
                set_doc(node, mprop)
                return mprop
        end
@@ -642,7 +610,9 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MPropDef")`
        private fun to_mpropdef(model: Model, node: NeoNode): MPropDef do
-               if mentities.has_key(node) then return mentities[node].as(MPropDef)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MPropDef then return m
+
                assert node.labels.has("MPropDef")
                var mclassdef = to_mclassdef(model, node.in_nodes("DECLARES").first)
                var mproperty = to_mproperty(model, node.out_nodes("DEFINES").first)
@@ -653,16 +623,16 @@ class NeoModel
                        mpropdef.is_abstract = node["is_abstract"].as(Bool)
                        mpropdef.is_intern = node["is_intern"].as(Bool)
                        mpropdef.is_extern = node["is_extern"].as(Bool)
-                       mentities[node] = mpropdef
+                       mentities[node.id.as(Int)] = mpropdef
                        mpropdef.msignature = to_mtype(model, node.out_nodes("SIGNATURE").first).as(MSignature)
                else if node.labels.has("MAttributeDef") then
                        mpropdef = new MAttributeDef(mclassdef, mproperty.as(MAttribute), location)
-                       mentities[node] = mpropdef
+                       mentities[node.id.as(Int)] = mpropdef
                        var static_mtype = node.out_nodes("TYPE")
                        if not static_mtype.is_empty then mpropdef.static_mtype = to_mtype(model, static_mtype.first)
                else if node.labels.has("MVirtualTypeDef") then
                        mpropdef = new MVirtualTypeDef(mclassdef, mproperty.as(MVirtualTypeProp), location)
-                       mentities[node] = mpropdef
+                       mentities[node.id.as(Int)] = mpropdef
                        var bound = node.out_nodes("BOUND")
                        if not bound.is_empty then mpropdef.bound = to_mtype(model, bound.first)
                end
@@ -720,7 +690,9 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MType")`
        private fun to_mtype(model: Model, node: NeoNode): MType do
-               if mentities.has_key(node) then return mentities[node].as(MType)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MType then return m
+
                assert node.labels.has("MType")
                if node.labels.has("MClassType") then
                        var mclass = to_mclass(model, node.out_nodes("CLASS").first)
@@ -729,24 +701,24 @@ class NeoModel
                                args.add to_mtype(model, narg)
                        end
                        var mtype = mclass.get_mtype(args)
-                       mentities[node] = mtype
+                       mentities[node.id.as(Int)] = mtype
                        return mtype
                else if node.labels.has("MParameterType") then
                        var mclass = to_mclass(model, node.out_nodes("CLASS").first)
                        var rank = node["rank"].to_s.to_i
                        var mtype = mclass.mparameters[rank]
-                       mentities[node] = mtype
+                       mentities[node.id.as(Int)] = mtype
                        return  mtype
                else if node.labels.has("MNullableType") then
                        var intype = to_mtype(model, node.out_nodes("TYPE").first)
                        var mtype = intype.as_nullable
-                       mentities[node] = mtype
+                       mentities[node.id.as(Int)] = mtype
                        return mtype
                else if node.labels.has("MVirtualType") then
                        var mproperty = to_mproperty(model, node.out_nodes("PROPERTY").first)
                        assert mproperty isa MVirtualTypeProp
                        var mtype = mproperty.mvirtualtype
-                       mentities[node] = mtype
+                       mentities[node.id.as(Int)] = mtype
                        return mtype
                else if node.labels.has("MSignature") then
                        # Get all param nodes
@@ -770,7 +742,7 @@ class NeoModel
                                return_mtype = to_mtype(model, ret_nodes.first)
                        end
                        var mtype = new MSignature(mparameters, return_mtype)
-                       mentities[node] = mtype
+                       mentities[node.id.as(Int)] = mtype
                        return mtype
                end
                print "not yet implemented to_mtype for {node.labels.join(",")}"
@@ -791,13 +763,15 @@ class NeoModel
        #
        # REQUIRE `node.labels.has("MParameter")`
        private fun to_mparameter(model: Model, node: NeoNode): MParameter do
-               if mentities.has_key(node) then return mentities[node].as(MParameter)
+               var m = mentities.get_or_null(node.id.as(Int))
+               if m isa MParameter then return m
+
                assert node.labels.has("MParameter")
                var name = node["name"].to_s
                var mtype = to_mtype(model, node.out_nodes("TYPE").first)
                var is_vararg = node["is_vararg"].as(Bool)
                var mparameter = new MParameter(name, mtype, is_vararg)
-               mentities[node] = mparameter
+               mentities[node.id.as(Int)] = mparameter
                return mparameter
        end
 
index e174145..a443b0a 100644 (file)
@@ -422,6 +422,13 @@ The Nit language documentation and the source code of its tools and libraries ma
                        if res.file_exists and "{res}/src/nit.nit".file_exists then return res.simplify_path
                end
 
+               # search in the PATH
+               var ps = "PATH".environ.split(":")
+               for p in ps do
+                       res = p/".."
+                       if res.file_exists and "{res}/src/nit.nit".file_exists then return res.simplify_path
+               end
+
                return null
        end
 end
index 14be6d4..966dee1 100755 (executable)
@@ -74,8 +74,8 @@ saferun()
        if test -n "$TIME"; then
                $TIME -o "$o" $a $TIMEOUT "$@"
        else
-               $TIMEOUT "$@"
                if test -n "$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
+               $TIMEOUT "$@"
        fi
 }