Skip to content

Commit

Permalink
実行時に変数を初期化するようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
massongit committed Jun 13, 2020
1 parent 028e992 commit 657ba1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nako3.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class NakoCompiler {
this.__v1 = this.__varslist[1]
this.__vars = this.__varslist[2]
this.gen.reset()
this.clearLog()
}

/**
Expand Down Expand Up @@ -146,7 +145,8 @@ class NakoCompiler {
}

_run(code, isReset, isTest) {
if (isReset) {this.reset()}
this.reset()
if (isReset) {this.clearLog()}
let js = this.compile(code, isTest)
let __varslist = this.__varslist
let __vars = this.__vars = this.__varslist[2] // eslint-disable-line
Expand Down
15 changes: 15 additions & 0 deletions test/func_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ describe('func_test', () => {
if (nako.debug) console.log('code=' + code)
assert.equal(nako.runReset(code).log, res)
}
const cmpWithoutReset = (code, res) => {
if (nako.debug) console.log('code=' + code)
assert.equal(nako.run(code).log, res)
}
// --- test ---

it('簡単な関数定義', () => {
Expand Down Expand Up @@ -68,6 +72,17 @@ describe('func_test', () => {
cmp('定数のN=30\n' +
'Nを表示。', '30')
})
it('ローカル定数2', () => {
const _res = '30'
let res = _res

nako.clearLog()
for (let i = 0; i < 2; i++) {
cmpWithoutReset('定数のN=30\n' +
'Nを表示。', res)
res += '\n' + _res
}
})
it('助詞の複数定義', () => {
cmp('●加算処理(AにBを|AとBの)\n' +
'(A+B)を戻す。\n' +
Expand Down

0 comments on commit 657ba1c

Please sign in to comment.