mirror of https://github.com/aamine/cbc
* test/cbc: provide -I option to add load path.
* net/loveruby/cflat/compiler/Compiler.java: new option -I. * net/loveruby/cflat/parser/Parser.jj: allow nested library ID "a.b.c". * net/loveruby/cflat/compiler/LibraryLoader.java: ditto. * import/unistd.hb: declare fork, getpid, getppid. * import/sys/types.hb: new file. * test/fork.cb: test nested library ID "sys.types". git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3829 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
1b544d25f6
commit
cf37e6ae72
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
Mon Jan 14 21:48:59 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* test/cbc: provide -I option to add load path.
|
||||
|
||||
* net/loveruby/cflat/compiler/Compiler.java: new option -I.
|
||||
|
||||
* net/loveruby/cflat/parser/Parser.jj: allow nested library ID
|
||||
"a.b.c".
|
||||
|
||||
* net/loveruby/cflat/compiler/LibraryLoader.java: ditto.
|
||||
|
||||
* import/unistd.hb: declare fork, getpid, getppid.
|
||||
|
||||
* import/sys/types.hb: new file.
|
||||
|
||||
* test/fork.cb: test nested library ID "sys.types".
|
||||
|
||||
Mon Jan 14 21:23:33 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* move *.hb files from test/ to import/.
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// sys/types.hb
|
||||
|
||||
typedef int pid_t;
|
|
@ -1,3 +1,8 @@
|
|||
// unistd.hb
|
||||
|
||||
import sys.types;
|
||||
|
||||
extern void _exit(int status);
|
||||
extern pid_t fork(void);
|
||||
extern pid_t getpid(void);
|
||||
extern pid_t getppid(void);
|
||||
|
|
|
@ -40,7 +40,18 @@ public class Compiler {
|
|||
while (it.hasNext()) {
|
||||
String arg = (String)it.next();
|
||||
if (arg.startsWith("-")) {
|
||||
if (arg.equals("--check-syntax")
|
||||
if (arg.startsWith("-I")) {
|
||||
String path = arg.substring(2);
|
||||
if (path.length() == 0) {
|
||||
if (! it.hasNext()) {
|
||||
errorExit("-I option missing argument");
|
||||
}
|
||||
it.remove();
|
||||
path = (String)it.next();
|
||||
}
|
||||
loader.addLoadPath(path);
|
||||
}
|
||||
else if (arg.equals("--check-syntax")
|
||||
|| arg.equals("--dump-tokens")
|
||||
|| arg.equals("--dump-ast")
|
||||
|| arg.equals("--dump-reference")
|
||||
|
@ -50,11 +61,9 @@ public class Compiler {
|
|||
arg + " option is exclusive");
|
||||
}
|
||||
mode = arg;
|
||||
it.remove();
|
||||
}
|
||||
else if (arg.equals("--debug-parser")) {
|
||||
debugParser = true;
|
||||
it.remove();
|
||||
}
|
||||
else if (arg.equals("--help")) {
|
||||
printUsage(System.out);
|
||||
|
@ -65,6 +74,7 @@ public class Compiler {
|
|||
printUsage(System.err);
|
||||
System.exit(1);
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (mode == null) {
|
||||
|
|
|
@ -20,6 +20,10 @@ public class LibraryLoader {
|
|||
loadedLibrary = new HashMap();
|
||||
}
|
||||
|
||||
public void addLoadPath(String path) {
|
||||
loadPath.add(path);
|
||||
}
|
||||
|
||||
public Declarations loadLibrary(String libid, ErrorHandler handler)
|
||||
throws CompileException {
|
||||
if (loadedLibrary.containsKey(libid)) {
|
||||
|
@ -36,7 +40,7 @@ public class LibraryLoader {
|
|||
Iterator pathes = loadPath.iterator();
|
||||
while (pathes.hasNext()) {
|
||||
String path = (String)pathes.next();
|
||||
File file = new File(path + "/" + libid + ".hb");
|
||||
File file = new File(path + "/" + libPath(libid) + ".hb");
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
|
@ -48,4 +52,8 @@ public class LibraryLoader {
|
|||
throw new FileException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected String libPath(String id) {
|
||||
return id.replace('.', '/');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,9 +388,17 @@ Declarations import_stmts():
|
|||
}
|
||||
|
||||
String import_stmt():
|
||||
{ String n; }
|
||||
{
|
||||
<IMPORT> n=name() ";" { return n; }
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String n;
|
||||
}
|
||||
{
|
||||
<IMPORT> n=name() { buf.append(n); }
|
||||
("." n=name() { buf.append("."); buf.append(n); } )*
|
||||
";"
|
||||
{
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Declarations top_decls():
|
||||
|
|
2
test/cbc
2
test/cbc
|
@ -1,2 +1,2 @@
|
|||
#!/bin/sh
|
||||
java -classpath ../build/classes net.loveruby.cflat.compiler.Compiler ${@+"$@"}
|
||||
java -classpath ../build/classes net.loveruby.cflat.compiler.Compiler -I../import ${@+"$@"}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import stdio;
|
||||
import unistd;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (fork()) {
|
||||
printf("parent: pid=%d ppid=%d\n", getpid(), getppid());
|
||||
}
|
||||
else {
|
||||
printf("child : pid=%d ppid=%d\n", getpid(), getppid());
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue