Skip to content

Commit 3f21d62

Browse files
authored
Merge pull request #1055 from live-codes/pullfrog/1054-add-cobol-language-support
feat(Compilers): add COBOL support
2 parents 4c7027e + cd5d6ce commit 3f21d62

101 files changed

Lines changed: 1113 additions & 377 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/livecodes/language-support/references/languages.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Enabled via `processors` config:
123123
| C++ (Wasm) | `cpp-wasm`, `clang`, `wasm.cpp` | Clang WASM |
124124
| Objective-C | `objc-wasm`, `objc`, `wasm.m` | Clang WASM |
125125
| Objective-C++ | `objcpp-wasm`, `objcpp`, `wasm.mm` | Clang WASM |
126+
| COBOL (Wasm) | `cobol-wasm`, `cobol`, `cob`, `cbl`, `cpy`, `gnucobol`, `wasm.cobol` | GnuCOBOL (COBOL -> WASM) |
126127
| Java | `java` | Java runtime |
127128
| C# | `csharp-wasm`, `cs`, `cs-wasm`, `wasm.cs` | C# WASM |
128129
| Blazor (Wasm) | `blazor-wasm`, `blazor`, `razor`, `razor-wasm`, `wasm.razor` | Razor components rendered by Blazor (WASM) |

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A [feature-rich](https://livecodes.io/docs/features/), open-source, **client-sid
1313
[![LiveCodes: npm version](https://img.shields.io/npm/v/livecodes)](https://www.npmjs.com/package/livecodes)
1414
[![LiveCodes: npm downloads](https://img.shields.io/npm/dm/livecodes)](https://www.npmjs.com/package/livecodes)
1515
[![LiveCodes: jsdelivr downloads](https://data.jsdelivr.com/v1/package/npm/livecodes/badge?style=rounded)](https://www.jsdelivr.com/package/npm/livecodes)
16-
[![LiveCodes: languages](https://img.shields.io/badge/languages-115-blue)](https://livecodes.io/docs/languages/)
16+
[![LiveCodes: languages](https://img.shields.io/badge/languages-116-blue)](https://livecodes.io/docs/languages/)
1717
[![LiveCodes: docs](https://img.shields.io/badge/Documentation-575757?logo=gitbook&logoColor=white)](https://livecodes.io/docs/)
1818
[![LiveCodes: llms.txt](https://img.shields.io/badge/llms.txt-575757?logo=googledocs&logoColor=white)](https://livecodes.io/docs/llms.txt)
1919
[![LiveCodes: llms-full.txt](https://img.shields.io/badge/llms--full.txt-575757?logo=googledocs&logoColor=white)](https://livecodes.io/docs/llms-full.txt)

‎docs/docs/languages/cobol-wasm.mdx‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# COBOL (Wasm)
2+
3+
COBOL is a compiled, imperative programming language designed for business data processing.
4+
5+
COBOL in LiveCodes is compiled to WebAssembly by the real [GnuCOBOL](https://gnucobol.sourceforge.io/)
6+
compiler and run in the browser, with no server. The toolchain translates COBOL to C, compiles that
7+
with Clang, links `libcob`, and runs the resulting WebAssembly module.
8+
9+
## Usage
10+
11+
Demo:
12+
13+
import LiveCodes from '../../src/components/LiveCodes.tsx';
14+
15+
export const cobolConfig = {
16+
activeEditor: 'script',
17+
script: {
18+
language: 'cobol-wasm',
19+
content: `IDENTIFICATION DIVISION.
20+
PROGRAM-ID. HELLO-WORLD.
21+
PROCEDURE DIVISION.
22+
DISPLAY "Hello, World!".
23+
STOP RUN.`,
24+
},
25+
mode: 'simple',
26+
editor: 'auto',
27+
tools: {
28+
status: 'full',
29+
},
30+
};
31+
32+
<LiveCodes config={cobolConfig}></LiveCodes>
33+
34+
### Communication with JavaScript
35+
36+
The program runs in the context of the result page. A few helpers are available in the browser global
37+
`livecodes.cobol` object:
38+
39+
- `livecodes.cobol.input`: the standard input passed to the program.
40+
- `livecodes.cobol.loaded`: a promise that resolves when the compiler has downloaded and the program
41+
has run, and rejects if the toolchain fails to load. Other helpers should be used after it resolves.
42+
- `livecodes.cobol.output`: the program's output (stdout and stderr combined).
43+
- `livecodes.cobol.error`: the compiler diagnostics, if the code failed to compile.
44+
- `livecodes.cobol.exitCode`: the exit code of the program.
45+
- `livecodes.cobol.run`: compiles and runs the code again with new input, returning a promise that
46+
resolves with `output`, `error` and `exitCode`.
47+
48+
Example:
49+
50+
<LiveCodes template="cobol-wasm" params={{ activeEditor: 'markup' }} height="80vh"></LiveCodes>
51+
52+
```cobol
53+
IDENTIFICATION DIVISION.
54+
PROGRAM-ID. HELLO-WORLD.
55+
PROCEDURE DIVISION.
56+
DISPLAY "Hello, World!".
57+
STOP RUN.
58+
```
59+
60+
`ACCEPT` reads from the **stdin** pane, in the same way as the other console languages:
61+
62+
```cobol
63+
IDENTIFICATION DIVISION.
64+
PROGRAM-ID. GREET.
65+
DATA DIVISION.
66+
WORKING-STORAGE SECTION.
67+
01 WS-NAME PIC X(20).
68+
PROCEDURE DIVISION.
69+
ACCEPT WS-NAME
70+
DISPLAY "Hello, " WS-NAME
71+
STOP RUN.
72+
```
73+
74+
## Language Info
75+
76+
### Name
77+
78+
`cobol-wasm`
79+
80+
### Aliases / Extensions
81+
82+
`cobol`, `cob`, `cbl`, `cpy`, `gnucobol`, `wasm.cobol`
83+
84+
### Editor
85+
86+
`script`
87+
88+
## Compiler
89+
90+
[GnuCOBOL](https://gnucobol.sourceforge.io/) 3.2 compiled to WebAssembly, with Clang and LLD for the
91+
generated C.
92+
93+
### Custom Settings
94+
95+
The GnuCOBOL compiler can be configured through the `customSettings` object, under the `cobol-wasm`
96+
key. The following options are supported:
97+
98+
- `sourceFormat`: the COBOL source format, `free` (the default) or `fixed`.
99+
- `compileArgs`: extra GnuCOBOL (`cobc`) flags.
100+
- `cCompileArgs`: extra Clang flags for the generated C.
101+
- `args`: the program's command-line arguments.
102+
- `fileName`: the name the source is compiled under (`main.cob` by default).
103+
104+
Example:
105+
106+
```js
107+
const config = {
108+
activeEditor: 'script',
109+
script: {
110+
language: 'cobol-wasm',
111+
content: '...',
112+
},
113+
customSettings: {
114+
'cobol-wasm': {
115+
sourceFormat: 'fixed',
116+
},
117+
},
118+
};
119+
```
120+
121+
## Code Formatting
122+
123+
Not currently supported.
124+
125+
## Live Reload
126+
127+
By default, new code changes are sent to the result page for re-evaluation without a full page reload. This behavior can be disabled by adding the code comment `*> __livecodes_reload__` to the COBOL code, which forces a full page reload.
128+
129+
This comment can be added in the [`hiddenContent` property of the editor](../configuration/configuration-object.mdx#markup) for embedded playgrounds.
130+
131+
## Example Usage
132+
133+
```cobol
134+
IDENTIFICATION DIVISION.
135+
PROGRAM-ID. INVOICE.
136+
DATA DIVISION.
137+
WORKING-STORAGE SECTION.
138+
01 WS-RATE PIC 9(3)V99 VALUE 25.50.
139+
01 WS-HOURS PIC 9(3) VALUE 40.
140+
01 WS-PAY PIC 9(5)V99.
141+
PROCEDURE DIVISION.
142+
COMPUTE WS-PAY = WS-RATE * WS-HOURS
143+
DISPLAY "Rate: " WS-RATE
144+
DISPLAY "Pay: " WS-PAY
145+
STOP RUN.
146+
```
147+
148+
## Starter Template
149+
150+
https://livecodes.io/?template=cobol-wasm
151+
152+
## Links
153+
154+
- [GnuCOBOL](https://gnucobol.sourceforge.io/)
155+
- [Learn X in Y minutes, where X=COBOL](https://learnxinyminutes.com/docs/cobol/)
156+
- [@live-codes/cobol-wasm](https://www.npmjs.com/package/@live-codes/cobol-wasm)

‎docs/src/components/LanguageSliders.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default function Sliders() {
9292
{ name: 'cpp-wasm', title: 'C++ (Wasm)' },
9393
{ name: 'objc-wasm', title: 'Objective-C (Wasm)' },
9494
{ name: 'objcpp-wasm', title: 'Objective-C++ (Wasm)' },
95+
{ name: 'cobol-wasm', title: 'COBOL (Wasm)' },
9596
{ name: 'fortran', title: 'Fortran' },
9697
{ name: 'rust-wasm', title: 'Rust (Wasm)' },
9798
{ name: 'swift-wasm', title: 'Swift (Wasm)' },

‎docs/src/components/TemplateList.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const templates = [
4848
{ name: 'php-wasm', title: 'PHP (Wasm) Starter', thumbnail: 'php.svg' },
4949
{ name: 'cpp', title: 'C++ Starter', thumbnail: 'cpp.svg' },
5050
{ name: 'c-wasm', title: 'C (Wasm) Starter', thumbnail: 'c.svg' },
51+
{ name: 'cobol-wasm', title: 'COBOL Starter', thumbnail: 'cobol.svg' },
5152
{ name: 'fortran-wasm', title: 'Fortran Starter', thumbnail: 'fortran.svg' },
5253
{ name: 'cpp-wasm', title: 'C++ (Wasm) Starter', thumbnail: 'cpp.svg' },
5354
{ name: 'objc-wasm', title: 'Objective-C (Wasm) Starter', thumbnail: 'objective-c.svg' },

‎functions/vendors/templates.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const starterTemplates = {
5050
"c-wasm": "C (Wasm) Starter",
5151
"cpp-wasm": "C++ (Wasm) Starter",
5252
"objc-wasm": "Objective-C (Wasm) Starter",
53+
"cobol-wasm": "COBOL Starter",
5354
"fortran-wasm": "Fortran Starter",
5455
"rust-wasm": "Rust (Wasm) Starter",
5556
"swift-wasm": "Swift (Wasm) Starter",

‎scripts/build.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ const iifeBuild = () =>
229229
'languages/cpp/lang-cpp-script.ts',
230230
'languages/clang-wasm/lang-clang-wasm-script.ts',
231231
'languages/fortran-wasm/lang-fortran-wasm-script.ts',
232+
'languages/cobol-wasm/lang-cobol-wasm-script.ts',
232233
'languages/go-wasm/lang-go-wasm-script.ts',
233234
'languages/csharp-wasm/lang-csharp-wasm-script.ts',
234235
'languages/fanak/lang-fanak-script.ts',

‎server/php/inc/starter-templates.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"c-wasm": "C (Wasm) Starter",
5151
"cpp-wasm": "C++ (Wasm) Starter",
5252
"objc-wasm": "Objective-C (Wasm) Starter",
53+
"cobol-wasm": "COBOL Starter",
5354
"fortran-wasm": "Fortran Starter",
5455
"rust-wasm": "Rust (Wasm) Starter",
5556
"swift-wasm": "Swift (Wasm) Starter",

‎src/livecodes/UI/command-menu-actions.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export const getCommandMenuActions = ({
306306
'c-wasm',
307307
'cpp-wasm',
308308
'objc-wasm',
309+
'cobol-wasm',
309310
'fortran-wasm',
310311
'rust-wasm',
311312
'swift-wasm',
Lines changed: 6 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)