> For the complete documentation index, see [llms.txt](https://yutian-chen.gitbook.io/c0vm.ts-dev-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yutian-chen.gitbook.io/c0vm.ts-dev-documentation/backend/compile-api.md).

# Compile API

Technically, it is possible to implement a parser (which is already done in the syntax highlighting module of code editor!) and corresponding code generation module in TypeScript to transform C0 to BC0 on browser.

However, to control the scale of this project, we decided to use the `cc0` compiler with `-b` to do this instead. We've set up a server to provide a `Compile API` for the frontend browser to call on.

## Compile C0 code into BC0 byte code

<mark style="color:green;">`POST`</mark> `URL: ...(backend not deployed on public server yet)/compile`

Accept multiple C0 source code files and&#x20;

On `Success`: response with a compiled BC0 byte code file.

On `Failure`: response with empty BC0 byte code and return the standard output from `cc0` compiler.

#### Query Parameters

| Name                                         | Type    | Description                                          |
| -------------------------------------------- | ------- | ---------------------------------------------------- |
| dyn\_check<mark style="color:red;">\*</mark> | boolean | Apply Dynamic Contract Check (-d flag in CC0) or not |

#### Request Body

| Name                                        | Type      | Description                                                                         |
| ------------------------------------------- | --------- | ----------------------------------------------------------------------------------- |
| filenames<mark style="color:red;">\*</mark> | String\[] | List of file names                                                                  |
| codes<mark style="color:red;">\*</mark>     | String\[] | Content (source codes) in each file, must have same length and order as `filenames` |

{% tabs %}
{% tab title="200: OK Almost in any situation" %}

```javascript
{
    "bytecode": string,    // Empty when compile failed
    "error": string        // Empty when compile successed
}
```

{% endtab %}

{% tab title="500: Internal Server Error Something's wrong in server side" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}
