Skip to content

Commit a42c3fa

Browse files
committed
.
1 parent de85943 commit a42c3fa

File tree

9 files changed

+3687
-18
lines changed

9 files changed

+3687
-18
lines changed

Makefile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ clean:
77
rm $(ALL) */node_modules
88
.PHONY: clean
99

10-
test: ecmascript3_commonjs/node_modules
11-
$(MAKE) all
12-
cd ecmascript3_commonjs && yarn test
10+
test: all test_ecmascript3
1311
.PHONY: test
1412

13+
test_ecmascript3: all ecmascript3_commonjs/node_modules
14+
cd ecmascript3_commonjs && yarn test
15+
.PHONY: test_ecmascript3
16+
17+
test_lua: all lua/node_modules
18+
cd lua && yarn test
19+
.PHONY: test_lua
20+
1521
typescript/node_modules: typescript/yarn.lock
1622
cd typescript && yarn && touch node_modules/
1723

@@ -21,14 +27,14 @@ ecmascript3_commonjs/node_modules: ecmascript3_commonjs/yarn.lock
2127
lua/node_modules: lua/yarn.lock
2228
cd lua && yarn && touch node_modules/
2329

24-
lua/lang.ts: typescript/lang.ts.d/*.ts typescript/lang.ts.d/lua.d/*.ts
25-
cat typescript/lang.ts.d/*.ts typescript/lang.ts.d/lua.d/*.ts > lua/lang.ts
30+
lua/lang.ts: typescript/lang.ts.d/lua.d/*.ts typescript/lang.ts.d/*.ts
31+
cat typescript/lang.ts.d/lua.d/*.ts typescript/lang.ts.d/*.ts > lua/lang.ts
2632

2733
lua/lang.lua: lua/tsconfig.json lua/lang.ts lua/node_modules
2834
cd lua && ./node_modules/.bin/tstl
2935

30-
ecmascript3_commonjs/lang.ts: typescript/lang.ts.d/*.ts typescript/lang.ts.d/ecmascript3.d/*.ts
31-
cat typescript/lang.ts.d/*.ts typescript/lang.ts.d/ecmascript3.d/*.ts > ecmascript3_commonjs/lang.ts
36+
ecmascript3_commonjs/lang.ts: typescript/lang.ts.d/ecmascript3.d/*.ts typescript/lang.ts.d/*.ts
37+
cat typescript/lang.ts.d/ecmascript3.d/*.ts typescript/lang.ts.d/*.ts > ecmascript3_commonjs/lang.ts
3238

3339
ecmascript3_commonjs/lang.js: ecmascript3_commonjs/tsconfig.json ecmascript3_commonjs/lang.ts ecmascript3_commonjs/node_modules
3440
cd ecmascript3_commonjs && ./node_modules/.bin/tsc

ecmascript3_commonjs/lang.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
The Language
3+
Copyright (C) 2018, 2019 Zaoqi <zaomir@outlook.com>
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
*/
19+
// ecmascript3_commonjs/lang.test.js與lua/lang.test.js內容相同
120
const BiwaScheme = require('@zaoqi/biwascheme')
221
const TheLanguage = require('./lang.js')
322
BiwaScheme.define_libfunc('test-describe', 2, 2, (ar, intp)=>{

lua/lang.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
The Language
3+
Copyright (C) 2018, 2019 Zaoqi <zaomir@outlook.com>
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
*/
19+
const assert = require('assert').strict
20+
const {luaconf, lua, lauxlib, lualib} = require('fengari')
21+
const fengari = require('fengari')
22+
const lua_interop = require('fengari-interop')
23+
const L = lauxlib.luaL_newstate()
24+
lualib.luaL_openlibs(L)
25+
lauxlib.luaL_requiref(L, fengari.to_luastring("js"), lua_interop.luaopen_js, 0)
26+
assert.equal(lauxlib.luaL_loadfile(L, 'lang.lua'),0)
27+
lua.lua_call(L, 0, 1)
28+
const TheLanguage = lua_interop.tojs(L, -1)
29+
for(const [k, _] of TheLanguage) {
30+
const raw_v = TheLanguage.get(k)
31+
let v = raw_v
32+
if(typeof v === 'function'){
33+
v = (...args)=>(x=>x).call.call(raw_v, ...args)
34+
}
35+
exports[k] = v
36+
}
37+
exports._lua_module = TheLanguage
38+
exports._lua_state = L
39+
exports._fengari = fengari
40+
exports._fengari_interop = lua_interop

lua/lang.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
The Language
3+
Copyright (C) 2018, 2019 Zaoqi <zaomir@outlook.com>
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
*/
19+
// ecmascript3_commonjs/lang.test.js與lua/lang.test.js內容相同
20+
const BiwaScheme = require('@zaoqi/biwascheme')
21+
const TheLanguage = require('./lang.js')
22+
BiwaScheme.define_libfunc('test-describe', 2, 2, (ar, intp)=>{
23+
BiwaScheme.assert_closure(ar[1])
24+
const name=BiwaScheme.to_write(ar[0])
25+
const body=BiwaScheme.js_closure(ar[1], intp)
26+
test(name,()=>{
27+
body()
28+
})
29+
})
30+
BiwaScheme.define_libfunc('test-check-equal?', 2, 2, (ar)=>{
31+
expect(BiwaScheme.equal(ar[0],ar[1])).toBe(true)
32+
})
33+
for(const [k, a, v] of [
34+
['complex-parse', 1, TheLanguage.complex_parse],
35+
['complex-print', 1, TheLanguage.complex_print],
36+
['simple-print', 1, TheLanguage.simple_print],
37+
['machinetext-parse', 1, TheLanguage.machinetext_parse],
38+
['machinetext-print', 1, TheLanguage.machinetext_print],
39+
['evaluate-with-environment', 2, TheLanguage.evaluate_with_environment],
40+
['force-all-rec-ignore-comment', 1, TheLanguage.force_all_rec_ignore_comment],
41+
]){
42+
BiwaScheme.define_libfunc(k, a, a, (ar)=>v.apply(null, ar))
43+
}
44+
for(const [k, v] of [
45+
['null-v', TheLanguage.null_v],
46+
['environment-null-v', TheLanguage.env_null_v],
47+
]){
48+
BiwaScheme.TopEnv[k] = v
49+
}
50+
BiwaScheme.run_file('../test.scm')

lua/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
2+
"scripts": {
3+
"test": "jest"
4+
},
25
"devDependencies": {
6+
"@zaoqi/biwascheme": "^0.6.9-4-ecbc0c5c4fd8b90aa64bfbf0214483220e71eea1",
37
"fengari": "^0.1.4",
48
"fengari-interop": "^0.1.2",
9+
"jest": "^24.9.0",
510
"typescript-to-lua": "^0.27.1"
611
}
712
}

lua/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"target": "esnext",
44
"lib": ["esnext"],
5-
"strict": true
5+
"strict": true,
6+
"types" : [],
67
},
78
"tstl": {
89
"luaTarget": "JIT"

0 commit comments

Comments
 (0)