Skip to content

Commit

Permalink
Fix data offset case
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Aug 12, 2024
1 parent 179e41b commit 740340a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const build = {

// (data (i32.const 0) "\aa" "\bb"?)
data([, offset, ...inits], ctx) {
// FIXME: first is mem index
if (offset[0] === 'offset') [, offset] = offset
ctx.data.push([0, ...iinit(offset, ctx), ...str(inits.map(i => i[0] === '"' ? i.slice(1, -1) : i).join(''))])
},

Expand All @@ -354,11 +354,11 @@ const build = {

// (i32.const 0) - instantiation time initializer
const iinit = ([op, literal], ctx) =>
op.startsWith('f32') ? [OP_F32_CONST, ...f32(literal), OP_END] :
op.startsWith('f64') ? [OP_F64_CONST, ...f64(literal), OP_END] :
op.startsWith('i32') ? [OP_I32_CONST, ...leb(literal[0] === '$' ? ctx.global[literal] : literal), OP_END] :
op.startsWith('i64') ? [OP_I64_CONST, ...bigleb(literal[0] === '$' ? ctx.global[literal] : literal), OP_END] :
err('Unknown init')
op === 'f32.const' ? [OP_F32_CONST, ...f32(literal), OP_END] :
op === 'f64.const' ? [OP_F64_CONST, ...f64(literal), OP_END] :
op === 'i32.const' ? [OP_I32_CONST, ...leb(literal[0] === '$' ? ctx.global[literal] : literal), OP_END] :
op === 'i64.const' ? [OP_I64_CONST, ...bigleb(literal[0] === '$' ? ctx.global[literal] : literal), OP_END] :
err(`Unknown init ${op} ${literal}`)

const escape = { n: 10, r: 13, t: 9, v: 1, '\\': 92 }

Expand Down
2 changes: 1 addition & 1 deletion test/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ t('case: data content', () => {
is(compile(parse(src)), wat2wasm(src).buffer)
})

t.todo('case: data offset', () => {
t('case: data offset', () => {
let src = `(data (offset (i32.const 65505)) "\\16\\17\\18\\19\\20\\21\\22\\23\\24\\25\\26\\27\\28\\29\\30\\31")`
is(compile(parse(src)), wat2wasm(src).buffer)
})
Expand Down

0 comments on commit 740340a

Please sign in to comment.