Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
Signed-off-by: Shaw Summa <[email protected]>
  • Loading branch information
ShawSumma committed Feb 14, 2024
1 parent 702278c commit cc4ecd3
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 274 deletions.
2 changes: 1 addition & 1 deletion vm/backend/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void *vm_cache_comp(const char *comp, const char **srcs, const char *entry) {
}
fclose(out);
vm_io_buffer_t *cmd_buf = vm_io_buffer_new();
vm_io_buffer_format(cmd_buf, "%s -shared -O2 -foptimize-sibling-calls -fPIC %s -o %s -w", comp, c_file, so_file);
vm_io_buffer_format(cmd_buf, "%s -shared -O2 -foptimize-sibling-calls -fPIC %s -o %s -w -pipe", comp, c_file, so_file);
int res = system(cmd_buf->buf);
if (res) {
return NULL;
Expand Down
158 changes: 2 additions & 156 deletions vm/backend/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ void vm_tb_func_print_value(vm_tb_state_t *state, vm_tag_t tag, TB_Node *value);
TB_Node *vm_tb_func_body_once(vm_tb_state_t *state, TB_Node **regs, vm_block_t *block);
void vm_tb_func_report_error(vm_tb_state_t *state, const char *str);

#define vm_tb_select_binary_type(xtag, onint, onfloat, ...) ({ \
vm_tag_t tag = xtag; \
TB_Node *ret = NULL; \
if (tag != VM_TAG_F64 && tag != VM_TAG_F32) { \
ret = onint(__VA_ARGS__, TB_ARITHMATIC_NONE); \
} else { \
ret = onfloat(__VA_ARGS__); \
} \
ret; \
})

#define vm_tb_select_binary_cmp(xtag, onint, onfloat, ...) ({ \
vm_tag_t tag = xtag; \
TB_Node *ret = NULL; \
Expand Down Expand Up @@ -540,9 +529,9 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
} else if (instr.tag == VM_TAG_I64) {
len = tb_inst_zxt(state->fun, len, TB_TYPE_I64);
} else if (instr.tag == VM_TAG_F32) {
len = tb_inst_int2float(state->fun, len, TB_TYPE_F32, false);
len = tb_inst_int2float(state->fun, len, TB_TYPE_F32, true);
} else if (instr.tag == VM_TAG_F64) {
len = tb_inst_int2float(state->fun, len, TB_TYPE_F64, false);
len = tb_inst_int2float(state->fun, len, TB_TYPE_F64, true);
}
vm_tb_func_write(
state,
Expand Down Expand Up @@ -895,7 +884,6 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
};

TB_FunctionPrototype *call_proto = tb_prototype_create(state->module, VM_TB_CC, nargs, call_proto_params, 2, call_proto_rets, false);
#if VM_USE_CACHE
TB_Node *global_ptr = tb_inst_array_access(
state->fun,
vm_tb_ptr_name(state, "<code_cache>", cache),
Expand Down Expand Up @@ -1038,80 +1026,6 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
}

tb_inst_set_control(state->fun, after);
#else

TB_Node *rblock_call_table = vm_tb_ptr_name(state, "<call_table>", branch.call_table);
TB_Node *rblock_ref = tb_inst_array_access(
state->fun,
rblock_call_table,
block_num,
sizeof(vm_rblock_t *)
);
TB_Node *rblock = tb_inst_load(state->fun, TB_TYPE_PTR, rblock_ref, 1, false);

TB_PrototypeParam comp_params[1] = {
{TB_TYPE_PTR},
};

TB_PrototypeParam comp_ret[1] = {
{TB_TYPE_PTR},
};

TB_FunctionPrototype *comp_proto = tb_prototype_create(state->module, VM_TB_CC, 1, comp_params, 1, comp_ret, false);

for (size_t i = 0; i < state->blocks->len; i++) {
vm_rblock_t *rblock = branch.call_table[i];
if (rblock == NULL) {
continue;
}
rblock->state = state;
}

