Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Feature/o3opt -O3 : 44 MB -> 37 MB #28

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 8 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash
set -e
[ -z $EM_DIR] && EM_DIR=~/src/emscripten
[ -z "$EM_DIR" ] && EM_DIR=~/src/emscripten

OPTZ="-Oz -O3"

do_config() {
echo config
# something wrong with emcc + cproto, use gcc as CPP instead
CPPFLAGS="-Os -DFEAT_GUI_WEB" \
CPP="gcc -E" \
CPPFLAGS="$OPTZ -DFEAT_GUI_WEB" \
CFLAGS="$OPTZ" \
CPP="emcc -E" \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that emcc -E does not work well. Did you try this on a fresh clone of vim.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think it worked. But for emterpreter I had to use emscripten 1.29 for the configure step and the latest version for make and link.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I think it's better to use gcc here.

$EM_DIR/emconfigure ./configure \
--enable-gui=web \
--with-features=small \
Expand Down Expand Up @@ -46,7 +49,7 @@ $EM_DIR/emconfigure ./configure \
}

do_make() {
$EM_DIR/emmake make -j8
$EM_DIR/emmake make CFLAGS="$OPTZ" -j8
}

do_link() {
Expand All @@ -58,7 +61,7 @@ cat vim_lib.js | sed -e "1 s/\(foldmethod\|foldmarker\)[^ ]\+//g" > usr/local/sh
# Use vim.js as filename to generate vim.js.mem
$EM_DIR/emcc vim.bc \
-o vim.js \
-Oz \
$OPTZ \
--memory-init-file 1 \
--js-library vim_lib.js \
-s ASYNCIFY=1 \
Expand Down
2 changes: 2 additions & 0 deletions web/usr/local/share/vim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ set wildmenu
set tabstop=4
set expandtab
set nocompatible
set encoding=utf8
set termencoding=utf8
set fileencodings=utf8
set backspace=indent,eol,start
set wildmode=longest,list,full
Expand Down
47 changes: 39 additions & 8 deletions web/vim_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,27 @@ var LibraryVIM = {
if(charCode == 0) {
var special = vimjs.special_keys[keyCode];
if(special !== undefined) {
vimjs.gui_web_handle_key(charCode || keyCode, modifiers, special.charCodeAt(0), special.charCodeAt(1));
vimjs.gui_web_handle_key(keyCode, modifiers, special.charCodeAt(0), special.charCodeAt(1));
handled = true;
}
} else {
vimjs.gui_web_handle_key(keyCode, modifiers, 0, 0);
handled = true;
}
}

if(!handled)
vimjs.gui_web_handle_key(charCode || keyCode, modifiers, 0, 0);
if(!handled) {
var MAX_UTF8_BYTES = 6;
var chars = new Uint8Array(MAX_UTF8_BYTES + 1); // null-terminated
var charLen = stringToUTF8Array(String.fromCharCode(charCode), chars, 0, MAX_UTF8_BYTES);
if (charLen == 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this if clause useful?

vimjs.gui_web_handle_key(chars[0], 0, 0, 0);
} else {
// no modifers for UTF-8, should be handled in chars already
for (var i = 0; i < charLen; i++) {
vimjs.gui_web_handle_key(chars[i], 0, 0, 0);
}
}
}

},//VIMJS_FOLD_END

Expand Down Expand Up @@ -685,6 +699,7 @@ var LibraryVIM = {
* C means "needed for Chrome"
*/
var keys_to_intercept_upon_keydown = {};
var ctrl_keys_to_intercept_upon_keydown = {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this line right before it is assigned.

[ KeyEvent.DOM_VK_ESCAPE, // CF
KeyEvent.DOM_VK_TAB, // C
KeyEvent.DOM_VK_BACK_SPACE, // C
Expand All @@ -695,14 +710,24 @@ var LibraryVIM = {
KeyEvent.DOM_VK_DELETE, // C
KeyEvent.DOM_VK_PAGE_UP, // C
KeyEvent.DOM_VK_PAGE_DOWN, // C
KeyEvent.DOM_VK_HOME, // C
KeyEvent.DOM_VK_END, // C
].forEach(function(k) {
keys_to_intercept_upon_keydown[k] = 1;
});
[
KeyEvent.DOM_VK_F,
KeyEvent.DOM_VK_B,
].forEach(function(k) {
ctrl_keys_to_intercept_upon_keydown[k] = 1;
});


/* capture some special keys that won't trigger 'keypress' */
document.addEventListener('keydown', function(e) {
if (ignoreKeys()) return true;
if(e.keyCode in keys_to_intercept_upon_keydown) {
if((e.keyCode in keys_to_intercept_upon_keydown) ||
(e.ctrlKey && (e.keyCode in ctrl_keys_to_intercept_upon_keydown))) {
e.preventDefault();
vimjs.handle_key(0, e.keyCode, e);
}
Expand Down Expand Up @@ -778,7 +803,15 @@ var LibraryVIM = {
},

vimjs_draw_string__deps: ['vimjs_clear_block'],
vimjs_draw_string: function(row, col, s, len, flags) {
vimjs_draw_string: function(row, col, s_ptr, len, flags) {
var byteArray = [];
for (var i = 0; i < len; i++) {
c = getValue(s_ptr + i, 'i8', true);
byteArray.push(c);
}
byteArray.push(0);
var s = UTF8ArrayToString(byteArray, 0);
len = s.length;

// TODO: use macros for flag constants
if(!(flags & 0x01)) {
Expand All @@ -788,8 +821,6 @@ var LibraryVIM = {
var font = vimjs.font;
if(flags & 0x02) font = 'bold ' + font;

s = Pointer_stringify(s, len);

var ctx = vimjs.canvas_ctx;

ctx.font = font;
Expand Down