tapmach 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +60 -22
  2. package/dist/index.js +52 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,51 +1,89 @@
1
+ ![Banner](assets/logo.png)
2
+
1
3
  # tapmach
2
4
 
3
- **tapmach** tape-based programming language designed for visual execution and extreme simplicity. It focuses on manipulating a dynamic array of cells through a clean, terminal-inspired interface.
5
+ **tapmach**, a list-based programming language designed for visual execution and extreme simplicity. It focuses on manipulating a dynamic array of cells through a clean interface. It is also quite performant.
4
6
 
5
7
  >[!note]
6
- > All the claims of performance are restrained by the execution speed of javascript. So don't really think this can beat C or other high performance programming languages.
8
+ > All the claims of performance are restrained by the execution speed of javascript. So don't assume this can beat C or other high performance programming languages.
7
9
 
8
- ---
9
10
 
10
- ### 🚀 Getting Started
11
+ ## 🚀 Getting Started
11
12
 
12
13
  To run the Tapmach environment, ensure you have **Bun** installed, then execute:
13
14
 
14
15
  ```bash
15
- bun run index.ts
16
+ bun add -g tapmach
16
17
  ```
17
18
 
18
- The server will start at `http://localhost:3000`. Use the built-in editor to write your code and hit the **Run** button to see the tape come to life. To stop the server, press `q` in your terminal.
19
+ This will install tapmach on your system. To run the server just type `tapmach` on the command line.
20
+
21
+ The server will start at `http://localhost:3000`. Use the built-in editor to write your code and hit the **Run** button to see the your program come to life. To stop the server, press `q` in your terminal.
22
+
23
+ >[!note]
24
+ > I am quite sorry but `Ctrl+C` doesn't work if you want to exit the program.
19
25
 
20
- ---
21
26
 
22
- ### 📜 Language Reference
27
+ ## 📜 Language Reference
23
28
 
24
29
  Tapmach operates on a **Tape** (a sequence of cells). You interact with the "current" cell by creating, modifying, or destroying it.
25
30
 
31
+ The tape can be understood as the memory of the program in the form of a list. Also it is the only type of data-structure you can use in this programming language.
32
+
33
+ There are currently 3 instruction sets to suit different tastes.
34
+ You can switch to a different instruction set using the `Modes` dropdown menu.
35
+
36
+ Now lets understand the syntax of all the 3 instruction sets.
37
+
38
+ ### `Default` Instruction Set
39
+
40
+ It has the following instruction set -
41
+
42
+
43
+ | Instruction | Description |
44
+ | :--- | :--- |
45
+ | `create_cell` | Appends a new cell to the end of the tape/memory with an initial value of `0`. |
46
+ | `add <number>` | Adds the specified integer to the value of the currently active cell. |
47
+ | `destroy_cell`| Removes the current cell from the tape/memory. |
48
+ | `move <number>` | Moves through the tape/memory with the specified integer. |
49
+
50
+
51
+ Now one important thing to note here is that the `add` and `move` instructions can receive negative integers.
52
+
53
+
54
+ ### `Shortcodes` Instruction Set
55
+
56
+ The instruction set of this is similar to the `Default` Instruction Set and is just composed of shortcodes.
57
+
58
+
26
59
  | Instruction | Description |
27
60
  | :--- | :--- |
28
- | `create_cell` | Appends a new cell to the end of the tape with an initial value of `0`. |
61
+ | `cc` | Appends a new cell to the end of the tape/memory with an initial value of `0`. |
29
62
  | `add <number>` | Adds the specified integer to the value of the currently active cell. |
30
- | `destroy_cell`| Removes the current cell from the tape with a visual collapse animation. |
63
+ | `dc`| Removes the current cell from the tape/memory. |
64
+ | `mov <number>` | Moves through the tape/memory with the specified integer. |
65
+
66
+
67
+ ### `Numberless Shortcodes` Instruction Set
31
68
 
32
69
  >[!note]
33
- > Every line in Tapmach is treated as a distinct operation followed by a 1-second delay to allow the visual animations to complete.
70
+ > Actual meaning of numberless is countless, but sometimes it can refer to absence of numbers.
34
71
 
35
- ---
72
+ This instruction set has a little more keywords. Since there are no numbers.
36
73
 
37
- ### 🛠 Technical Architecture
38
74
 
39
- The project is built with a high-performance, "HTML-First" mindset:
75
+ | Instruction | Description |
76
+ | :--- | :--- |
77
+ | `cc` | Appends a new cell to the end of the tape/memory with an initial value of `0`. |
78
+ | `add` | Adds 1 to the value of the currently active cell. |
79
+ | `sub` | Subtracts 1 to the value of the currently active cell. |
80
+ | `dc` | Removes the current cell from the tape/memory. |
81
+ | `mov` | Moves forward in the tape/memory with a value of 1. |
82
+ | `vom` | Moves backward in the tape/memory with a value of a value of 1. |
40
83
 
41
- * **Runtime:** Powered by **Bun** for fast I/O and dev-server capabilities.
42
- * **Frontend:** Pure HTML/CSS/JS.
43
- * **Styling:** Features a minimalist UI.
44
- * **State:** Code is automatically persisted to `localStorage` using a debounced saving mechanism, ensuring you never lose your work.
45
84
 
46
- ---
85
+ ## 🎨 Design Goals
47
86
 
48
- ### 🎨 Design Goals
87
+ * **Minimalist UI:** No clutter, just the code and output.
88
+ * **Performance:** Lightweight execution with minimal dependencies.
49
89
 
