nadesiko3 3.3.76 → 3.3.77

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/core/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nadesiko3core",
3
- "version": "3.3.76",
3
+ "version": "3.3.77",
4
4
  "description": "Japanese Programming Language Nadesiko v3 core",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
@@ -36,8 +36,8 @@
36
36
  "sample"
37
37
  ],
38
38
  "devDependencies": {
39
- "@types/mocha": "^9.1.1",
40
- "@types/node": "^17.0.35",
39
+ "@types/mocha": "^10.0.0",
40
+ "@types/node": "^18.11.7",
41
41
  "chai": "^4.3.6",
42
42
  "eslint": "^8.23.1",
43
43
  "eslint-plugin-import": "^2.26.0",
@@ -159,7 +159,6 @@ export class NakoCompiler {
159
159
  _loadDependencies(code, filename, preCode, tools) {
160
160
  const dependencies = {};
161
161
  const compiler = new NakoCompiler({ useBasicPlugin: true });
162
- const defaultNamespace = NakoLexer.filenameToModName(this.filename);
163
162
  /**
164
163
  * @param {any} item
165
164
  * @param {any} tasks
@@ -182,8 +181,7 @@ export class NakoCompiler {
182
181
  // preDefineFuncはトークン列に変更を加えるため、事前にクローンしておく。
183
182
  // 「プラグイン名設定」を行う (#956)
184
183
  const modName = NakoLexer.filenameToModName(item.filePath);
185
- code = `『${modName}』にプラグイン名設定;『${modName}』に名前空間設定;` + code +
186
- `『メイン』にプラグイン名設定;『${defaultNamespace}』に名前空間設定。`;
184
+ code = `『${modName}』に名前空間設定;『${modName}』にプラグイン名設定;` + code + ';名前空間ポップ;';
187
185
  const tokens = this.rawtokenize(code, 0, item.filePath);
188
186
  dependencies[item.filePath].tokens = tokens;
189
187
  const funclist = {};
@@ -685,7 +683,7 @@ export class NakoCompiler {
685
683
  options = newCompilerOptions(options);
686
684
  const out = this.compileFromCode(code, filename, options);
687
685
  // 実行前に環境を生成
688
- const nakoGlobal = this.getNakoGlobal(options, out.gen);
686
+ const nakoGlobal = this.getNakoGlobal(options, out.gen, filename);
689
687
  // 実行
690
688
  this.evalJS(out.runtimeEnv, nakoGlobal);
691
689
  return nakoGlobal;
@@ -702,12 +700,12 @@ export class NakoCompiler {
702
700
  options = newCompilerOptions(options);
703
701
  const out = this.compileFromCode(code, filename, options);
704
702
  // 実行前に環境を生成
705
- const nakoGlobal = this.getNakoGlobal(options, out.gen);
703
+ const nakoGlobal = this.getNakoGlobal(options, out.gen, filename);
706
704
  // 実行
707
705
  this.evalJS(out.runtimeEnv, nakoGlobal);
708
706
  return nakoGlobal;
709
707
  }
710
- getNakoGlobal(options, gen) {
708
+ getNakoGlobal(options, gen, filename) {
711
709
  // オプションを参照
712
710
  let g = options.nakoGlobal;
713
711
  if (!g) {
@@ -718,6 +716,8 @@ export class NakoCompiler {
718
716
  else {
719
717
  g = new NakoGlobal(this, gen, (this.__globals.length + 1));
720
718
  }
719
+ // 名前空間を設定
720
+ g.__varslist[0]['名前空間'] = NakoLexer.filenameToModName(filename);
721
721
  }
722
722
  if (this.__globals.indexOf(g) < 0) {
723
723
  this.__globals.push(g);
@@ -239,7 +239,6 @@ export class NakoCompiler {
239
239
  _loadDependencies (code: string, filename: string, preCode: string, tools: LoaderTool) {
240
240
  const dependencies: Dependencies = {}
241
241
  const compiler = new NakoCompiler({ useBasicPlugin: true })
242
- const defaultNamespace: string = NakoLexer.filenameToModName(this.filename)
243
242
  /**
244
243
  * @param {any} item
245
244
  * @param {any} tasks
@@ -262,8 +261,7 @@ export class NakoCompiler {
262
261
  // preDefineFuncはトークン列に変更を加えるため、事前にクローンしておく。
263
262
  // 「プラグイン名設定」を行う (#956)
264
263
  const modName = NakoLexer.filenameToModName(item.filePath)
265
- code = `『${modName}』にプラグイン名設定;『${modName}』に名前空間設定;` + code +
266
- `『メイン』にプラグイン名設定;『${defaultNamespace}』に名前空間設定。`
264
+ code = `『${modName}』に名前空間設定;『${modName}』にプラグイン名設定;` + code + ';名前空間ポップ;'
267
265
  const tokens = this.rawtokenize(code, 0, item.filePath)
268
266
  dependencies[item.filePath].tokens = tokens
269
267
  const funclist = {}
@@ -794,7 +792,7 @@ export class NakoCompiler {
794
792
  options = newCompilerOptions(options)
795
793
  const out = this.compileFromCode(code, filename, options)
796
794
  // 実行前に環境を生成
797
- const nakoGlobal = this.getNakoGlobal(options, out.gen)
795
+ const nakoGlobal = this.getNakoGlobal(options, out.gen, filename)
798
796
  // 実行
799
797
  this.evalJS(out.runtimeEnv, nakoGlobal)
800
798
  return nakoGlobal
@@ -812,13 +810,13 @@ export class NakoCompiler {
812
810
  options = newCompilerOptions(options)
813
811
  const out = this.compileFromCode(code, filename, options)
814
812
  // 実行前に環境を生成
815
- const nakoGlobal = this.getNakoGlobal(options, out.gen)
813
+ const nakoGlobal = this.getNakoGlobal(options, out.gen, filename)
816
814
  // 実行
817
815
  this.evalJS(out.runtimeEnv, nakoGlobal)
818
816
  return nakoGlobal
819
817
  }
820
818
 
821
- private getNakoGlobal (options: CompilerOptions, gen: NakoGen): NakoGlobal {
819
+ private getNakoGlobal (options: CompilerOptions, gen: NakoGen, filename: string): NakoGlobal {
822
820
  // オプションを参照
823
821
  let g: NakoGlobal|null = options.nakoGlobal
824
822
  if (!g) {
@@ -828,6 +826,8 @@ export class NakoCompiler {
828
826
  } else {
829
827
  g = new NakoGlobal(this, gen, (this.__globals.length + 1))
830
828
  }
829
+ // 名前空間を設定
830
+ g.__varslist[0]['名前空間'] = NakoLexer.filenameToModName(filename)
831
831
  }
832
832
  if (this.__globals.indexOf(g) < 0) { this.__globals.push(g) }
833
833
  return g
@@ -1,8 +1,8 @@
1
1
  // 実際のバージョン定義 (自動生成されるので以下を編集しない)
2
2
  const coreVersion = {
3
- version: '3.3.76',
3
+ version: '3.3.77',
4
4
  major: 3,
5
5
  minor: 3,
6
- patch: 76
6
+ patch: 77
7
7
  };
8
8
  export default coreVersion;
@@ -11,9 +11,9 @@ export interface NakoCoreVersion {
11
11
  }
12
12
  // 実際のバージョン定義 (自動生成されるので以下を編集しない)
13
13
  const coreVersion: NakoCoreVersion = {
14
- version: '3.3.76',
14
+ version: '3.3.77',
15
15
  major: 3,
16
16
  minor: 3,
17
- patch: 76
17
+ patch: 77
18
18
  }
19
19
  export default coreVersion
@@ -857,7 +857,17 @@ export class NakoGen {
857
857
  const idx = this._convGen(list[i], true);
858
858
  code += '[' + idx + ']';
859
859
  }
860
- const value = this._convGen(node.value, true);
860
+ // value
861
+ let value = null;
862
+ if (this.speedMode.invalidSore === 0) {
863
+ value = this.varname('それ');
864
+ }
865
+ if (node.value) {
866
+ value = this._convGen(node.value, true);
867
+ }
868
+ if (value == null) {
869
+ throw NakoSyntaxError.fromNode('代入する先の変数名がありません。', node);
870
+ }
861
871
  code += ' = ' + value + ';\n';
862
872
  // generate code
863
873
  const src = this.convLineno(node, false) + codeInit + code;
@@ -922,7 +922,13 @@ export class NakoGen {
922
922
  const idx = this._convGen(list[i], true)
923
923
  code += '[' + idx + ']'
924
924
  }
925
- const value = this._convGen(node.value, true)
925
+ // value
926
+ let value = null
927
+ if (this.speedMode.invalidSore === 0) { value = this.varname('それ') }
928
+ if (node.value) { value = this._convGen(node.value, true) }
929
+ if (value == null) {
930
+ throw NakoSyntaxError.fromNode('代入する先の変数名がありません。', node)
931
+ }
926
932
  code += ' = ' + value + ';\n'
927
933
  // generate code
928
934
  const src = this.convLineno(node, false) + codeInit + code
@@ -17,7 +17,7 @@ export default {
17
17
  // 言語バージョンを設定
18
18
  sys.__v0['ナデシコバージョン'] = sys.version;
19
19
  sys.__v0['ナデシコ言語バージョン'] = sys.coreVersion;
20
- sys.__namespace = '*';
20
+ sys.__namespaceList = [];
21
21
  // なでしこの関数や変数を探して返す
22
22
  sys.__findVar = function (nameStr, def) {
23
23
  if (typeof nameStr === 'function') {
@@ -2820,12 +2820,29 @@ export default {
2820
2820
  },
2821
2821
  return_none: true
2822
2822
  },
2823
+ '名前空間': { type: 'const', value: '' },
2823
2824
  '名前空間設定': {
2824
2825
  type: 'func',
2825
2826
  josi: [['に', 'へ']],
2826
2827
  pure: true,
2827
2828
  fn: function (s, sys) {
2828
- sys.__namespace = s;
2829
+ // push namespace
2830
+ sys.__namespaceList.push([sys.__v0['名前空間'], sys.__v0['プラグイン名']]);
2831
+ sys.__v0['名前空間'] = s;
2832
+ },
2833
+ return_none: true
2834
+ },
2835
+ '名前空間ポップ': {
2836
+ type: 'func',
2837
+ josi: [],
2838
+ pure: true,
2839
+ fn: function (sys) {
2840
+ // pop namespace
2841
+ const a = sys.__namespaceList.pop();
2842
+ if (a) {
2843
+ sys.__v0['名前空間'] = a[0];
2844
+ sys.__v0['プラグイン名'] = a[1];
2845
+ }
2829
2846
  },
2830
2847
  return_none: true
2831
2848
  },
@@ -18,7 +18,7 @@ export default {
18
18
  // 言語バージョンを設定
19
19
  sys.__v0['ナデシコバージョン'] = sys.version
20
20
  sys.__v0['ナデシコ言語バージョン'] = sys.coreVersion
21
- sys.__namespace = '*'
21
+ sys.__namespaceList = []
22
22
  // なでしこの関数や変数を探して返す
23
23
  sys.__findVar = function (nameStr: any, def: any): any {
24
24
  if (typeof nameStr === 'function') { return nameStr }
@@ -2671,12 +2671,29 @@ export default {
2671
2671
  },
2672
2672
  return_none: true
2673
2673
  },
2674
- '名前空間設定': { // @名前空間が変更される // @なまえくうかんせってい
2674
+ '名前空間': { type: 'const', value: '' }, // @なまえくうかん
2675
+ '名前空間設定': { // @名前空間をSに設定する(システムにより自動的に変更される。ファイル名から拡張子を削ったもの) // @なまえくうかんせってい
2675
2676
  type: 'func',
2676
2677
  josi: [['に', 'へ']],
2677
2678
  pure: true,
2678
2679
  fn: function (s: string, sys: any) {
2679
- sys.__namespace = s
2680
+ // push namespace
2681
+ sys.__namespaceList.push([sys.__v0['名前空間'], sys.__v0['プラグイン名']])
2682
+ sys.__v0['名前空間'] = s
2683
+ },
2684
+ return_none: true
2685
+ },
2686
+ '名前空間ポップ': { // @システム利用のため呼ぶべからず。(名前空間を一つ前の値に戻す) // @なまえくうかんぽっぷ
2687
+ type: 'func',
2688
+ josi: [],
2689
+ pure: true,
2690
+ fn: function (sys: any) {
2691
+ // pop namespace
2692
+ const a = sys.__namespaceList.pop()
2693
+ if (a) {
2694
+ sys.__v0['名前空間'] = a[0]
2695
+ sys.__v0['プラグイン名'] = a[1]
2696
+ }
2680
2697
  },
2681
2698
  return_none: true
2682
2699
  },
@@ -32,4 +32,7 @@ describe('array_test', async () => {
32
32
  it('要素から配列を記述する際に明示的な()が必要になる不具合 #1000', async () => {
33
33
  await cmp('Aは[0,1,2];Bは[A[1], A[1], A[2]];B[1]を表示', '1')
34
34
  })
35
+ it('配列を「代入」文するとエラーが出る問題 (nadesiko3 #1354)(core #75)', async () => {
36
+ await cmp('Aは[];1に2を足して、A[0]に代入。A[0]を表示。', '3')
37
+ })
35
38
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nadesiko3",
3
- "version": "3.3.76",
3
+ "version": "3.3.77",
4
4
  "description": "Japanese Programming Language",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",