diff --git a/ChangeLog b/ChangeLog index ced9c9c..4c7c52f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +Mon Jan 14 21:48:59 2008 Minero Aoki + + * 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 * move *.hb files from test/ to import/. diff --git a/import/sys/types.hb b/import/sys/types.hb new file mode 100644 index 0000000..77a37c9 --- /dev/null +++ b/import/sys/types.hb @@ -0,0 +1,3 @@ +// sys/types.hb + +typedef int pid_t; diff --git a/import/unistd.hb b/import/unistd.hb index fa10b95..2fe302a 100644 --- a/import/unistd.hb +++ b/import/unistd.hb @@ -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); diff --git a/net/loveruby/cflat/compiler/Compiler.java b/net/loveruby/cflat/compiler/Compiler.java index 7539089..7364245 100644 --- a/net/loveruby/cflat/compiler/Compiler.java +++ b/net/loveruby/cflat/compiler/Compiler.java @@ -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) { diff --git a/net/loveruby/cflat/compiler/LibraryLoader.java b/net/loveruby/cflat/compiler/LibraryLoader.java index 0af690b..95fd918 100644 --- a/net/loveruby/cflat/compiler/LibraryLoader.java +++ b/net/loveruby/cflat/compiler/LibraryLoader.java @@ -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('.', '/'); + } } diff --git a/net/loveruby/cflat/parser/Parser.jj b/net/loveruby/cflat/parser/Parser.jj index 8c2ecb5..0119bc6 100644 --- a/net/loveruby/cflat/parser/Parser.jj +++ b/net/loveruby/cflat/parser/Parser.jj @@ -388,9 +388,17 @@ Declarations import_stmts(): } String import_stmt(): -{ String n; } { - n=name() ";" { return n; } + StringBuffer buf = new StringBuffer(); + String n; +} +{ + n=name() { buf.append(n); } + ("." n=name() { buf.append("."); buf.append(n); } )* + ";" + { + return buf.toString(); + } } Declarations top_decls(): diff --git a/test/cbc b/test/cbc index 60c7a10..375dcdf 100755 --- a/test/cbc +++ b/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 ${@+"$@"} diff --git a/test/fork.cb b/test/fork.cb new file mode 100644 index 0000000..aa62965 --- /dev/null +++ b/test/fork.cb @@ -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; +}