oberonjs.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <p>
  5. Oberon module:
  6. </p>
  7. <textarea id="source" rows="10" cols="80">
  8. MODULE test;
  9. IMPORT JS;
  10. BEGIN
  11. JS.alert("Hello, World!")
  12. END test.
  13. </textarea>
  14. <p>
  15. <button onclick="compile()">Compile</button>
  16. <button onclick="compile(); run()">Compile &amp; Run</button>
  17. </p>
  18. <p id="compileErrors" style="color:red"></p>
  19. <p id="compileTime"></p>
  20. <textarea id="result" rows="10" cols="80">
  21. </textarea>
  22. <p>
  23. <button onclick="run()">Run</button>
  24. </p>
  25. <p id="runErrors" style="color:red"></p>
  26. <p id="runTime"></p>
  27. <p><a href="http://oberspace.dyndns.org">Home</a></p>
  28. <p><a href="https://github.com/vladfolts/oberonjs">Development</a></p>
  29. <p id="version"></p>
  30. <script>
  31. function require(){}
  32. </script>
  33. <script src="oc.js"></script>
  34. <script>
  35. if (typeof buildVersion != "undefined")
  36. document.getElementById("version").textContent = buildVersion;
  37. function compile(){
  38. var src = document.getElementById("source").value;
  39. var result;
  40. var errors = "";
  41. var start = new Date();
  42. try {
  43. result = require("oc.js").compile(src, function(e){
  44. errors += e;
  45. });
  46. }
  47. catch (e) {
  48. errors += e;
  49. }
  50. var compileTime = (new Date() - start) / 1000;
  51. if (!result)
  52. result = "";
  53. document.getElementById("result").value = result;
  54. document.getElementById("compileErrors").textContent = errors;
  55. document.getElementById("compileTime").textContent = "compile time (seconds): " + compileTime;
  56. }
  57. function run(){
  58. var errElement = document.getElementById("runErrors");
  59. errElement.textContent = "";
  60. var start = new Date();
  61. try{
  62. eval(document.getElementById("result").value);
  63. }
  64. catch (e){
  65. var errors = "" + e;
  66. errElement.textContent = errors;
  67. }
  68. var runTime = (new Date() - start) / 1000;
  69. document.getElementById("runTime").textContent = "run time (seconds): " + runTime;
  70. }
  71. </script>
  72. </body>
  73. </html>