Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for build #22

Merged
merged 23 commits into from
Mar 3, 2019
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
15 changes: 3 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@ version: 2
jobs:
build:
docker:
- image: dlanguage/ldc
- image: node:11-slim
steps:
- checkout
- run:
name: Install debian-packaged dependencies
command: |
apt update
apt install -y git build-essential curl build-essential
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt update && apt install -y nodejs
# curl/apt-transport-https for yarn, python, build-essential for node-gyp
apt install -y curl apt-transport-https python build-essential
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt update && apt install -y yarn
ln -s $(which ldc2) /usr/local/bin/ldc
- run:
name: Install btest
command: |
git clone https://github.com/briansteffens/btest
cd btest
make
make install
- run:
name: Install Node dependencies, run tests
command: |
Expand Down
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'prettier',
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-use-before-define': 0,
"arrow-parens": [
1,
"always"
],
"class-methods-use-this": 1,
"func-names": 0,
"function-paren-newline": 0,
"no-plusplus": 0,
"object-curly-newline": 0,
"prefer-arrow-callback": 0,
}
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bin
build
node_modules
*~
yarn-error.log
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $ node bin/index.js
* Prototype functions
* Nested functions
* Closures
* And much, much more!

### Code produced

Expand Down Expand Up @@ -61,56 +62,57 @@ Gets compiled to:
```cpp
#include "lib.cc"

void tco_fib(const FunctionCallbackInfo<Value>& _args) {
Isolate* isolate = _args.GetIsolate();
std::vector<Local<Value>> args(_args.Length());;
for (int i = 0; i < _args.Length(); i++) args[i] = _args[i];
void tco_fib(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
Local<Value> tco_n = args[0];
Local<Value> tco_a = args[1];
Local<Value> tco_b = args[2];
tail_recurse_0:

Local<Number> sym_rhs_4 = Number::New(isolate, 0);
Local<Boolean> sym_anon_2 = args[0]->StrictEquals(sym_rhs_4) ? True(isolate) : False(isolate);
if (sym_anon_2->IsTrue()) {
_args.GetReturnValue().Set(args[1]);
if (tco_n->StrictEquals(Number::New(isolate, 0))) {
args.GetReturnValue().Set(tco_a);
return;
}

Local<Number> sym_rhs_11 = Number::New(isolate, 1);
Local<Boolean> sym_anon_9 = args[0]->StrictEquals(sym_rhs_11) ? True(isolate) : False(isolate);
if (sym_anon_9->IsTrue()) {
_args.GetReturnValue().Set(args[2]);
if (tco_n->StrictEquals(Number::New(isolate, 1))) {
args.GetReturnValue().Set(tco_b);
return;
}

Local<Number> sym_rhs_19 = Number::New(isolate, 1);
Local<Value> sym_arg_17 = genericMinus(isolate, args[0], sym_rhs_19);
Local<Value> sym_arg_21 = genericPlus(isolate, args[1], args[2]);
args[0] = sym_arg_17;
args[1] = args[2];
args[2] = sym_arg_21;
Local<Number> sym_arg_20 =
genericMinus(isolate, tco_n, Number::New(isolate, 1));
Local<Value> sym_arg_23 = tco_b;
Local<Value> sym_arg_24 = genericPlus(isolate, tco_a, tco_b);
tco_n = Local<Value>::Cast(sym_arg_20);
tco_a = sym_arg_23;
tco_b = sym_arg_24;
goto tail_recurse_0;

return;
}

void jsc_main(const FunctionCallbackInfo<Value>& _args) {
Isolate* isolate = _args.GetIsolate();
std::vector<Local<Value>> args(_args.Length());;
for (int i = 0; i < _args.Length(); i++) args[i] = _args[i];
void jsc_main(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
tail_recurse_1:

Local<Number> sym_arg_29 = Number::New(isolate, 100);
Local<Number> sym_arg_30 = Number::New(isolate, 0);
Local<Number> sym_arg_31 = Number::New(isolate, 1);
Local<Value> sym_args_32[] = { sym_arg_29, sym_arg_30, sym_arg_31 };
Local<Function> sym_fn_33 = FunctionTemplate::New(isolate, tco_fib)->GetFunction();
sym_fn_33->SetName(String::NewFromUtf8(isolate, "tco_fib"));
Local<Value> sym_arg_28 = sym_fn_33->Call(sym_fn_33, 3, sym_args_32);

Local<Value> sym_args_34[] = { sym_arg_28 };
Local<Value> sym_parent_37 = isolate->GetCurrentContext()->Global()->Get(String::NewFromUtf8(isolate, "console"));
Local<Value> sym_anon_36 = sym_parent_37.As<Object>()->Get(String::NewFromUtf8(isolate, "log"));
Local<Function> sym_fn_35 = Local<Function>::Cast(sym_anon_36);
Local<Value> sym_anon_27 = sym_fn_35->Call(sym_fn_35, 1, sym_args_34);
Local<Value> sym_args_33[] = {Number::New(isolate, 50),
Number::New(isolate, 0),
Number::New(isolate, 1)};
Local<Value> sym_arg_29 =
Local<Function>::Cast(
Local<Value>::Cast(
FunctionTemplate::New(isolate, tco_fib)->GetFunction()))
->Call(Local<Function>::Cast(Local<Value>::Cast(
FunctionTemplate::New(isolate, tco_fib)->GetFunction())),
3, sym_args_33);

Local<Value> sym_args_35[] = {sym_arg_29};
Local<Value> sym_parent_37 = isolate->GetCurrentContext()->Global()->Get(
String::NewFromUtf8(isolate, "console"));
Local<Value> sym_fn_36 =
sym_parent_37.As<Object>()->Get(String::NewFromUtf8(isolate, "log"));
Local<Value> sym_block_28 = Local<Function>::Cast(sym_fn_36)->Call(
Local<Function>::Cast(sym_fn_36), 1, sym_args_35);

return;
}
Expand All @@ -121,5 +123,3 @@ void Init(Local<Object> exports) {

NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
```