TB_Node *call_func = vm_tb_inst_call(
state,
comp_proto,
tb_inst_get_symbol_address(state->fun, state->vm_tb_rfunc_comp),
1,
&rblock
)
.single;

TB_Node **call_args = vm_malloc(sizeof(TB_Node *) * nargs);
call_args[0] = vm_tb_bitcast_to_value(state, closure);
for (size_t arg = 1; branch.args[arg].type != VM_ARG_NONE; arg++) {
call_args[arg] = vm_tb_bitcast_to_value(state, vm_tb_func_read_arg(state, regs, branch.args[arg]));
}

TB_Node **got = vm_tb_inst_call(
state,
call_proto,
call_func,
nargs,
call_args
)
.multiple;

vm_free(call_args);

tb_inst_store(
state->fun,
VM_TB_TYPE_VALUE,
val_val,
got[0],
8,
false
);

tb_inst_store(
state->fun,
TB_TYPE_I32,
val_tag,
got[1],
4,
false
);

#endif

val_val = tb_inst_load(
state->fun,
Expand Down Expand Up @@ -1286,7 +1200,6 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b

vm_free(next_params);

#if VM_USE_CACHE
void **mem = vm_malloc(sizeof(void *) * VM_TAG_MAX);

memset(mem, 0, sizeof(void *) * VM_TAG_MAX);
Expand Down Expand Up @@ -1424,73 +1337,6 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
);
}
}
#else
TB_PrototypeParam comp_params[1] = {
{TB_TYPE_PTR},
};

TB_PrototypeParam comp_ret[1] = {
{TB_TYPE_PTR},
};

TB_FunctionPrototype *comp_proto = tb_prototype_create(state->module, VM_TB_CC, 1, comp_params, 1, comp_ret, false);

for (size_t i = 1; i < VM_TAG_MAX; i++) {
branch.rtargets[i]->state = state;
}

TB_Node *comp_args[1];
comp_args[0] = tb_inst_load(
state->fun,
TB_TYPE_PTR,
tb_inst_array_access(
state->fun,
vm_tb_ptr_name(state, "<rtargets>", &block->branch.rtargets[0]),
val_tag,
sizeof(vm_rblock_t *)
),
1,
false
);

TB_MultiOutput new_func_multi = vm_tb_inst_call(
state,
comp_proto,
tb_inst_get_symbol_address(state->fun, state->vm_tb_rfunc_comp),
1,
comp_args
);

TB_Node **next_args = vm_malloc(sizeof(TB_Node *) * next_nargs);
for (size_t argno = 0; argno < next_nargs; argno++) {
vm_arg_t arg = branch.targets[0]->args[argno];
if (arg.type == VM_ARG_REG && arg.reg == branch.out.reg) {
next_args[argno] = val_val;
} else {
next_args[argno] = vm_tb_bitcast_to_value(state, vm_tb_func_read_arg(state, regs, arg));
}
}

if (VM_NO_TAILCALL) {
TB_MultiOutput out = vm_tb_inst_call(
state,
next_proto,
new_func_multi.single,
next_nargs,
next_args
);

tb_inst_ret(state->fun, 2, out.multiple);
} else {
tb_inst_tailcall(
state->fun,
next_proto,
new_func_multi.single,
next_nargs,
next_args
);
}
#endif

break;
}
Expand Down
8 changes: 0 additions & 8 deletions vm/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
#define VM_NO_TAILCALL 0
#define VM_FORMAT_FLOAT "%.14g"

#if defined(EMSCRIPTEN)
#undef VM_NO_TAILCALL
#define VM_NO_TAILCALL 1
#define VM_USE_CACHE 0
#else
#define VM_USE_CACHE 1
#endif

struct vm_config_t;
typedef struct vm_config_t vm_config_t;

Expand Down
2 changes: 1 addition & 1 deletion web/empty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

cd $(dirname "$0")