50
- * **Minimalist UI:** No clutter, just the tape and the code.
51
- * **Performance:** Lightweight execution with minimal dependencies (`ansis` for terminal styling and `Bun.serve` for the backend).
package/dist/index.js CHANGED
@@ -391,11 +391,15 @@ var main_default = `<!DOCTYPE html>
391
391
  </head>
392
392
  <body>
393
393
  <div class="controls-header">
394
+ <div class="status">
395
+ -
396
+ </div>
394
397
  <div class="lang-control">
395
398
  <label for="lang">Mode:</label>
396
399
  <select id="lang">
397
400
  <option value="default">Default</option>
398
401
  <option value="shortcodes">Shortcodes</option>
402
+ <option value="numberless shortcodes">Numberless Shortcodes</option>
399
403
  </select>
400
404
  </div>
401
405
  <div class="speed-control">
@@ -485,6 +489,26 @@ var main_default = `<!DOCTYPE html>
485
489
  }
486
490
  }
487
491
 
492
+ function tokenToCode_Numberless_Shortcodes(code, currentToken, nextToken, speed) {
493
+ if (currentToken === 'cc') {
494
+ code.push('create_cell();');
495
+ } else if (currentToken === 'dc') {
496
+ code.push('destroy_cell();');
497
+ } else if (currentToken === 'add') {
498
+ code.push('add(1);')
499
+ } else if (currentToken === 'sub') {
500
+ code.push('add(-1);')
501
+ } else if (currentToken === 'mov') {
502
+ code.push('move(1);')
503
+ } else if (currentToken === 'vom') {
504
+ code.push('move(-1);')
505
+ } else if (currentToken === 'line_end') {
506
+ code.push(\`await sleep(\${speed});\`);
507
+ } else {
508
+ throw Error(\`Can't parse the code, wrong instruction: \${currentToken}\`);
509
+ }
510
+ }
511
+
488
512
  function convertToCode(text, lang = 'default') {
489
513
  let tokens = parse(text);
490
514
  const speed = document.getElementById('speed').value || 1000;
@@ -494,17 +518,22 @@ var main_default = `<!DOCTYPE html>
494
518
  tokenToCode = tokenToCode_Default;
495
519
  } else if (lang === 'shortcodes') {
496
520
  tokenToCode = tokenToCode_Shortcodes;
521
+ } else if (lang === 'numberless shortcodes') {
522
+ tokenToCode = tokenToCode_Numberless_Shortcodes;
497
523
  } else {
498
524
  tokenToCode = tokenToCode_Default;
499
525
  }
500
526
 
527
+ code.push(\`status.style.color = '#eed49f';status.innerHTML = ' ... ';\`);
528
+
501
529
  for (let i = 0; i < tokens.length; i++) {
502
530
  tokenToCode(code, tokens[i], tokens[i+1], speed);
503
531
  }
504
-
532
+
533
+ code.push(\`status.innerHTML = ' :) ';status.style.color = '#a6da95';setTimeout(() => { status.style.color = '#cad3f5'; status.innerHTML = ' - '; }, 2000);\`);
505
534
  code.push('})();')
506
535
  code = code.join('');
507
-
536
+
508
537
  return code;
509
538
  }
510
539
  </script>
@@ -556,7 +585,7 @@ var main_default = `<!DOCTYPE html>
556
585
  let current_cell = 0;
557
586
  let list = [];
558
587
 
559
- async function update() {
588
+ function update() {
560
589
  if (cells.length === 0) return;
561
590
 
562
591
  const target = cells[current_cell];
@@ -569,7 +598,7 @@ var main_default = `<!DOCTYPE html>
569
598
  target.classList.add('animate-update')
570
599
  }
571
600
 
572
- async function create_cell() {
601
+ function create_cell() {
573
602
  const val = 0;
574
603
  const div = document.createElement('div');
575
604
  div.classList.add('cell', 'animate-create', \`i\${list.length+1}\`);
@@ -592,17 +621,30 @@ var main_default = `<!DOCTYPE html>
592
621
  update();
593
622
  }
594
623
 
595
- async function destroy_cell() {
624
+ function destroy_cell() {
596
625
  const target = cells[current_cell];
597
626
  if (typeof target === null) return;
598
627
 
599
628
  target.classList.add('animate-destroy');
600
629
 
601
- setTimeout(() => target.remove(), 300);
602
- move(-1);
630
+ setTimeout(() => {
631
+ target.remove();
632
+ }, 300);
633
+ if (current_cell === 0) {
634
+ move(1);
635
+ list.splice(current_cell-1, 1);
636
+ cells.splice(current_cell-1, 1);
637
+ current_cell = 0;
638
+ } else {
639
+ move(-1);
640
+ list.splice(current_cell+1, 1);
641
+ cells.splice(current_cell+1, 1);
642
+ }
643
+
644
+ console.log(current_cell);
603
645
  }
604
646
 
605
- async function move(index) {
647
+ function move(index) {
606
648
  if (current_cell+index < 0 || current_cell+index >= cells.length) return;
607
649
 
608
650
  previous_cell = current_cell;
@@ -631,9 +673,11 @@ var main_default = `<!DOCTYPE html>
631
673
 
632
674
  <script>
633
675
  const button = document.querySelector('.run-btn');
676
+ const status = document.querySelector('.status');
634
677
  button.addEventListener('click', async (e) => {
635
678
  let text = localStorage.getItem('text-content');
636
679
  let selectedLang = localStorage.getItem('selectedLang');
680
+
637
681
  eval(convertToCode(text, selectedLang));
638
682
  })
639
683
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tapmach",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "module": "./src/index.ts",
5
5
  "type": "module",
6
6
  "private": false,