- dir = "{dir}/java"
- dir.mkdir
- file = new OFStream.open("{dir}/{name}.java")
-
- var cl = ""
- if interfaces then cl = "X"
- write "class {name} \{"
- if interfaces then
- write "static interface Root\n\t\{ int id(); \}"
- else
- write "static class Root\n\t\{ int id() \{ return 0;\} \}"
- end
- for c in classes do
- if interfaces then
- write "static interface {c}<E> "
- else
- write "static class {c}<E> "
- end
- if c.supers.is_empty then
- write "\textends Root"
- else for s in [c.supers.first] do
- write "\textends {s}<E>"
- end
- if interfaces then
- write "\{\}"
- write "static class X{c}<E> implements {c}<E>"
- end
- write "\{"
- write "\tpublic int id() \{ return {c.id}; \}"
- write "\}"
- end
-
- write "static public void main(String args[]) \{"
- if interfaces then
- write "\t{classes.first}<Root> a = new X{classes.last}<Root>();"
- write "\t{classes.first}<Root> b = new X{classes.first}<Root>();"
- for c in classes do
- write "\t\t\tif (a.id() > 0) a = new X{c}<Root>();"
- end
- else
- write "\t{classes.first}<Root> a = new {classes.last}<Root>();"
- write "\t{classes.first}<Root> b = new {classes.first}<Root>();"
- for c in classes do
- write "\t\t\tif (a.id() > 0) a = new {c}<Root>();"
- end
- end
- write "\ttest(b, b, 10, -100);"
- write "\ttest(a, a, {loops}, 0);"
- write "\}"
-
- write "static public void test({classes.first}<Root> a, {classes.first}<Root> b, int loops, int start) \{"
- write "\tint x = start;"
- write "\tfor(int i = 0; i < loops; i++) \{"
- write "\t\tfor(int j = 0; j < loops; j++) \{"
- var test
- if dry then test = "" else test = "a instanceof {classes[middle]} && "
- write "\t\t\tif({test}x>=0) \{"
- if check then write "\t\t\t\tx += 1"
- write "\t\t\t\} else \{ x--; a = b;\}"
- write "\t\t}"
- write "\t\}"
- write "\tSystem.out.println(x);"
- write "\}"
- write "\}"
- file.close