makecode projects generally consist of three types of code:
- Blocks/Python
- TypeScript (we call it “JavaScript” but it’s actually TypeScript)
- C++/assembly
the compilation process looks like this:
┌──────────────────┐
│ Blocks/Python │
└────────┬─────────┘
▼
┌──────────────────┐ ┌───────────────────┐
│ TypeScript │ │ C++/assembly │
└────────┬─────────┘ └────────┬──────────┘
▼ ▼
┌──────────────────┐ ┌───────────────────┐
┌───────────┤ IR │ │ Cloud compiler │
│ └────────┬─────────┘ └────────┬──────────┘
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌───────────────────┐
│Simulator Emitter│ │ Native Emitter │ │ Binary Hexfile │
└────────┬────────┘ └────────┬─────────┘ └─────────┬─────────┘
▼ │ │
┌─────────────────┐ │ ┌────────────────┐ │
│ Simulator │ └──►│ Browser Linker │◄──┘
└─────────────────┘ └───────┬────────┘
▼
┌────────────┐
│Hex/UF2 File│
└────────────┘
basically, we first take the C++ and assembly code in a project and send it off to our cloud compilation service. this compiler produces a hexfile which is downloaded by the browser and stored in the browser’s localstorage so that makecode can work offline after it has been fetched at least once. we also download a lot of information about the hex file in this step which is used later by our linker.
next, when the user attempts to compile their blocks or python project, we first convert that code into typescript. then our browser compiler takes that typescript and compiles it down into an intermediate representation (IR). note that we do not use the standard typescript compiler to convert the typescript code into javascript first; it goes straight from typescript to the IR.
this IR is then sent to one of two emitters. if this compilation is being done to run the user code in the simulator in the browser, we send the IR to our javascript emitter which produces a string of javascript that can be run inside of the simulator iframe to simulate the program. this javascript is not human readable, it’s machine generated code that accurately mimics the behavior of our native code (e.g. it supports multithreading which javascript does not)
if this is a compilation for a binary file, the IR is instead sent to a native emitter which outputs machine code. this code is then linked with the binary hex file that was compiled by the cloud compiler to create the final hex/uf2 file that you download.
this entire process happens offline unless the project contains C++ code; in that case we have to ping the cloud compiler once to get the compiled binary for that source.
so, to answer your question, we do not convert typescript files into C++ files.