@nirguna/plugin-fasm 1.2.0 → 1.4.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.
@@ -1,6 +1,10 @@
1
1
  import {types} from 'putout';
2
2
 
3
- const {isMemberExpression} = types;
3
+ const {
4
+ isMemberExpression,
5
+ isAwaitExpression,
6
+ } = types;
7
+
4
8
  const PREFIX = '__nirguna_';
5
9
 
6
10
  export const report = ({name, newName}) => `Add prefix to label: '${name}' -> '${newName}'`;
@@ -45,8 +49,9 @@ function getIds(path, name) {
45
49
  return;
46
50
 
47
51
  const calleePath = path.parentPath.get('callee');
52
+ const parentAwait = isAwaitExpression(path.parentPath.parentPath);
48
53
 
49
- if (calleePath === path)
54
+ if (!parentAwait && calleePath === path)
50
55
  return;
51
56
 
52
57
  ids.push(path);
@@ -2,19 +2,7 @@ import {types} from 'putout';
2
2
 
3
3
  const {isArrayExpression} = types;
4
4
 
5
- function getType(arg) {
6
- return arg.__nirguna_type || 'i16';
7
- }
8
-
9
- export const report = (path) => {
10
- const arg1 = path.get('left.0');
11
- const arg2 = path.get('right.0');
12
- const type1 = getType(arg1);
13
- const type2 = getType(arg2);
14
-
15
- if (type1 !== type2)
16
- return `Types mismatch: '${arg1}:${type1} = ${arg2}:${type2}'`;
17
-
5
+ export const report = () => {
18
6
  return `Use registers to address memory`;
19
7
  };
20
8
 
@@ -25,16 +13,8 @@ export const match = () => ({
25
13
  });
26
14
 
27
15
  export const replace = () => ({
28
- '[__a] = [__b]': (vars, path) => {
29
- const arg1 = path.get('left.0');
30
- const arg2 = path.get('right.0');
31
- const type1 = getType(arg1);
32
- const type2 = getType(arg2);
33
-
34
- if (type1 !== type2)
35
- return path;
36
-
37
- const reg = type1 === 'i8' ? 'al' : 'ax';
16
+ '[__a] = [__b]': () => {
17
+ const reg = 'ax';
38
18
 
39
19
  return `{
40
20
  mov(${reg}, [__b]);
@@ -3,6 +3,7 @@ import {
3
3
  types,
4
4
  operator,
5
5
  } from 'putout';
6
+ import {TARGETS} from '#targets';
6
7
 
7
8
  const {
8
9
  replaceWithMultiple,
@@ -80,21 +81,6 @@ export const replace = () => ({
80
81
  },
81
82
  });
82
83
 
83
- const TARGET = {
84
- linux: {
85
- size: 8,
86
- bits: 'i64',
87
- },
88
- kernel: {
89
- size: 2,
90
- bits: 'i16',
91
- },
92
- boot: {
93
- size: 2,
94
- bits: 'i16',
95
- },
96
- };
97
-
98
84
  const REG = {
99
85
  i16: {
100
86
  eax: 'ax',
@@ -130,7 +116,7 @@ function getBytes(path) {
130
116
  const target = getTarget(path);
131
117
 
132
118
  if (target)
133
- return TARGET[target].size;
119
+ return TARGETS[target].size;
134
120
 
135
121
  const {returnType} = path.node;
136
122
 
@@ -146,7 +132,7 @@ function getRegister(path, reg) {
146
132
  const target = getTarget(path);
147
133
 
148
134
  if (target) {
149
- const {bits} = TARGET[target];
135
+ const {bits} = TARGETS[target];
150
136
 
151
137
  return REG[bits][reg];
152
138
  }
@@ -1,19 +1,5 @@
1
1
  import {template} from 'putout';
2
-
3
- const createBinary = (address) => `{
4
- org(${address});
5
- use16();
6
- }`;
7
-
8
- const TARGET = {
9
- boot: createBinary('0x7c00'),
10
- kernel: createBinary('0x7e00'),
11
- nemesis: createBinary('0x500'),
12
- linux: `{
13
- format.ELF64.executable;
14
- entry.$;
15
- }`,
16
- };
2
+ import {TARGETS} from '#targets';
17
3
 
18
4
  export const report = (path, {options}) => {
19
5
  const {target} = options;
@@ -24,7 +10,9 @@ export const fix = (path, {options}) => {
24
10
  const {target} = options;
25
11
 
26
12
  path.node.extra.target = target;
27
- path.node.body.unshift(template.ast(TARGET[target]));
13
+ const {code} = TARGETS[target];
14
+
15
+ path.node.body.unshift(template.ast(code));
28
16
  };
29
17
 
30
18
  export const include = () => ['Program'];
@@ -38,5 +26,5 @@ export const filter = (path, {options}) => {
38
26
  if (path.node.extra.target)
39
27
  return;
40
28
 
41
- return TARGET[target];
29
+ return TARGETS[target];
42
30
  };
package/lib/targets.js ADDED
@@ -0,0 +1,30 @@
1
+ const createBinary = (address) => `{
2
+ org(${address});
3
+ use16();
4
+ }`;
5
+
6
+ export const TARGETS = {
7
+ linux: {
8
+ size: 8,
9
+ bits: 'i64',
10
+ code: `{
11
+ format.ELF64.executable;
12
+ entry.$;
13
+ }`,
14
+ },
15
+ kernel: {
16
+ size: 2,
17
+ bits: 'i16',
18
+ code: createBinary('0x7e00'),
19
+ },
20
+ boot: {
21
+ size: 2,
22
+ bits: 'i16',
23
+ code: createBinary('0x7c00'),
24
+ },
25
+ nemesis: {
26
+ size: 2,
27
+ bits: 'i16',
28
+ code: createBinary('0x500'),
29
+ },
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nirguna/plugin-fasm",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊nirguna plugin adds ability to optimize fasm",
@@ -13,6 +13,9 @@
13
13
  "type": "git",
14
14
  "url": "git+https://github.com/coderaiser/putout.git"
15
15
  },
16
+ "imports": {
17
+ "#targets": "./lib/targets.js"
18
+ },
16
19
  "scripts": {
17
20
  "test": "madrun test",
18
21
  "watch:test": "madrun watch:test",
@@ -35,7 +38,7 @@
35
38
  "devDependencies": {
36
39
  "@putout/plugin-remove-nested-blocks": "^9.1.0",
37
40
  "@putout/test": "^15.1.1",
38
- "c8": "^10.0.0",
41
+ "c8": "^11.0.0",
39
42
  "eslint": "^10.0.1",
40
43
  "eslint-plugin-n": "^17.0.0",
41
44
  "eslint-plugin-putout": "^31.0.1",