Permalink
Browse files

More optimizations, test script

  • Loading branch information...
1 parent b782d67 commit 97205683702c6d6dd7bb79940110f3f141bdce81 @fasterthanlime committed Aug 28, 2009
Showing with 414 additions and 383 deletions.
  1. +1 −0 .gitignore
  2. +0 −14 build.sh
  3. +2 −0 sdk/lang/ooclib.ooc
  4. +6 −2 src/org/ooc/backend/cdirty/AwesomeWriter.java
  5. +11 −19 src/org/ooc/backend/cdirty/ClassDeclWriter.java
  6. +8 −13 src/org/ooc/backend/cdirty/FunctionCallWriter.java
  7. +15 −11 src/org/ooc/backend/cdirty/ModuleWriter.java
  8. +24 −17 src/org/ooc/frontend/CommandLine.java
  9. +2 −2 src/org/ooc/frontend/PathList.java
  10. +17 −5 src/org/ooc/frontend/model/ArrayAccess.java
  11. +30 −16 src/org/ooc/frontend/model/BinaryOperation.java
  12. +0 −6 src/org/ooc/frontend/model/BuiltinType.java
  13. +8 −55 src/org/ooc/frontend/model/ClassDecl.java
  14. +4 −15 src/org/ooc/frontend/model/CoverDecl.java
  15. +1 −0 src/org/ooc/frontend/model/FuncType.java
  16. +3 −5 src/org/ooc/frontend/model/FunctionCall.java
  17. +3 −13 src/org/ooc/frontend/model/Instantiation.java
  18. +9 −7 src/org/ooc/frontend/model/MemberAccess.java
  19. +4 −3 src/org/ooc/frontend/model/MemberCall.java
  20. +22 −0 src/org/ooc/frontend/model/Module.java
  21. +4 −0 src/org/ooc/frontend/model/NodeList.java
  22. +8 −9 src/org/ooc/frontend/model/Type.java
  23. +33 −4 src/org/ooc/frontend/model/TypeDecl.java
  24. +0 −5 src/org/ooc/frontend/model/TypeParam.java
  25. +2 −6 src/org/ooc/frontend/model/VariableAccess.java
  26. +3 −2 src/org/ooc/frontend/model/VariableDecl.java
  27. +9 −9 src/org/ooc/frontend/parser/CoverDeclParser.java
  28. +1 −1 src/org/ooc/frontend/parser/ImportParser.java
  29. +1 −1 src/org/ooc/frontend/parser/IncludeParser.java
  30. +1 −1 src/org/ooc/frontend/parser/LineParser.java
  31. +27 −0 src/org/ooc/frontend/parser/ModuleParser.java
  32. +1 −1 src/org/ooc/frontend/parser/OpDeclParser.java
  33. +2 −3 src/org/ooc/frontend/parser/TypeParser.java
  34. +1 −1 src/org/ooc/frontend/parser/UseParser.java
  35. +1 −1 src/org/ooc/middle/hobgoblins/Checker.java
  36. +3 −65 src/org/ooc/middle/hobgoblins/Resolver.java
  37. +74 −15 src/org/ooc/middle/hobgoblins/Unwrapper.java
  38. +37 −7 src/org/ooc/middle/structs/MultiMap.java
  39. +1 −1 tests/arrays/006-literal-fitsin.ooc
  40. +12 −18 tests/inherit/001-callsuperfunc.ooc
  41. +8 −15 tests/inherit/002-thiscall.ooc
  42. +8 −14 tests/inherit/003-supercall.ooc
  43. +3 −1 tests/statements/001-if-inside-of-while.ooc
  44. BIN utils/jar-in-jar-loader.zip
  45. +4 −0 utils/test
