diff options
| author | 2026-11-08 06:49:14 +0000 | |
|---|---|---|
| committer | 2026-11-08 06:49:14 +0000 | |
| commit | 0e856ca15d8aa1499edc33c7302d4d97be404290 (patch) | |
| tree | d2bb840d13c57aa17f643e6039af370255e38379 /README.org | |
| download | lab-04-0e856ca15d8aa1499edc33c7302d4d97be404290.tar.gz | |
Diffstat (limited to 'README.org')
| -rw-r--r-- | README.org | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/README.org b/README.org new file mode 100644 index 0000000..8dd015a --- /dev/null +++ b/README.org | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | #+title: Refinement of the CMiLan compiler | ||
| 2 | #+subtitle: Adding function support | ||
| 3 | #+date: 2025H1 | ||
| 4 | |||
| 5 | * Introduction | ||
| 6 | :PROPERTIES: | ||
| 7 | :CUSTOM_ID: introduction | ||
| 8 | :UNNUMBERED: toc | ||
| 9 | :END: | ||
| 10 | /Milan/ is an educational procedural programming language. The standard | ||
| 11 | distribution of the /CMilan/ compiler supports the definition of only | ||
| 12 | one procedure, which is the entry point of the program. In this | ||
| 13 | laboratory work, the compiler is extended to implement declarations, | ||
| 14 | definitions, and function calls. | ||
| 15 | |||
| 16 | * Refinement description | ||
| 17 | :PROPERTIES: | ||
| 18 | :CUSTOM_ID: refinement-description | ||
| 19 | :END: | ||
| 20 | All functions must be declared before the entry point is defined, and | ||
| 21 | defined after it. In the function declarations, you need to specify | ||
| 22 | the number of arguments and indicate whether it returns a single value | ||
| 23 | or does not return anything. | ||
| 24 | |||
| 25 | Several functions can have the same name if they have different | ||
| 26 | numbers of arguments (function-overloading). You can declare local | ||
| 27 | variables in functions, which shadow global variables. The compiler | ||
| 28 | eliminates tail calls. | ||
| 29 | |||
| 30 | Obviously, some changes had to be made to the virtual machine as well, | ||
| 31 | i.e. stack framing. | ||
| 32 | |||
| 33 | * Documentation | ||
| 34 | :PROPERTIES: | ||
| 35 | :CUSTOM_ID: documentation | ||
| 36 | :END: | ||
| 37 | The exported report can be found at [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-04/report.pdf][this link]]. | ||
| 38 | |||
| 39 | * Showcase | ||
| 40 | :PROPERTIES: | ||
| 41 | :CUSTOM_ID: showcase | ||
| 42 | :END: | ||
| 43 | ** Doubling a number | ||
| 44 | *Source code:* | ||
| 45 | #+include: "src/double.mil" src text | ||
| 46 | |||
| 47 | *Machine commands:* | ||
| 48 | #+include: "build/double.ms" src text | ||
| 49 | |||
| 50 | *Usage:* | ||
| 51 | #+begin_src text | ||
| 52 | > 10 | ||
| 53 | 20 | ||
| 54 | #+end_src | ||
| 55 | |||
| 56 | ** GCD | ||
| 57 | *Source code:* | ||
| 58 | #+include: "src/gcd.mil" src text | ||
| 59 | |||
| 60 | *Machine commands:* | ||
| 61 | #+include: "build/gcd.ms" src text | ||
| 62 | |||
| 63 | *Usage:* | ||
| 64 | #+begin_src text | ||
| 65 | > 9 | ||
| 66 | > 6 | ||
| 67 | 3 | ||
| 68 | #+end_src | ||
| 69 | |||
| 70 | ** Factorial (w/o tail-call elimination) | ||
| 71 | *Source code:* | ||
| 72 | #+include: "src/fac.mil" src text | ||
| 73 | |||
| 74 | *Machine commands:* | ||
| 75 | #+include: "build/fac.ms" src text | ||
| 76 | |||
| 77 | *Usage:* | ||
| 78 | #+begin_src text | ||
| 79 | > 31 | ||
| 80 | 738197504 | ||
| 81 | #+end_src | ||
| 82 | |||
| 83 | ** Factorial (w/ tail-call elimination) | ||
| 84 | *Source code:* | ||
| 85 | #+include: "src/fac-tail.mil" src text | ||
| 86 | |||
| 87 | *Machine commands:* | ||
| 88 | #+include: "build/fac-tail.ms" src text | ||
| 89 | |||
| 90 | *Usage:* | ||
| 91 | #+begin_src text | ||
| 92 | > 31 | ||
| 93 | 738197504 | ||
| 94 | #+end_src | ||
| 95 | |||
| 96 | ** Fibonacci (w/o tail-call elimination) | ||
| 97 | *Source code:* | ||
| 98 | #+include: "src/fib.mil" src text | ||
| 99 | |||
| 100 | *Machine commands:* | ||
| 101 | #+include: "build/fib.ms" src text | ||
| 102 | |||
| 103 | *Usage:* | ||
| 104 | #+begin_src text | ||
| 105 | > 20000 | ||
| 106 | Error: stack overflow | ||
| 107 | Code: | ||
| 108 | |||
| 109 | 14 CALL 4 | ||
| 110 | VM error | ||
| 111 | #+end_src | ||
| 112 | |||
| 113 | ** Fibonacci (w/ tail-call elimination) | ||
| 114 | *Source code:* | ||
| 115 | #+include: "src/fib-tail.mil" src text | ||
| 116 | |||
| 117 | *Machine commands:* | ||
| 118 | #+include: "build/fib-tail.ms" src text | ||
| 119 | |||
| 120 | *Usage:* | ||
| 121 | #+begin_src text | ||
| 122 | > 1000000 | ||
| 123 | 1884755131 | ||
| 124 | #+end_src | ||
| 125 | |||
| 126 | * Unlicense | ||
| 127 | :PROPERTIES: | ||
| 128 | :CUSTOM_ID: unlicense | ||
| 129 | :END: | ||
| 130 | #+include: UNLICENSE verse | ||