By running `./build.sh examples/recursion.js`.
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
"version": "0.0.1",
"bin": "./build/jsc",
"scripts": {
"install": "yarn tsc",
"test": "./tests/run.sh"
"install": "tsc",
"test": "./scripts/test.sh",
"lint": "./scripts/lint.sh",
"lint:fix": "./scripts/lint.sh --fix"
},
"dependencies": {
"@types/node": "^11.9.4",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2",
"eslint": "^5.15.0",
"eslint-config-prettier": "^4.1.0",
"node-gyp": "^3.8.0",
"prettier": "^1.16.4",
"prettylint": "^1.0.0",
"rimraf": "^2.6.3",
"tsc": "^1.20150623.0",
"typescript": "^3.3.3"
},
"prettier": {
"singleQuote": true,
"arrowParens": "always",
"trailingComma": "all"
}
}
2 changes: 2 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eslint src/*.ts src/**/*.ts $1
prettylint src/*.ts src/**/*.ts $1
4 changes: 3 additions & 1 deletion tests/run.sh → scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

for f in tests/*.js; do
echo "Testing $f"
node build/main "$f"
node build/jsc.js "$f"
node bin
done

exit
54 changes: 38 additions & 16 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,48 @@ export function build(buildDirectory: string, program: string) {
try {
rimraf.sync(buildDirectory);
fs.mkdirSync(buildDirectory);
} catch (e) {}
} catch (e) {
// Ignore
}

fs.writeFileSync(path.join(buildDirectory, 'lib.cc'),
fs.readFileSync(path.join(__dirname, '../src/compile/lib.cc')));
fs.writeFileSync(path.join(buildDirectory, 'jsc.cc'),
program);
fs.writeFileSync(path.join(buildDirectory, 'binding.gyp'),
JSON.stringify({
targets: [
{
target_name: 'jsc',
sources: ['jsc.cc'],
},
],
}));
fs.writeFileSync(
path.join(buildDirectory, 'lib.cc'),
fs.readFileSync(path.join(__dirname, '../src/compile/lib.cc')),
);
fs.writeFileSync(path.join(buildDirectory, 'jsc.cc'), program);
fs.writeFileSync(
path.join(buildDirectory, 'binding.gyp'),
JSON.stringify({
targets: [
{
sources: ['jsc.cc'],
// eslint-disable-next-line @typescript-eslint/camelcase
target_name: 'jsc',
},
],
}),
);

try {
cp.execSync(
['clang-format -i', path.join(buildDirectory, 'lib.cc')].join(' '),
);
cp.execSync(
['clang-format -i', path.join(buildDirectory, 'jsc.cc')].join(' '),
);
} catch (e) {
// Oh well
}

// Build library
cp.execSync('../node_modules/.bin/node-gyp configure', { cwd: buildDirectory });
cp.execSync('../node_modules/.bin/node-gyp configure', {
cwd: buildDirectory,
});
cp.execSync('../node_modules/.bin/node-gyp build', { cwd: buildDirectory });

// Create Node entrypoint
fs.writeFileSync(path.join(buildDirectory, 'index.js'), 'require(\"./build/Release/jsc.node\").jsc_main();\n');
fs.writeFileSync(
path.join(buildDirectory, 'index.js'),
'require("./build/Release/jsc.node").jsc_main();\n',
);
}
Loading