-
Notifications
You must be signed in to change notification settings - Fork 722
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
[AssemblyScript] porting source from JS to AS #421
Draft
StEvUgnIn
wants to merge
32
commits into
toji:master
Choose a base branch
from
OpenCampusOrg:assemblyscript
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
65f3513
configuring env for working with assemblyscript
StEvUgnIn 600fc7d
porting js into as
StEvUgnIn 68c0b01
set assemblyscript portability for AS/TS
StEvUgnIn 758766d
update gitignore - yarn
StEvUgnIn 2239143
configuration for compilation of AS into JS
StEvUgnIn b61761e
add source types declarations for build
StEvUgnIn 4276d9c
fix required explicit toString conversion
StEvUgnIn fd1907b
fix module typings
StEvUgnIn f917c0c
implement workaround for AS100
StEvUgnIn 2e2ac0b
tsc build dist/index.dts from portable AS directly
StEvUgnIn a53c4e3
build successfully javascript and webassembly
StEvUgnIn 6f18cce
removed directive for TS typings
StEvUgnIn f1b573b
another fix to AS100 for expected closure
StEvUgnIn 6ff09f6
fix AS warnings
StEvUgnIn 6deca79
optimize MathUtil library
StEvUgnIn dc5e7da
optimize build for speed
StEvUgnIn cca26fa
fix modules in dist/index.d.ts
StEvUgnIn 598eff0
compile from single file index.ts
StEvUgnIn 28f978a
changetype is not implemented for TS compilation
StEvUgnIn 0749891
change MathUtil into JSMath and Maths namespaces
StEvUgnIn 36ecee9
merge JSMath and Maths and toolchain TS into AMD modules
StEvUgnIn 79a3b97
simplify toolchain to compile TS/AS into JS
StEvUgnIn 8a56b64
definitive toolchain compilation
StEvUgnIn 78a6d91
hypot cannot be parsed in JS build
StEvUgnIn 0dd49ae
javascript interface for webassembly
StEvUgnIn 194ed13
update .travis.yml for using latest node-lts version
StEvUgnIn 1922b8d
add upper case support
StEvUgnIn 1124e84
right asynchronous call for WebAssembly loading
StEvUgnIn 885e3b1
update assembly and asconfig.json
StEvUgnIn 2b03776
loader
StEvUgnIn 32801c0
build
StEvUgnIn ae420e4
as-pect
StEvUgnIn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"extends": "assemblyscript/std/portable.json", | ||
"exclude": [ | ||
"./**/*.spec.ts" | ||
], | ||
"include": [ | ||
"./**/*.ts" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.js | ||
!index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import wasm from '../build/optimized.wasm'; | ||
|
||
let modules; | ||
|
||
wasm({ ...imports }).then(instance => { | ||
modules = instance.exports; | ||
}); | ||
|
||
export const { | ||
glMatrix, | ||
mat2, mat2d, mat3, mat4, | ||
quat, quat2, | ||
vec2, vec3, vec4 | ||
} = modules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "umd", | ||
"outDir": "../dist/wasm", | ||
"allowJs": true, | ||
"checkJs": false | ||
}, | ||
"exclude": ["index.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const inputDir = 'assembly'; | ||
const outputDir = 'loader'; | ||
|
||
let declarations = new Set(); | ||
|
||
let content; | ||
|
||
fs.readdirSync(inputDir) | ||
.filter(file => | ||
file.includes('.ts') && | ||
!file.includes('import') && | ||
!file.includes('index') && | ||
!file.includes('math') && | ||
!file.includes('d.ts') && | ||
!file.includes('_tests_')) | ||
.forEach(file => { | ||
const fileName = file.split('.')[0]; | ||
let moduleName = fileName; | ||
if (file.includes('common')) { | ||
moduleName = 'glMatrix'; | ||
} | ||
content = `import { ${moduleName} } from './index.js'\n\nexport const {\n`; | ||
console.log(`Searching for exported functions and objects in file ${path.join(inputDir, file)}...`); | ||
fs.readFileSync(path.join(inputDir, file)).toString().split('\n').forEach(line => { | ||
if (line.match(/export.+(function|var).[a-z]+.+[;\{]/g) !== null) { | ||
declarations.add(line.replace(/export.+(function|var).([a-z]+).+[;\{\r]/g, "$2")); | ||
} | ||
}); | ||
|
||
declarations.forEach((value, value2, set) => { | ||
if (value != 'min' && value != 'max') { | ||
content += ` ${value},\n`; | ||
} | ||
}); | ||
content += `\} = ${moduleName};\n`; | ||
|
||
console.log(`Found ${declarations.size ?? 0} exports.`); | ||
|
||
loader = fs.writeFileSync(path.join(outputDir, fileName + '.js'), content); | ||
console.log(`Exports are being written to file ${path.join(outputDir, fileName + '.js')}\n`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary, before I implement a better solution for exporting WebAssembly modules. Solutions are either:
Making a WASM file for each module (curently max size for synchronous compilation is 4KB). Current WASM file is >100KB with-O3
optimizationloader.instantiateStreaming
<script>
to WebAssembly usingeval
or some callback and DOM for moving executed elements to<noscript>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebAssembly.Module.exports()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently experimenting with as-bind