2
0

main.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 
  2. // Because it would be slow to check if the build system needs to be recompiled every time something uses it,
  3. // you must manually delete the build system's binary and try to build a project using it after making changes to the builder's source code.
  4. // Otherwise buildProject.sh will just see that an old version exists and use it.
  5. // TODO:
  6. // * Implement more features for the machine, such as:
  7. // * Unary negation.
  8. // * else and elseif cases.
  9. // * Temporarily letting the theoretical path go into another folder within a scope, similar to if statements but only affecting the path.
  10. // Like writing (cd path; stmt;) in Bash but with fast parsed Basic-like syntax.
  11. // The same stack used to store theoretical paths might be useful for else if cases to remember when the scope has already passed a case when not jumping with gotos.
  12. // * Create portable scripted events for pre-build and post-build, translated into both Batch and Bash.
  13. // Pre-build can be used to generate and transpile code before compiling.
  14. // Post-build should be used to execute the resulting program.
  15. // Optionally with variables from the build script as input arguments.
  16. #include "../../DFPSR/api/fileAPI.h"
  17. #include "generator.h"
  18. using namespace dsr;
  19. // List dependencies for main.cpp on Linux: ./builder main.cpp --depend
  20. DSR_MAIN_CALLER(dsrMain)
  21. void dsrMain(List<String> args) {
  22. if (args.length() <= 2) {
  23. printText(U"To use the DFPSR build system, pass a path to the project file and the flags you want assigned before running the build script.\n");
  24. } else {
  25. // Get the project file path from the first argument after the program name.
  26. String projectFilePath = args[1];
  27. String platform = args[2];
  28. Machine settings;
  29. // Begin reading input arguments after the project's path, as named integers assigned to ones.
  30. // Calling builder with the extra arguments "Graphics" and "Linux" will then create and assign both variables to 1.
  31. // Other values can be assigned using an equality sign.
  32. // Avoid spaces around the equality sign, because quotes are already used for string arguments in assignments.
  33. for (int a = 2; a < args.length(); a++) {
  34. String argument = args[a];
  35. int64_t assignmentIndex = string_findFirst(argument, U'=');
  36. if (assignmentIndex == -1) {
  37. assignValue(settings, argument, U"1");
  38. printText(U"Assigning ", argument, U" to 1 from input argument.\n");
  39. } else {
  40. String key = string_removeOuterWhiteSpace(string_before(argument, assignmentIndex));
  41. String value = string_removeOuterWhiteSpace(string_after(argument, assignmentIndex));
  42. assignValue(settings, key, value);
  43. printText(U"Assigning ", key, U" to ", value, U" from input argument.\n");
  44. }
  45. }
  46. // Evaluate compiler settings while searching for source code mentioned in the project and imported headers.
  47. printText(U"Executing project file from ", projectFilePath, U".\n");
  48. evaluateScript(settings, projectFilePath);
  49. // Once we are done finding all source files, we can resolve the dependencies to create a graph connected by indices.
  50. resolveDependencies();
  51. if (getFlagAsInteger(settings, U"ListDependencies")) {
  52. printDependencies();
  53. }
  54. generateCompilationScript(settings, file_getAbsoluteParentFolder(projectFilePath));
  55. }
  56. }