# Introduction Minimacy is a combination of: - a high-level programming language - an instant compiler which compiles the high-level language into a bytecode - a virtual machine made of a virtual processor and a set of little independent instructions, written in C language - some of these instructions communicate with the underlying machine: o an OS based machine: Windows, Unix/Linux, MacOS, iOS, Android o or a bare-metal machine, such as a RaspberryPi [](html) As a developer, you may: - use the Minimacy programming language to implement your program - read the source code of the Virtual Processor and the instructions to fully understand how things are working - implement your own instructions in C when speed is critical or when you need to address a new hardware device - read the source code of the instant compiler for your own fun! # Hello world Let’s start with the "hello world" program. Create a new file "hello.mcy", and enter the following line: fun main() = echoLn "Hello world!";; What we can see there: { fun we are declaring a function (because functions are fun;-) main() the name of the function = the result of the function follows the sign “equals” echoLn this system function takes one argument, displays it and appends a newline "Hello world!" the argument for the function echoLn ;; this marks the end of the function declaration } Now you can start your program: - on windows: double-click on hello.mcy - on unix: [minimacy]/bin/minimacy hello.mcy - on macos: [minimacy]/bin/minimacyMac hello.mcy >> Minimacy - Sylvain Huet - 2020-24 - 1.3.0/Windows >> ---- >> 64 bits >> Minimacy directory : ~/minimacy/ >> Rom directory : ~/minimacy/rom/ >> BIOS compiled in 5 ms >> current time: Thu, 22 Feb 2024 18:32:39 UTC >> compiling 'hello' >>>>>>>>>> package: hello >> fun main : fun -> Str >> compiled in 0 ms > >Hello world! >> end of line { \> 64 bits This is the 64 bits version of Minimacy \> Minimacy directory: ~/minimacy The system directory. It is the directory containing the hello.mcy file \> Rom directory: ~/minimacy/rom/ The rom directory. It contains the BIOS source files \> BIOS compiled in 5 ms The BIOS is written in Minimacy and is compiled first. \> current time: Thu, 22 Feb 2024 18:32:39 UTC On some baremetal targets, it is convenient to check the clock. \> compiling 'hello' Start the compilation of hello.mcy \>>>>>>>>> package: hello This starts the dump of the compiled hello package \> fun main : fun -> Str The inferred type of the "main" function \> compiled in 0 ms Always fast! but this one was simple Hello world! The evaluation of the "main" function calls the [[echoLn]] function which displays this message on the console \> end of line This is the last system message before Minimacy terminates on its own } What we learn from this example: - Minimacy is a virtual machine which runs the Minimacy language - Minimacy source files have ".mcy" extension - When Minimacy starts with a ".mcy" file argument, it compiles the source file and calls the function “main” - The function “main” has no argument - It stops automatically when there is nothing more to compute and nothing to wait for - the machine did not create any intermediary file, such as a binary or bytecode file We wrote the function “main” in a single line but this was not mandatory. Minimacy does not take care of the spaces, tabulation or newlines. We could as well write it like this: fun main() = echoLn "Hello world!" ;; # Top-Level Locate the file “topLevel.mcy” in the Minimacy directory, and launch it. You get a Top-level interface with a prompt: >Minimacy Top-level >Ready >] It looks like a shell, but it is more than that. A dedicated empty package has been created for you and you can type either declarations as in a *.mcy file, and expressions. The Top-level automatically adds “;;” at the end of each line. >] 123+456 >-> Int: 579 (0x243) The purpose of this Top-level is not to write full programs. It's just an easy way of testing system functions, and therefore very useful for discovering the Minimacy language.