There are three test case set in this homework.
You can use make example, make test, make bonus to run them.
We provide simple argument parser in parser.y, if output is not NULL, please use it as assembly filename, otherwise you can use the PROGRAM name as filename.
It would be something like:
codegen( ProgNode ){
char fn[128];
prog = node->name;
// Output format *.j
sprintf(fn, "%s.j", node->name);
fd = fopen(output ? output : fn, "w");
gen("..."); // Generate your assembly...
fclose(fd);
}
- Use float to implement real type.
Bonus:
- nested (pure) function
- string operation
- array assignment
Material:
Note the example of x := y + z (strings) in mapping:
java/lang/StringBuffer/append(java/lang/String;)Ljava/lang/StringBuffer;
should be:
java/lang/StringBuffer/append(Ljava/lang/String;)Ljava/lang/StringBuffer;
Hints:
- you may initialize the variables manually
- We have some built-in function such as
writelnI,writelnS, and you can find the implementation atexample/builtin-io/*.j.