I'm new to Verilog and would really appreciate it if someone could help me with this. I have a task written in a separate file - "task.v" :
module task_create();
task assign_inp;
reg a,b,c,d;
//details
endtask
endmodule
I have a module that is calling this task:
module tb();
`include "task.v"
assign_inp(a,b,c,d);
endmodule
When I execute this, I get this error:
Module definition task_create cannot nest into module tb
When I remove the module and endmodule in task.v, I get this error:
Task must be contained inside a module
Where am I going wrong? Thank you so much!
Your task in in a module and so can only be seen in the module. What you can do is remove the module wrapper and just declare the task in a separate file.
task assign_inp;
reg a,b,c,d;
//details
endtask
You can include the task and you should be able to see the task.
Removing the modules works for me.
EDIT: You may need to declare the verilog file as a header file for the task
Related
I'm working on a personal project and I'm trying to get Lua to work on my embedded device.
I have my own simple file system that works with the the flash drive, and now I'm trying to use modules for the lua scripts that I run on the device.
I have edited linit.c, to make it also load the modules that are existing in the flash drive, and it works for a few modules, but for most of them it just gives me a syntax error when it parses the contents of the module. I have a lua interpreter running on my Windows machine and the code I'm writing is syntactically correct and works, and the Lua API that I use is of the same version 5.4 on the device.
These are the arguments I pass to
luaL_loadbufferx(L, luaCFunction, sizeOfModule, moduleName, "t")
where, L is the lua state, luaCFunction is the lua module wrapped in a C-style return statement, sizeOfModule, moduleName and t is selfexplanatory.
Right now luaL_loadbufferx is called in a loop for every module in my flash-drive, I have overwritten the openf function from the Lua API for these external modules.
This below is one of the examples of a module that gives me
"Syntax Error: PANIC, unprotected error in call to Lua API
[string "module"]:3: '(' expected near 'writeobj'"
File: module.lua
Contents:
function writeobj()
print('Hello World')
end
File: run.lua
Contents:
require ('module')
writeobj()
Does anyone know why this happens or did I not provide sufficient information? Please let me know.
The problem was that I thought the modules passed to the buffer had to be of the LuaToC form, i.e. "return { ...luamodule...}", but changing it to pass the module only to loadbuffer was sufficient enough because it covers the case of it not being in a C style return format.
When I try to create a new process on separate node using
Pid = spawn(mynode, mymodule, myfunction, [self()])
(myfunction/1 is exported), I get this error:
Error in process <0.10.0> on node 'no#de1' with exit value:
{undef,[{mymodule, myfunction, [<33.64.0>], []}]}
I tried to set -compile(export_all) flag, but assuming the additional braces in error log, this is not the case.
I don't know what causes the error and I have no clue what to do.
The error you get is saying “There is no module ‘mymodule’ and/or no function ‘mymodule:myfunction/1’”.
This means mymodule is not loaded in the code server of your separate node.
To load mymodule's code there you need something like this snippet or this function
Did you check that the module mymodule is in the path of no#de1?
When you spwan a process using spawn(mynode, mymodule, myfunction, [self()]), the VM needs to load the code before executing it.
If you use a high order function (a fun) in this way spawn(Node, Fun), then in is not more necessary to have the code in the path (but beware that any call to a function in the function definition need to be solved on the remote node)
go to no#de1 and run m(mymodule). It should clarify if the module is loadable and which functions does export.
also: check if the other node is reachable. Do a net_adm:ping on it.
I two modules in same src folder. mod1 declares function I wish to use in module mod2:
-module(mod1).
-export([myfunc/1]).
myfunc(A) -> {ok}.
In other module I not import mod1:
-module(mod2).
If I do "mod1:" in mod2 it recognizes "myfunc", problem is at run-time when I call mod1:myfunc(A) I get "undefined function mod1:myfunc/1"
I not understand why I get error if intellisense detect my mod1 function in mod2?
From the shell, you could try doing mod1:module_info(exports) to see the list of all the exported functions, though if your module is written as it is above, it should be generating a syntax error.
If, however, I'm wrong, and you actually do have it written properly in your module, (ie, it's just a typo here), try doing the following at the erlang shell:
c(mod1).
c(mod2).
And see if that works for you. This will compile and load the modules for you. If you don't have the module compiled (ie, it's just a .erl file in the directory), that's insufficient.
EDIT
Also, make sure that the beam files are being loaded properly when erlang launches. This is typically done by launching erl with erl -pa /path/to/beams
I'm new to Riak and new to Erlang. I have successfully created and run JS MapReduce jobs, now I'm trying to execute the following Reduce function:
http://web.archive.org/web/20130329021000/http://contrib.basho.com/delete_keys.html
What are the steps to execute this reduce function? Specifically,
Where should I put the code?
What should I type into addReducePhase( ) ?
Thanks
You should write something like:
MapReduceResult result = client.mapReduce("myBucket")
.addLinkPhase("bucketX", "test", false)
.addMapPhase(new NamedJSFunction("Riak.mapValuesJson"), false)
.addReducePhase(new NamedErlangFunction("riak_kv_mapreduce", "reduce_sort"), true)
.execute();
In this case the reduce phase call the function reduce_sort of erlang module riak_kv_mapreduce.
In your case you should call
.addReducePhase(new NamedErlangFunction("reduce_functions", "delete"), true)
(the true at the end is a flag that set if results have to be returned to client - last step - or not -intermediate step -)
The Erlang files should be compiled as .beam before use and added to 'add_paths' parameters in riak.config like
{add_paths, ["/home/vinz/riak/custom_modules/"]}
where /home/vinz/riak/custom_modules is the directory containing the compiled Erlang modules.
Refer to Basho Java Client readme for further information.
I hope this helps!
In Java there's a simple way to get path of a running jar file:
MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath()
But in Clojure we do not have class name, only namespace and functions. Same thing applies to the uncompiled scripts/REPL.
So my questions are:
How can we find a path to the running jar file?
How can we find a path to uncompiled source files?
By default the name of your class is the name of your AOT-compiled namespace (that's what gen-class is for), so you can simply use the namespace's class.
(ns foo.core
(:gen-class))
(defn this-jar
"utility function to get the name of jar in which this function is invoked"
[& [ns]]
;; The .toURI step is vital to avoid problems with special characters,
;; including spaces and pluses.
;; Source: https://stackoverflow.com/q/320542/7012#comment18478290_320595
(-> (or ns (class *ns*))
.getProtectionDomain .getCodeSource .getLocation .toURI .getPath))
(defn -main [& _]
(println (this-jar foo.core)))
Result of running:
$ java -cp foo-0.1.0-SNAPSHOT-standalone.jar foo.core
/home/rlevy/prj/foo/target/foo-0.1.0-SNAPSHOT-standalone.jar
The idea of classpath is to hide where classes come from. You may have classes with the same name loaded from different classloaders, you may have the same class in multiple jars and rely on classpath ordering to choose the correct one.
Why do you want to know? If it's for any other reason than debug/logging purposes you are on dangerous ground and should tread carefully.
In fact it's perfectly reasonable for classes to have no jar file. This can happen in java for any runtime generated classes (think proxies).
In clojure a simple example would be as shown in the repl session below... You'll see #mikera's suggestion works fine for clojure.lang.Atom which is a built in class. But when you use a deftype to create your own type, clojure generates a class and it has no location...
user> (prn (-> clojure.lang.Atom
(.getProtectionDomain)
(.getCodeSource)
(.getLocation)))
#<URL file:/workspace/clj-scratch/lib/clojure-1.3.0.jar>
nil
user> (deftype Foo [])
user.Foo
user> (prn (-> (Foo.)
(.getClass)
(.getProtectionDomain)
(.getCodeSource)
(.getLocation)))
nil
nil
user>
I haven't tried this, but it seems like all you need is a class instance. So for example can you not do this:
(-> (new Object) (.getClass) (.getProtectionDomain) (.getCodeSource) (.getLocation) (.getPath))
You could try getting the path from a class defined by Clojure itself, e.g.:
(-> clojure.lang.Atom (.getProtectionDomain) (.getCodeSource) (.getLocation))
=> file:/some/path/to/clojure-1.3.0.jar
I believe this is technically the running jar file if you are running Clojure scripts or coding at the REPL.
(defn this-jar
"utility function to get the name of jar in which this function is invoked"
[& [ns]]
(-> (or ns (class *ns*))
.getProtectionDomain .getCodeSource .getLocation .toURI .getPath))
Note that it's crucial to call .toURI to avoid problems with paths that have spaces as described in the equivalent Java question: How to get the path of a running JAR file?.
find source files in a jar: tools.namespace/clojure-sources-in-jar