@nirguna/plugin-nemesis 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ ## putout-plugin-nemesis
2
+
3
+ Transforms:
4
+
5
+ - ✅[`convert-get-char-to-int-0xff`](https://putout.cloudcmd.io/#/gist/42fe266583e24b282f0d96e6c9756ac1/8fed2362fa547c025a3cd93b95542747dcebccf3);
6
+ - ✅[`convert-printf-to-int-0xff`](https://putout.cloudcmd.io/#/gist/1d20463027c9f8ef0926d0031a602b5c/c347707d4b5bc41bc764705b36679e55203d7204);
7
+ - ✅[`remove-useless-imports`](https://putout.cloudcmd.io/#/gist/7d513c2f0b80435db5c6191ebd535efe/8c7c6075eb0a9878d223637b0fd86c7d50ea535a);
8
+ - ✅[`convert-set-cursor-to-int-0xff`](https://putout.cloudcmd.io/#/gist/e35f9d22c2e219227e2b06caf9be08d4/81cbdb1367607e9dda83594958ac0d6b346e67eb);
9
+ - ✅[`convert-read-sector-to-int-0xff`](https://putout.cloudcmd.io/#/gist/6ae8820756ba1af043f93f3bdb49360e/0be46185f32f36c3f5126a1af753c3f741388cd0);
10
+ - ✅[`convert-find-file-to-int-0xff`](https://putout.cloudcmd.io/#/gist/2418e874e298b187a04d245a8351f66f/2d2e4b1f8caa652aab613162bd81f0b6e460a1fa);
11
+ - ✅[`convert-set-screen-size-to-0xff`](https://putout.cloudcmd.io/#/gist/38fafd9ef79f96fccbf78966ad912508/a75089d6a7fcd3c96efe36dc1890a54b02ad40e0);
12
+ - ✅[`convert-read-first-to-0xff`](https://putout.cloudcmd.io/#/gist/473ebf06c3a5b17523adca09ca3240a9/dc4e3d59a06be51985d0b002f8199e0f3618274e);
13
+ - ✅[`convert-set-color-to-int-0xff`](https://putout.cloudcmd.io/#/gist/a2dfbe8d6cf1f79328c572d5f10b201c/7b0f12fb1e4a61bac0914e3697eff75678bcb707);
14
+ - ✅[`convert-gets-to-0xff`](https://putout.cloudcmd.io/#/gist/ac0146b899433d90ba83214a20865db0/4fce39e0d68031b05a65a68aa817c29d46560f4f);
15
+ - ✅[`convert-debug-to-printf`](https://putout.cloudcmd.io/#/gist/2bc7d9ead127236ae4593c8abe150538/5993e8fe1355acbab1778f1cf70b2311c21913b1);
16
+ - ✅[`convert-clear-screen-to-int-0xff`](https://putout.cloudcmd.io/#/gist/693fcd438d105d74a243636662d79011/a722a5729204527189e5dc1b2a867e053cf2e0f5);
17
+ - ✅[`remove-useless-declarations`](https://putout.cloudcmd.io/#/gist/9045b99fbb58a53047dec060d3f143cf/646d41281b8010f6b4429b81cc4ba6987c12a041);
package/lib/api.js ADDED
@@ -0,0 +1,31 @@
1
+ import {operator, types} from 'putout';
2
+
3
+ const {isArrayExpression} = types;
4
+ const {extract} = operator;
5
+
6
+ export const GET_CHAR = 1;
7
+ export const PRINTF = 2;
8
+ export const FIND_FILE = 3;
9
+ export const FIND_FIRST = 5;
10
+ export const SET_COLOR = 6;
11
+ export const SET_CURSOR = 7;
12
+ export const GETS = 8;
13
+ export const SET_MIN_MAX_COL_LINE = 0xb;
14
+ export const READ_SECTOR = 0xc;
15
+
16
+ export function parseArgs({properties}) {
17
+ const result = {};
18
+
19
+ for (const {key, value} of properties) {
20
+ const extracted = extract(value);
21
+
22
+ if (isArrayExpression(value)) {
23
+ result[key.name] = `[${extracted}]`;
24
+ continue;
25
+ }
26
+
27
+ result[key.name] = extracted;
28
+ }
29
+
30
+ return result;
31
+ }
@@ -0,0 +1,12 @@
1
+ export const report = () => `Use '0xff' instead of 'nemesis.clearScreen()'`;
2
+
3
+ const CLEAR_SCREEN = 9;
4
+
5
+ export const replace = () => ({
6
+ 'nemesis.clearScreen()': () => {
7
+ return `{
8
+ al = ${CLEAR_SCREEN};
9
+ int(0xff);
10
+ }`;
11
+ },
12
+ });
@@ -0,0 +1,29 @@
1
+ import {types} from 'putout';
2
+
3
+ const {isIdentifier} = types;
4
+
5
+ export const report = () => `Use 'nemesis.printf()' instead of 'debug()'`;
6
+
7
+ export const match = () => ({
8
+ 'debug(__a)': ({__a}) => isIdentifier(__a),
9
+ });
10
+
11
+ export const replace = ({options}) => {
12
+ const {
13
+ color = 4,
14
+ background = 0,
15
+ } = options;
16
+
17
+ return {
18
+ 'debug(__a)': `{
19
+ pusha();
20
+ nemesis.setColor({
21
+ color: ${color},
22
+ background: ${background},
23
+ });
24
+ nemesis.printf(__a);
25
+ nemesis.setColor();
26
+ popa();
27
+ }`,
28
+ };
29
+ };
@@ -0,0 +1,9 @@
1
+ export const report = () => `Use 'int(0xff)' instead of 'nemesis.exec()'`;
2
+
3
+ export const replace = () => ({
4
+ 'nemesis.exec(__a)': `{
5
+ al = 4;
6
+ bx = __a;
7
+ int(0xff);
8
+ }`,
9
+ });
@@ -0,0 +1,12 @@
1
+ import {FIND_FILE} from '../api.js';
2
+
3
+ export const report = () => `Use 'int(0xff)' instead of 'nemesis.findFile()'`;
4
+
5
+ export const replace = () => ({
6
+ '__a = nemesis.findFile(__b)': `{
7
+ al = ${FIND_FILE};
8
+ bx = __b;
9
+ int(0xff);
10
+ __a = ax;
11
+ }`,
12
+ });
@@ -0,0 +1,27 @@
1
+ import {FIND_FIRST} from '../api.js';
2
+
3
+ export const report = () => `Use '0xff' instead of 'nemesis.readSector()'`;
4
+
5
+ export const match = () => ({
6
+ 'nemesis.findFirst(__a)': (vars, path) => {
7
+ return path.parentPath.isExpressionStatement();
8
+ },
9
+ });
10
+
11
+ export const replace = () => ({
12
+ '__a = nemesis.findFirst(__b)': `{
13
+ al = ${FIND_FIRST};
14
+ bx = __b;
15
+ int(0xff);
16
+ __a = ax;
17
+ }`,
18
+ 'nemesis.findFirst(__a)': `{
19
+ al = ${FIND_FIRST};
20
+ bx = __a;
21
+ int(0xff);
22
+ }`,
23
+ 'nemesis.findFirst()': `{
24
+ al = ${FIND_FIRST};
25
+ int(0xff);
26
+ }`,
27
+ });
@@ -0,0 +1,10 @@
1
+ import {GET_CHAR} from '../api.js';
2
+
3
+ export const report = () => `Use 'int(0xff)' instead of 'nemesis.getChar()'`;
4
+
5
+ export const replace = () => ({
6
+ 'nemesis.getChar()': `{
7
+ al = ${GET_CHAR}
8
+ int(0xff);
9
+ }`,
10
+ });
@@ -0,0 +1,16 @@
1
+ import {GETS, parseArgs} from '../api.js';
2
+
3
+ export const report = () => `Use '0xff' instead of 'nemesis.gets()'`;
4
+
5
+ export const replace = () => ({
6
+ 'nemesis.gets(__a)': ({__a}) => {
7
+ const {buffer, size} = parseArgs(__a);
8
+
9
+ return `{
10
+ bx = ${buffer};
11
+ cx = ${size};
12
+ al = ${GETS};
13
+ int(0xff);
14
+ }`;
15
+ },
16
+ });
@@ -0,0 +1,11 @@
1
+ export const report = () => `Use 'int(0xff)' instead of 'nemesis.printf()'`;
2
+
3
+ import {PRINTF} from '../api.js';
4
+
5
+ export const replace = () => ({
6
+ 'nemesis.printf(__a)': `{
7
+ al = ${PRINTF}
8
+ bx = __a;
9
+ int(0xff);
10
+ }`,
11
+ });
@@ -0,0 +1,91 @@
1
+ import {types, operator} from 'putout';
2
+ import {is8bit} from '@nirguna/operator-fasm/regs';
3
+ import {READ_SECTOR} from '../api.js';
4
+
5
+ export const report = () => `Use '0xff' instead of 'nemesis.readSector()'`;
6
+
7
+ const {isArrayExpression} = types;
8
+ const {extract} = operator;
9
+
10
+ export const match = () => ({
11
+ 'nemesis.readSector()': (vars, path) => {
12
+ return path.parentPath.isExpressionStatement();
13
+ },
14
+ });
15
+
16
+ export const replace = () => ({
17
+ '__a = nemesis.readSector(__object)': ({__object, __a}, path) => {
18
+ const {line} = path.node.loc.start;
19
+ const reg = parseReg(__a.name);
20
+ const {
21
+ count = 1,
22
+ buffer = 0,
23
+ sector = 0,
24
+ track = 0,
25
+ disk = 0,
26
+ head = 0,
27
+ } = parseArgs(__object.properties);
28
+
29
+ return `{
30
+ ah = ${count};
31
+ bx = ${buffer};
32
+ cl = ${sector};
33
+ ch = ${track};
34
+ dl = ${disk};
35
+ dh = ${head};
36
+ ${createReadSector(line)}
37
+ mov(__a, ${reg});
38
+ }`;
39
+ },
40
+ '__a = nemesis.readSector()': ({__a}, path) => {
41
+ const {line} = path.node.loc.start;
42
+ const reg = parseReg(__a.name);
43
+
44
+ return `{
45
+ ${createReadSector(line)}
46
+ mov(__a, ${reg});
47
+ }`;
48
+ },
49
+ 'nemesis.readSector()': (vars, path) => {
50
+ const {line} = path.node.loc.start;
51
+ return createReadSector(line);
52
+ },
53
+ });
54
+
55
+ function createReadSector(line) {
56
+ return `{
57
+ al = ${READ_SECTOR};
58
+ int(0x0ff);
59
+ jnc(__nirguna_read_sector_ok_${line});
60
+ al = 1;
61
+ jmp(__nirguna_read_sector_end_${line});
62
+ __nirguna_read_sector_ok_${line}:
63
+ ax = 0
64
+ __nirguna_read_sector_end_${line}:
65
+ clc();
66
+ }`;
67
+ }
68
+
69
+ function parseReg(name) {
70
+ if (is8bit(name))
71
+ return 'al';
72
+
73
+ return 'ax';
74
+ }
75
+
76
+ function parseArgs(properties) {
77
+ const result = {};
78
+
79
+ for (const {key, value} of properties) {
80
+ const extracted = extract(value);
81
+
82
+ if (isArrayExpression(value)) {
83
+ result[key.name] = `[${extracted}]`;
84
+ continue;
85
+ }
86
+
87
+ result[key.name] = extracted;
88
+ }
89
+
90
+ return result;
91
+ }
@@ -0,0 +1,49 @@
1
+ import {parseArgs, SET_COLOR} from '../api.js';
2
+
3
+ const GREEN = 2;
4
+ const BLACK = 0;
5
+ const RED = 12;
6
+ const WHITE = 15;
7
+ const YELLOW = 14;
8
+
9
+ const prepareColor = (color) => {
10
+ if (color === 'red')
11
+ return RED;
12
+
13
+ if (color === 'white')
14
+ return WHITE;
15
+
16
+ if (color === 'yellow')
17
+ return YELLOW;
18
+
19
+ return color;
20
+ };
21
+
22
+ export const report = () => `Use '0xff' instead of 'nemesis.setColor()'`;
23
+
24
+ export const replace = () => ({
25
+ 'nemesis.setColor()': () => {
26
+ return `{
27
+ cl = ${GREEN}
28
+ ch = ${BLACK};
29
+ al = 6;
30
+ int(0xff);
31
+ }`;
32
+ },
33
+ 'nemesis.setColor(__object)': ({__object}) => {
34
+ const {
35
+ color = GREEN,
36
+ background = BLACK,
37
+ } = parseArgs(__object);
38
+
39
+ const preparedColor = prepareColor(color);
40
+ const preparedBackground = prepareColor(background);
41
+
42
+ return `{
43
+ cl = ${preparedColor}
44
+ ch = ${preparedBackground};
45
+ al = ${SET_COLOR};
46
+ int(0xff);
47
+ }`;
48
+ },
49
+ });
@@ -0,0 +1,16 @@
1
+ import {parseArgs, SET_CURSOR} from '../api.js';
2
+
3
+ export const report = () => `Use '0xff' instead of 'nemesis.setCursor'`;
4
+
5
+ export const replace = () => ({
6
+ 'nemesis.setCursor(__object)': ({__object}) => {
7
+ const {column, line} = parseArgs(__object);
8
+
9
+ return `{
10
+ bl = ${column};
11
+ bh = ${line};
12
+ al = ${SET_CURSOR};
13
+ int(0xff);
14
+ }`;
15
+ },
16
+ });
@@ -0,0 +1,25 @@
1
+ import {
2
+ parseArgs,
3
+ SET_MIN_MAX_COL_LINE,
4
+ } from '../api.js';
5
+
6
+ const {parse} = JSON;
7
+
8
+ export const report = () => `Use '0xff' instead of 'nemesis.setScreenSize()'`;
9
+
10
+ export const replace = () => ({
11
+ 'nemesis.setScreenSize(__a)': ({__a}) => {
12
+ const {columns, lines} = parseArgs(__a);
13
+ const [minColumn, maxColumn] = parse(columns);
14
+ const [minLine, maxLine] = parse(lines);
15
+
16
+ return `{
17
+ cl = ${maxColumn};
18
+ ch = ${maxLine};
19
+ bl = ${minColumn};
20
+ bh = ${minLine};
21
+ al = ${SET_MIN_MAX_COL_LINE};
22
+ int(0xff);
23
+ }`;
24
+ },
25
+ });
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import * as convertGetCharToInt0xff from './convert-get-char-to-int-0xff/index.js';
2
+ import * as removeUselessDeclarations from './remove-useless-declarations/index.js';
3
+ import * as convertFindFirstToInt0xff from './convert-find-first-to-int-0xff/index.js';
4
+ import * as convertClearScreenToInt0xff from './convert-clear-screen-to-int-0xff/index.js';
5
+ import * as convertGetsTo0xff from './convert-gets-to-0xff/index.js';
6
+ import * as convertSetScreenSizeTo0xff from './convert-set-screen-size-to-0xff/index.js';
7
+ import * as convertSetColorTo0xff from './convert-set-color-to-0xff/index.js';
8
+ import * as convertDebugToPrintf from './convert-debug-to-printf/index.js';
9
+ import * as convertFindFileToInt0xff from './convert-find-file-to-int-0xff/index.js';
10
+ import * as convertReadSectorToInt0xff from './convert-read-sector-to-int-0xff/index.js';
11
+ import * as convertExecToInt0xff from './convert-exec-to-int-0xff/index.js';
12
+ import * as convertSetCursorToInt0xff from './convert-set-cursor-to-int-0xff/index.js';
13
+ import * as removeUselessImports from './remove-useless-imports/index.js';
14
+ import * as convertPrintfToInt0xff from './convert-printf-to-int-0xff/index.js';
15
+
16
+ export const rules = {
17
+ 'convert-printf-to-int-0xff': convertPrintfToInt0xff,
18
+ 'remove-useless-imports': removeUselessImports,
19
+ 'convert-set-cursor-to-int-0xff': convertSetCursorToInt0xff,
20
+ 'convert-exec-to-int-0xff': convertExecToInt0xff,
21
+ 'convert-read-sector-to-int-0xff': convertReadSectorToInt0xff,
22
+ 'convert-find-file-to-int-0xff': convertFindFileToInt0xff,
23
+ 'convert-debug-to-printf': convertDebugToPrintf,
24
+ 'convert-set-color-to-0xff': convertSetColorTo0xff,
25
+ 'convert-set-screen-size-to-0xff': convertSetScreenSizeTo0xff,
26
+ 'convert-gets-to-0xff': convertGetsTo0xff,
27
+ 'convert-clear-screen-to-int-0xff': convertClearScreenToInt0xff,
28
+ 'convert-find-first-to-int-0xff': convertFindFirstToInt0xff,
29
+ 'remove-useless-declarations': removeUselessDeclarations,
30
+ 'convert-get-char-to-int-0xff': convertGetCharToInt0xff,
31
+ };
@@ -0,0 +1,5 @@
1
+ export const report = () => `Avoid useless import of '@nirguna/operator-nemesis'`;
2
+
3
+ export const replace = () => ({
4
+ 'import __imports from "@nirguna/operator-nemesis"': '',
5
+ });
@@ -0,0 +1,5 @@
1
+ export const report = () => `Avoid imports`;
2
+
3
+ export const replace = () => ({
4
+ 'import __imports from "@nirguna/operator-nemesis"': '',
5
+ });
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@nirguna/plugin-nemesis",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
+ "description": "Nirguna plugin adds ability to transform Nemesis",
7
+ "homepage": "https://github.com/putoutjs/nirguna/tree/master/packages/plugin-nemesis#readme",
8
+ "main": "lib/index.js",
9
+ "release": false,
10
+ "tag": false,
11
+ "changelog": false,
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/coderaiser/putout.git"
15
+ },
16
+ "scripts": {
17
+ "test": "madrun test",
18
+ "watch:test": "madrun watch:test",
19
+ "lint": "madrun lint",
20
+ "fresh:lint": "madrun fresh:lint",
21
+ "lint:fresh": "madrun lint:fresh",
22
+ "fix:lint": "madrun fix:lint",
23
+ "coverage": "madrun coverage",
24
+ "report": "madrun report"
25
+ },
26
+ "dependencies": {
27
+ "@nirguna/operator-fasm": "^1.0.0"
28
+ },
29
+ "keywords": [
30
+ "putout",
31
+ "putout-plugin",
32
+ "plugin",
33
+ "madrun"
34
+ ],
35
+ "devDependencies": {
36
+ "@putout/test": "^15.1.1",
37
+ "c8": "^10.0.0",
38
+ "eslint": "^10.0.0",
39
+ "eslint-plugin-n": "^17.0.0",
40
+ "eslint-plugin-putout": "^30.0.2",
41
+ "madrun": "^12.1.3",
42
+ "nodemon": "^3.0.1"
43
+ },
44
+ "peerDependencies": {
45
+ "putout": ">=41"
46
+ },
47
+ "license": "MIT",
48
+ "engines": {
49
+ "node": ">=22"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }