Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 77 additions & 77 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,80 +39,80 @@ jobs:
- if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1

benchmark:
name: Benchmark
runs-on: ubuntu-latest
steps:
- name: Lua Install
run: sudo apt-get install lua5.3 luajit
- name: Glow Install
run: brew install glow
# Checkout master & commit
- name: Checkout master
uses: actions/checkout@v2
with:
ref: master
path: master
- name: Checkout commit
uses: actions/checkout@v2
with:
path: commit
- name: Use Node.js 12.13.1
uses: actions/setup-node@v1
with:
node-version: 12.13.1
# NPM
- name: NPM master
run: npm ci && npm run build
working-directory: master
- name: NPM commit
run: npm ci && npm run build
working-directory: commit
# Benchmark directory setup
- name: Ensure benchmark data dir exists
run: mkdir -p ./benchmark/data
working-directory: commit
- name: Copy commit benchmark to master
run: rm -rf ./master/benchmark && cp -rf ./commit/benchmark ./master/benchmark
# Run master benchmark first and output to commit benchmark data
- name: Build benchmark Lua 5.3 master
run: node ../../commit/dist/tstl.js -p tsconfig.53.json
working-directory: master/benchmark
- name: Run benchmark Lua 5.3 master
id: benchmark-lua-master
run: lua5.3 -- run.lua ../../../commit/benchmark/data/benchmark_master_53.json
working-directory: master/benchmark/dist
- name: Build benchmark LuaJIT master
run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
working-directory: master/benchmark
- name: Run benchmark LuaJIT master
id: benchmark-jit-master
run: luajit -- run.lua ../../../commit/benchmark/data/benchmark_master_jit.json
working-directory: master/benchmark/dist
# Run commit benchmark and compare with master
- name: Build benchmark Lua 5.3 commit
run: node ../../commit/dist/tstl.js -p tsconfig.53.json
working-directory: commit/benchmark
- name: Run benchmark Lua 5.3 commit
id: benchmark-lua-commit
run: lua5.3 -- run.lua ../data/benchmark_master_vs_commit_53.json ../data/benchmark_master_53.json
working-directory: commit/benchmark/dist
- name: Build benchmark LuaJIT commit
run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
working-directory: commit/benchmark
- name: Run benchmark LuaJIT commit
id: benchmark-jit-commit
run: luajit -- run.lua ../data/benchmark_master_vs_commit_jit.json ../data/benchmark_master_jit.json
working-directory: commit/benchmark/dist
- name: Combine benchmark results
id: script-combine-results
uses: actions/github-script@v3
with:
benchmark-result-path-lua: commit/benchmark/data/benchmark_master_vs_commit_53.json
benchmark-result-path-jit: commit/benchmark/data/benchmark_master_vs_commit_jit.json
result-encoding: string
script: |
const createBenchmarkCheck = require(`${process.env.GITHUB_WORKSPACE}/commit/.github/scripts/create_benchmark_check.js`);
return createBenchmarkCheck({ github, context, core });
- name: Benchmark results
run: echo "${{steps.script-combine-results.outputs.result}}" | glow -s dark -w 120 -
# benchmark:
# name: Benchmark
# runs-on: ubuntu-latest
# steps:
# - name: Lua Install
# run: sudo apt-get install lua5.3 luajit
# - name: Glow Install
# run: brew install glow
# # Checkout master & commit
# - name: Checkout master
# uses: actions/checkout@v2
# with:
# ref: master
# path: master
# - name: Checkout commit
# uses: actions/checkout@v2
# with:
# path: commit
# - name: Use Node.js 12.13.1
# uses: actions/setup-node@v1
# with:
# node-version: 12.13.1
# # NPM
# - name: NPM master
# run: npm ci && npm run build
# working-directory: master
# - name: NPM commit
# run: npm ci && npm run build
# working-directory: commit
# # Benchmark directory setup
# - name: Ensure benchmark data dir exists
# run: mkdir -p ./benchmark/data
# working-directory: commit
# - name: Copy commit benchmark to master
# run: rm -rf ./master/benchmark && cp -rf ./commit/benchmark ./master/benchmark
# # Run master benchmark first and output to commit benchmark data
# - name: Build benchmark Lua 5.3 master
# run: node ../../commit/dist/tstl.js -p tsconfig.53.json
# working-directory: master/benchmark
# - name: Run benchmark Lua 5.3 master
# id: benchmark-lua-master
# run: lua5.3 -- run.lua ../../../commit/benchmark/data/benchmark_master_53.json
# working-directory: master/benchmark/dist
# - name: Build benchmark LuaJIT master
# run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
# working-directory: master/benchmark
# - name: Run benchmark LuaJIT master
# id: benchmark-jit-master
# run: luajit -- run.lua ../../../commit/benchmark/data/benchmark_master_jit.json
# working-directory: master/benchmark/dist
# # Run commit benchmark and compare with master
# - name: Build benchmark Lua 5.3 commit
# run: node ../../commit/dist/tstl.js -p tsconfig.53.json
# working-directory: commit/benchmark
# - name: Run benchmark Lua 5.3 commit
# id: benchmark-lua-commit
# run: lua5.3 -- run.lua ../data/benchmark_master_vs_commit_53.json ../data/benchmark_master_53.json
# working-directory: commit/benchmark/dist
# - name: Build benchmark LuaJIT commit
# run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
# working-directory: commit/benchmark
# - name: Run benchmark LuaJIT commit
# id: benchmark-jit-commit
# run: luajit -- run.lua ../data/benchmark_master_vs_commit_jit.json ../data/benchmark_master_jit.json
# working-directory: commit/benchmark/dist
# - name: Combine benchmark results
# id: script-combine-results
# uses: actions/github-script@v3
# with:
# benchmark-result-path-lua: commit/benchmark/data/benchmark_master_vs_commit_53.json
# benchmark-result-path-jit: commit/benchmark/data/benchmark_master_vs_commit_jit.json
# result-encoding: string
# script: |
# const createBenchmarkCheck = require(`${process.env.GITHUB_WORKSPACE}/commit/.github/scripts/create_benchmark_check.js`);
# return createBenchmarkCheck({ github, context, core });
# - name: Benchmark results
# run: echo "${{steps.script-combine-results.outputs.result}}" | glow -s dark -w 120 -
13 changes: 9 additions & 4 deletions benchmark/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@ export function readFile(path: string): string {
}

export function readAll(file: LuaFile): string {
const content = file.read(_VERSION === "Lua 5.3" ? "a" : ("*a" as any)) as [string | undefined];
const content = file.read(_VERSION === "Lua 5.3" ? "a" : ("*a" as any));

if (content[0]) {
return content[0];
if (content) {
return content as string;
}
throw Error(`Can't readAll for file ${file}`);
}

export function readDir(dir: string): string[] {
const findHandle = io.popen(isWindows ? `dir /A-D /B ${dir}` : `find '${dir}' -maxdepth 1 -type f`);
const [findHandle] = io.popen(isWindows ? `dir /A-D /B ${dir}` : `find '${dir}' -maxdepth 1 -type f`);

if (!findHandle) {
throw new Error(`Failed to read dir ${dir}`);
}

const findResult = readAll(findHandle);

if (!findHandle.close()) {
Expand Down
52 changes: 43 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"javascript-stringify": "^2.0.1",
"jest": "^26.0.1",
"jest-circus": "^25.1.0",
"lua-types": "^2.8.0",
"lua-types": "2.10.1",
"lua-wasm-bindings": "^0.2.2",
"prettier": "^2.3.2",
"ts-jest": "^26.3.0",
Expand Down
15 changes: 10 additions & 5 deletions src/LuaLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,27 @@ const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
ArrayConcat: [LuaLibFeature.ArrayIsArray],
ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
ArrayFlatMap: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
Decorate: [LuaLibFeature.CloneDescriptor],
Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
DelegatedYield: [LuaLibFeature.StringAccess],
Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors],
Error: [LuaLibFeature.New, LuaLibFeature.Class],
Error: [LuaLibFeature.Class, LuaLibFeature.ClassExtends, LuaLibFeature.New],
FunctionBind: [LuaLibFeature.Unpack],
Generator: [LuaLibFeature.Symbol],
InstanceOf: [LuaLibFeature.Symbol],
Iterator: [LuaLibFeature.Symbol],
NumberToString: [LuaLibFeature.StringAccess],
ObjectDefineProperty: [LuaLibFeature.CloneDescriptor, LuaLibFeature.SetDescriptor],
ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],
ParseFloat: [LuaLibFeature.StringAccess],
ParseInt: [LuaLibFeature.StringSubstr, LuaLibFeature.StringSubstring],
SetDescriptor: [LuaLibFeature.CloneDescriptor],
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
SymbolRegistry: [LuaLibFeature.Symbol],
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
Spread: [LuaLibFeature.Iterator, LuaLibFeature.Unpack],
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
SymbolRegistry: [LuaLibFeature.Symbol],
Spread: [LuaLibFeature.Iterator, LuaLibFeature.StringAccess, LuaLibFeature.Unpack],
};
/* eslint-enable @typescript-eslint/naming-convention */

Expand Down
2 changes: 2 additions & 0 deletions src/lualib/ArrayIsArray.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
declare type NextEmptyCheck = (this: void, table: any, index: undefined) => unknown | undefined;

function __TS__ArrayIsArray(this: void, value: any): value is any[] {
// Workaround to determine if value is an array or not (fails in case of objects without keys)
// See discussion in: https://github.com/TypeScriptToLua/TypeScriptToLua/pull/7
Expand Down
16 changes: 8 additions & 8 deletions src/lualib/ArrayReduce.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.reduce
function __TS__ArrayReduce<T>(
function __TS__ArrayReduce<TElement, TAccumulator>(
this: void,
arr: T[],
callbackFn: (accumulator: T, currentValue: T, index: number, array: T[]) => T,
...initial: T[]
): T {
arr: TElement[],
callbackFn: (accumulator: TAccumulator, currentValue: TElement, index: number, array: TElement[]) => TAccumulator,
...initial: TAccumulator[]
): TAccumulator {
const len = arr.length;

let k = 0;
let accumulator = undefined;
let accumulator: TAccumulator = undefined;

// Check if initial value is present in function call
if (select("#", ...initial) !== 0) {
accumulator = select(1, ...initial);
[accumulator] = select(1, ...initial);
} else if (len > 0) {
accumulator = arr[0];
accumulator = arr[0] as unknown as TAccumulator;
k = 1;
} else {
throw "Reduce of empty array with no initial value";
Expand Down
16 changes: 8 additions & 8 deletions src/lualib/ArrayReduceRight.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.reduce
function __TS__ArrayReduceRight<T>(
function __TS__ArrayReduceRight<TElement, TAccumulator>(
this: void,
arr: T[],
callbackFn: (accumulator: T, currentValue: T, index: number, array: T[]) => T,
...initial: T[]
): T {
arr: TElement[],
callbackFn: (accumulator: TAccumulator, currentValue: TElement, index: number, array: TElement[]) => TAccumulator,
...initial: TAccumulator[]
): TAccumulator {
const len = arr.length;

let k = len - 1;
let accumulator = undefined;
let accumulator: TAccumulator = undefined;

// Check if initial value is present in function call
if (select("#", ...initial) !== 0) {
accumulator = select(1, ...initial);
[accumulator] = select(1, ...initial);
} else if (len > 0) {
accumulator = arr[k];
accumulator = arr[k] as unknown as TAccumulator;
k -= 1;
} else {
throw "Reduce of empty array with no initial value";
Expand Down
8 changes: 4 additions & 4 deletions src/lualib/ArraySplice.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.splice
function __TS__ArraySplice<T>(this: void, list: T[], ...args: unknown[]): T[] {
function __TS__ArraySplice<T>(this: void, list: T[], ...args: T[]): T[] {
const len = list.length;

const actualArgumentCount = select("#", ...args);
const start = select(1, ...args) as number;
const deleteCount = select(2, ...args) as number;
const start = select(1, ...args)[0] as unknown as number;
const deleteCount = select(2, ...args)[0] as unknown as number;

let actualStart: number;

Expand Down Expand Up @@ -67,7 +67,7 @@ function __TS__ArraySplice<T>(this: void, list: T[], ...args: unknown[]): T[] {

let j = actualStart;
for (const i of $range(3, actualArgumentCount)) {
list[j] = select(i, ...args) as T;
list[j] = select(i, ...args)[0];
j++;
}

Expand Down
Loading