View
@@ -2,4 +2,5 @@
*.gen
bin/*
build/
+utils/test-suite
ooc_tmp
View
@@ -1,14 +0,0 @@
-cc=-tcc
-flags=-t -r -dyngc $cc
-
-cd tests/
-for dir in $(ls); do
- cd $dir
- for file in $(find ./ -name "*.ooc"); do
- ooc -sourcepath=$dir/ $file $flags
- code=$?
- if [[ code -ne 0 ]]; then
- exit
- fi
- done
-done
View
@@ -1,5 +1,7 @@
include stdlib, stdio, stdint, stdbool, memory, gc/gc, string
+void: extern cover
+
Char: cover from char
String: cover from Char*
Pointer: cover from void*
@@ -19,13 +19,17 @@ protected AwesomeWriter closeBlock() throws IOException {
}
protected AwesomeWriter openBlock() throws IOException {
- appendable.append("\n{");
+ appendable.append('\n');
+ appendable.append(tab, 0, tabLevel);
+ appendable.append('{');
tabLevel++;
return this;
}
protected AwesomeWriter openSpacedBlock() throws IOException {
- appendable.append("\n{\n");
+ appendable.append('\n');
+ appendable.append(tab, 0, tabLevel);
+ appendable.append("{\n");
tabLevel++;
appendable.append(tab, 0, tabLevel);
return this;
@@ -167,7 +167,7 @@ public static void writeDestroyFunc(ClassDecl classDecl, String className,
public static void writeInstanceImplFuncs(ClassDecl classDecl,
String className, CGenerator cgen) throws IOException {
- /* Non-static (ie. instance) functions */
+ // Non-static (ie. instance) functions
for (FunctionDecl decl : classDecl.getFunctions()) {
if (decl.isStatic() || decl.isAbstract())
continue;
@@ -180,10 +180,8 @@ public static void writeInstanceImplFuncs(ClassDecl classDecl,
if (!decl.isFinal())
cgen.current.app("_impl");
- writeFuncArgs(decl, decl.isConstructor(), cgen); // if is
- // constuctor,
- // don't write
- // the first arg
+ // if is constuctor, don't write the first arg
+ writeFuncArgs(decl, decl.isConstructor(), cgen);
cgen.current.openBlock();
@@ -202,10 +200,7 @@ public static void writeInstanceImplFuncs(ClassDecl classDecl,
}
cgen.current.closeSpacedBlock();
- /*
- * Special case: constructor, now write the corresponding construct
- * function
- */
+ // Special case: constructor, now write the corresponding construct
if (decl.isConstructor()) {
cgen.current.app("void ").app(className).app("_construct");
if (!decl.getSuffix().isEmpty())
@@ -266,9 +261,7 @@ public static void writeFuncPointers(ClassDecl writerClass,
}
for (FunctionDecl decl : writerClass.getFunctions()) {
- if (decl.isStatic())
- continue;
- if (decl.isConstructor())
+ if (decl.isStatic() || decl.isConstructor())
continue;
if (decl.isFinal() || decl.isAbstract()) {
@@ -308,19 +301,18 @@ public static void writeMemberFuncPrototypes(ClassDecl classDecl,
cgen.current.nl();
}
- public static Iterator<Argument> writeFuncPointer(FunctionDecl decl, CGenerator cgen)
+ public static void writeFuncPointer(FunctionDecl decl, CGenerator cgen)
throws IOException {
decl.getReturnType().accept(cgen);
cgen.current.app(" (*").app(decl.getName()).app(")(");
- Iterator<Argument> iter = decl.getArguments().iterator();
- while (iter.hasNext()) {
- Argument arg = iter.next();
- arg.accept(cgen);
- if (iter.hasNext())
+ int numArgs = decl.getArguments().size() - 1;
+ Node[] args = decl.getArguments().getNodes();
+ for (int i = 0; i <= numArgs; i++) {
+ args[i].accept(cgen);
+ if (i < numArgs)
cgen.current.app(", ");
}
cgen.current.app(')');
- return iter;
}
public static void writeClassStruct(ClassDecl classDecl, String className, CGenerator cgen)
@@ -10,33 +10,28 @@
public static void write(FunctionCall functionCall, CGenerator cgen) throws IOException {
- FunctionDecl decl = functionCall.getImpl();
+ FunctionDecl impl = functionCall.getImpl();
if(functionCall.isConstructorCall()) {
- cgen.current.app(decl.getTypeDecl().getName());
- if(functionCall.getImpl().getTypeDecl() instanceof ClassDecl) {
+ cgen.current.app(impl.getTypeDecl().getName());
+ if(impl.getTypeDecl() instanceof ClassDecl) {
cgen.current.app("_construct");
} else{
cgen.current.app("_new");
}
- if(!decl.getSuffix().isEmpty()) {
- cgen.current.app('_');
- cgen.current.app(decl.getSuffix());
- }
- } else if(decl.isFromPointer()) {
+ if(!impl.getSuffix().isEmpty()) cgen.current.app('_').app(impl.getSuffix());
+ } else if(impl.isFromPointer()) {
cgen.current.app(functionCall.getName());
} else {
- decl.writeFullName(cgen.current);
+ impl.writeFullName(cgen.current);
}
- FunctionDecl impl = functionCall.getImpl();
NodeList<Expression> args = functionCall.getArguments();
-
cgen.current.app('(');
if(functionCall.isConstructorCall() && impl.getTypeDecl() instanceof ClassDecl) {
cgen.current.app('(');
- decl.getTypeDecl().getInstanceType().accept(cgen);
+ impl.getTypeDecl().getInstanceType().accept(cgen);
cgen.current.app(')');
- cgen.current.app(" cgen");
+ cgen.current.app(" this");
if(!args.isEmpty()) cgen.current.app(", ");
}
writeCallArgs(args, impl, cgen);
@@ -28,13 +28,15 @@ public static void write(Module module, CGenerator cgen) throws IOException {
IncludeWriter.write(include, cgen);
}
- for(Node node: module.getBody()) {
- if(node instanceof ClassDecl) {
- ClassDecl classDecl = (ClassDecl) node;
- ClassDeclWriter.writeStructTypedef(classDecl.getName(), cgen);
- ClassDeclWriter.writeStructTypedef(classDecl.getName()+"Class", cgen);
- } else if(node instanceof CoverDecl) {
- CoverDeclWriter.writeTypedef((CoverDecl) node, cgen);
+ for(String key: module.getTypes().keySet()) {
+ for(TypeDecl node : module.getTypes().getAll(key)) {
+ if(node instanceof ClassDecl) {
+ ClassDecl classDecl = (ClassDecl) node;
+ ClassDeclWriter.writeStructTypedef(classDecl.getName(), cgen);
+ ClassDeclWriter.writeStructTypedef(classDecl.getName()+"Class", cgen);
+ } else if(node instanceof CoverDecl) {
+ CoverDeclWriter.writeTypedef((CoverDecl) node, cgen);
+ }
}
}
cgen.current.nl();
@@ -58,7 +60,11 @@ public static void write(Module module, CGenerator cgen) throws IOException {
cgen.current.app(".h\"");
cgen.current.nl();
- cgen.current = cgen.cw;
+ for(String key: module.getTypes().keySet()) {
+ for(TypeDecl node : module.getTypes().getAll(key)) {
+ node.accept(cgen);
+ }
+ }
module.acceptChildren(cgen);
ModuleWriter.writeInitFunc(cgen);
@@ -102,9 +108,7 @@ public static void writeInitFunc(CGenerator cgen)
for (Node node : cgen.module.getBody()) {
if (node instanceof ClassDecl) {
ClassDecl classDecl = (ClassDecl) node;
- cgen.current.nl().app(
- classDecl.getInstanceType().getMangledName());
- cgen.current.app("_load();");
+ cgen.current.nl().app(classDecl.getName()).app("_").app(classDecl.getLoadFunc().getName()).app("();");
}
}
for (Node node : cgen.module.getLoadFunc().getBody()) {
@@ -27,19 +27,14 @@
import org.ooc.frontend.model.Include.Mode;
import org.ooc.frontend.parser.BuildParams;
import org.ooc.frontend.parser.Parser;
-import org.ooc.middle.OocCompilationError;
import org.ooc.middle.Tinkerer;
import org.ooc.outputting.FileUtils;
+import org.ubi.CompilationFailedError;
public class CommandLine {
public static void main(String[] argv) throws InterruptedException, IOException {
- try {
- new CommandLine(argv);
- } catch(OocCompilationError err) {
- System.err.println(err);
- System.exit(1);
- }
+ new CommandLine(argv);
}
protected BuildParams params = new BuildParams();
@@ -204,11 +199,20 @@ public CommandLine(String[] args) throws InterruptedException, IOException {
if(params.sourcePath.isEmpty()) params.sourcePath.add(".");
params.sourcePath.add(params.distLocation + File.separator + "sdk");
+ int successCount = 0;
for(String modulePath: modulePaths) {
- parse(modulePath);
- if(params.clean) {
- FileUtils.deleteRecursive(params.outPath);
+ try {
+ int code = parse(modulePath);
+ if(code == 0) successCount++;
+ } catch(CompilationFailedError err) {
+ System.err.println(err);
}
+ if(params.clean) FileUtils.deleteRecursive(params.outPath);
+ }
+
+ if(modulePaths.size() > 1) {
+ System.out.println(modulePaths.size()+" compiled ("+successCount
+ +" success, "+(modulePaths.size() - successCount)+" failed)");
}
}
@@ -251,7 +255,7 @@ private void compileNasms(List<String> nasms, Collection<String> list) throws IO
}
- protected void parse(String modulePath) throws InterruptedException, IOException {
+ protected int parse(String modulePath) throws InterruptedException, IOException {
params.outPath.mkdirs();
long tt1 = System.nanoTime();
@@ -262,25 +266,26 @@ protected void parse(String modulePath) throws InterruptedException, IOException
long tt3 = System.nanoTime();
output(module, new HashSet<Module>());
long tt4 = System.nanoTime();
- compile(module);
+ int code = compile(module);
long tt5 = System.nanoTime();
if(params.timing) {
- System.out.printf("parse: %.2f ms, tink: %.2f ms, out: %.2f, cc: %.2f ms, TOTAL %.2f ms\n",
+ System.out.printf("parse: %.2f ms\ttink: %.2f ms\tout: %.2f\tcc: %.2f ms\tTOTAL %.2f ms\n",
Float.valueOf((tt2 - tt1) / 1000000.0f),
Float.valueOf((tt3 - tt2) / 1000000.0f),
Float.valueOf((tt4 - tt3) / 1000000.0f),
Float.valueOf((tt5 - tt4) / 1000000.0f),
Float.valueOf((tt5 - tt1) / 1000000.0f));
}
- if(params.run) {
+ if(code == 0 && params.run) {
ProcessBuilder builder = new ProcessBuilder();
builder.command("./"+module.getSimpleName());
Process process = builder.start();
ProcessUtils.redirectIO(process);
process.waitFor();
}
+ return code;
}
@@ -304,15 +309,17 @@ protected void tinker(Module module, Set<Module> done) throws IOException {
}
}
- protected void compile(Module module) throws Error,
+ protected int compile(Module module) throws Error,
IOException, InterruptedException {
compiler.reset();
for(Include inc: module.getIncludes()) {
if(inc.getMode() == Mode.LOCAL) {
- FileUtils.copy(new File(inc.getPath() + ".h"),
+ try {
+ FileUtils.copy(new File(inc.getPath() + ".h"),
new File(params.outPath, inc.getPath() + ".h"));
+ } catch(Exception e) { e.printStackTrace(); }
}
}
@@ -350,8 +357,8 @@ protected void compile(Module module) throws Error,
int code = compiler.launch();
if(code != 0) {
System.err.println("C compiler failed, aborting compilation process");
- System.exit(code);
}
+ return code;
}
@@ -33,10 +33,10 @@ public void add(String path) {
File file = new File(path);
if(!file.exists()) {
- System.err.println("Classpath element cannot be found: "+file.getPath());
+ System.err.println("Classpath element cannot be found: "+path);
return;
} else if(!file.isDirectory()) {
- System.err.println("Classpath element is not a directory: "+file.getPath());
+ System.err.println("Classpath element is not a directory: "+path);
return;
}
@@ -99,14 +99,26 @@ public boolean resolve(NodeList<Node> stack, Resolver res, boolean fatal)
int assignIndex = stack.find(Assignment.class);
- for(OpDecl op: res.ops) {
- if(assignIndex == -1) {
- if(tryIndexing(op, stack)) break;
- } else {
- if(tryIndexedAssign(op, stack, assignIndex)) break;
+ for(OpDecl op: res.module.getOps()) {
+ if(tryOp(stack, assignIndex, op)) break;
+ }
+ for(Import imp: res.module.getImports()) {
+ for(OpDecl op: imp.getModule().getOps()) {
+ if(tryOp(stack, assignIndex, op)) break;
}
}
+ return false;
+
+ }
+
+ private boolean tryOp(NodeList<Node> stack, int assignIndex, OpDecl op)
+ throws OocCompilationError, EOFException {
+ if(assignIndex == -1) {
+ if(tryIndexing(op, stack)) return true;
+ } else {
+ if(tryIndexedAssign(op, stack, assignIndex)) return true;
+ }
return false;
}
Oops, something went wrong.

0 comments on commit 9720568

Please sign in to comment.