emcc src/empty/empty.c -o src/empty/empty.js -O3 -flto -s EXPORT_ES6=1 -s EXPORTED_RUNTIME_METHODS=FS,PROXYFS,ERRNO_CODES,allocateUTF8 -s FORCE_FILESYSTEM=1 -s ALLOW_MEMORY_GROWTH=1 --no-entry -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$ERRNO_CODES' -s EXPORTED_FUNCTIONS=_main,_free,_malloc -s --js-library=src/empty/fsroot.js -lproxyfs.js
emcc src/empty/empty.c -o src/empty/empty.js -O3 -flto -s ENVIRONMENT=web,worker -s SINGLE_FILE=1 -s EXPORT_ES6=1 -s EXPORTED_RUNTIME_METHODS=FS,PROXYFS,ERRNO_CODES,allocateUTF8 -s FORCE_FILESYSTEM=1 -s ALLOW_MEMORY_GROWTH=1 --no-entry -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$ERRNO_CODES' -s EXPORTED_FUNCTIONS=_main,_free,_malloc -s --js-library=src/empty/fsroot.js -lproxyfs.js
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"worker-loader": "^3.0.8"
},
"scripts": {
"build": "sh empty.sh && npx webpack",
"serve": "sh empty.sh && npx webpack serve"
"build": "npx webpack",
"serve": "webpack serve"
},
"type": "module"
}
1 change: 0 additions & 1 deletion web/src/empty/empty.c

This file was deleted.

16 changes: 0 additions & 16 deletions web/src/empty/empty.js

This file was deleted.

Binary file removed web/src/empty/empty.wasm
Binary file not shown.
63 changes: 0 additions & 63 deletions web/src/empty/fsroot.js

This file was deleted.

3 changes: 0 additions & 3 deletions web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
</head>

<body>
<link rel="prefetch" as="wasm-package" href="wasm/minivm.wasm">
<link rel="prefetch" as="wasm-package" href="wasm/wasm-package.wasm">
<link rel="prefetch" as="wasm-package" href="wasm/empty.wasm">
<script type="module" src="minivm.js"></script>
</body>

Expand Down
32 changes: 14 additions & 18 deletions web/src/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@

import './app/global.css';
// import {lua} from './lib/spawn.js';
// import {load} from 'fengari-web';
import App from './app/App.svelte';

document.addEventListener('DOMContentLoaded', () => {
new App({
target: document.body,
});
new App({
target: document.body,
});

// const fengari = (str) => {
// load(str)();
// };
// window.fengari = fengari;

// const minivm = (str) => {
// lua(str);
// };
import {lua} from './lib/spawn.js';
const minivm = (str) => {
lua(str);
};

// window.minivm = minivm;
// window.fengari = fengari;
// window.bench = (func, ...args) => {
// console.time(func.name);
// const ret = func(...args);
// console.timeEnd(func.name);
// return ret;
// };
// console.log('window.{minvim, fengari, time} available');
window.minivm = minivm;
window.bench = (func, ...args) => {
console.time(func.name);
const ret = func(...args);
console.timeEnd(func.name);
return ret;
};
2 changes: 1 addition & 1 deletion web/src/lib/comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let comps = 0;
export const comp = (cBuf) => {
comps += 1;
emception.fileSystem.writeFile(`/working/in${comps}.c`, cBuf);
const result1 = emception.runx(`/usr/bin/clang -O2 -c ${flags1} /working/in${comps}.c -o /working/mid${comps}.o`);
const result1 = emception.runx(`/usr/bin/clang -O1 -c ${flags1} /working/in${comps}.c -o /working/mid${comps}.o`);
if (result1.returncode !== 0) {
console.error(`clang exited with code ${result1.returncode}`);
}
Expand Down
4 changes: 0 additions & 4 deletions web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ export default {
// new CompressionPlugin({
// exclude: /\.br$/,
// }),
new webpack.NormalModuleReplacementPlugin(
/brotli\.m?js$/,
fileURLToPath(new URL('./src/empty/empty.js', import.meta.url)),
),
],
devServer: {
headers: {
Expand Down

0 comments on commit cc4ecd3

Please sign in to comment.