Guest User

Untitled

a guest
Aug 7th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import subprocess
  4. import textwrap
  5.  
  6. expr = "-123%10"
  7.  
  8. def runner(name, cmds, source_fn=None, source=None):
  9. cmds = [[x.replace("EXPR", expr) for x in y] for y in cmds]
  10. if source is not None:
  11. source = textwrap.dedent(source.replace("EXPR", expr))
  12. with open(source_fn, "w") as f:
  13. f.write(source)
  14.  
  15. print(name + ": ", end="", flush=True)
  16. try:
  17. for cmd in cmds:
  18. subprocess.check_call(cmd)
  19. except:
  20. print("Error")
  21.  
  22. def main():
  23. print("Expression: " + expr)
  24.  
  25. runner("Python 2.7", [['python2.7', '-c', 'print(EXPR)']])
  26. runner("Python 3.9", [['python3.9', '-c', 'print(EXPR)']])
  27. runner("C", [['cc', 'test.c'], ['./a.out']], "test.c", r"""
  28. #include <stdio.h>
  29. int main() {printf("%f\n", (double)(EXPR));return 0;}
  30. """)
  31. runner("SQLite", [['sqlite3', ':memory:', 'select EXPR;']])
  32. runner("Node", [['node', '-e', 'require("./test").init()']], "test.js", r"""
  33. module.exports.init = function () {
  34. console.log(EXPR);
  35. };
  36. """)
  37. runner("Java", [['javac', 'test.java'], ['java', 'test']], "test.java", r"""
  38. public class test {
  39. public static void main(String[] args) {
  40. System.out.println(EXPR);
  41. }
  42. }
  43. """)
  44. runner("Go", [['go', 'run', 'test.go']], "test.go", r"""
  45. package main
  46. import "fmt"
  47. func main() {
  48. fmt.Println(EXPR)
  49. }
  50. """)
  51.  
  52. if __name__ == "__main__":
  53. main()
  54.  
Advertisement
Add Comment
Please, Sign In to add comment