testing string debug

This commit is contained in:
Stewart Allen 2021-07-11 12:41:24 -04:00
commit aea377a0fa
3 changed files with 24 additions and 6 deletions

View file

@ -152,6 +152,16 @@ if (!self.window) (function() {
console.log('diff',{p1:p1.points, p2:p2.points, d1:d1[0].points, d2:d2[0].points});
let o1 = geo.wasm.js.offset([p1], 1, 0);
console.log('offs',{o1:o1[0].points});
wasm.test_string(5);
}
function readString(pos, len) {
let view = new DataReader(geo.wasm.heap, pos);
let out = [];
while (len-- > 0) {
out.push(String.fromCharCode(view.readU8()));
}
return out.join('');
}
function enable() {
@ -165,7 +175,7 @@ if (!self.window) (function() {
env: {
polygon: (a,b) => { console.log('polygon',a,b) },
point: (a,b) => { console.log('point',a,b) },
abc: (a,b,c) => { console.log('abc',a,b,c) }
ostr: (len, ptr) => { console.log('ostr', readString(ptr, len)) }
},
wasi_snapshot_preview1: {
args_get: (count,bufsize) => { return 0 },
@ -188,7 +198,8 @@ if (!self.window) (function() {
memmax: exports.memory.buffer.byteLength,
malloc: exports.mem_get,
free: exports.mem_clr,
set_debug: exports.set_debug
set_debug: exports.set_debug,
test_string: exports.test_string
};
wasm.shared = wasm.malloc(1024 * 1024 * 30),
wasm.fn = {

View file

@ -16,7 +16,7 @@ Uint8 debug = 0;
extern "C" {
extern void polygon(Uint32 points, Uint32 inners);
extern void point(Uint32 x, Uint32 y);
extern void abc(Uint32 a, Uint32 b, Uint32 c);
extern void ostr(Uint32 len, std::string str);
}
struct length16 {
@ -55,12 +55,10 @@ Uint32 readPoly(Path &path, Uint32 pos) {
Uint32 readPolys(Paths &paths, Uint32 pos, Uint32 count) {
Uint32 poly = 0;
// if (debug) abc(poly, count, pos);
while (count > 0) {
pos = readPoly(paths[poly++], pos);
count--;
}
// if (debug) abc(poly, count, pos);
return pos;
}
@ -193,3 +191,12 @@ __attribute__ ((export_name("set_debug")))
void set_debug(Uint8 value) {
debug = value;
}
__attribute__ ((export_name("test_string")))
void test_string(Uint8 value) {
// Creating a string from const char*
std::string str1 = "hello";
//std::string str1 = std::format("{} {}", "hello", value);
ostr(str1.length(), str1);
}

View file

@ -4,7 +4,7 @@ kiri-sla.wasm: kiri-sla.c
emcc --no-entry -o kiri-sla.wasm kiri-sla.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
kiri-geo.wasm: kiri-geo.cpp
emcc --no-entry -o kiri-geo.wasm clipper.cpp kiri-geo.cpp -Oz -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s TOTAL_MEMORY=40mb
emcc --no-entry -o kiri-geo.wasm clipper.cpp kiri-geo.cpp -Oz -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s TOTAL_MEMORY=40mb -std=c++20
kiri-ani.wasm: kiri-ani.c
emcc --no-entry -o kiri-ani.wasm kiri-ani.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0