feat(web)!: use the WASM module in the bindings, and not the other way around
Parser is no longer the default export, but you *must* call `Parser.init()` before doing anything still
This commit is contained in:
parent
b1e39d2dba
commit
be7716dfa7
29 changed files with 613 additions and 662 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Edit, INTERNAL, Point, Range, SIZE_OF_INT, SIZE_OF_NODE, SIZE_OF_POINT } from "./constants";
|
||||
import { Edit, INTERNAL, Point, Range, SIZE_OF_INT, SIZE_OF_NODE, SIZE_OF_POINT, C } from "./constants";
|
||||
import { Node } from "./node";
|
||||
import { Tree } from "./tree";
|
||||
import { Query } from "./query";
|
||||
|
|
@ -7,7 +7,7 @@ import { TRANSFER_BUFFER } from "./parser";
|
|||
|
||||
export function unmarshalCaptures(query: Query, tree: Tree, address: number, result: {name: string, node: Node}[]) {
|
||||
for (let i = 0, n = result.length; i < n; i++) {
|
||||
const captureIndex = getValue(address, 'i32');
|
||||
const captureIndex = C.getValue(address, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
const node = unmarshalNode(tree, address)!;
|
||||
address += SIZE_OF_NODE;
|
||||
|
|
@ -18,29 +18,29 @@ export function unmarshalCaptures(query: Query, tree: Tree, address: number, res
|
|||
|
||||
export function marshalNode(node: Node) {
|
||||
let address = TRANSFER_BUFFER;
|
||||
setValue(address, node.id, 'i32');
|
||||
C.setValue(address, node.id, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
setValue(address, node.startIndex, 'i32');
|
||||
C.setValue(address, node.startIndex, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
setValue(address, node.startPosition.row, 'i32');
|
||||
C.setValue(address, node.startPosition.row, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
setValue(address, node.startPosition.column, 'i32');
|
||||
C.setValue(address, node.startPosition.column, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
setValue(address, node[0], 'i32');
|
||||
C.setValue(address, node[0], 'i32');
|
||||
}
|
||||
|
||||
export function unmarshalNode(tree: Tree, address = TRANSFER_BUFFER): Node | null {
|
||||
const id = getValue(address, 'i32');
|
||||
const id = C.getValue(address, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
if (id === 0) return null;
|
||||
|
||||
const index = getValue(address, 'i32');
|
||||
const index = C.getValue(address, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
const row = getValue(address, 'i32');
|
||||
const row = C.getValue(address, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
const column = getValue(address, 'i32');
|
||||
const column = C.getValue(address, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
const other = getValue(address, 'i32');
|
||||
const other = C.getValue(address, 'i32');
|
||||
|
||||
const result = new Node(INTERNAL, {
|
||||
id,
|
||||
|
|
@ -54,28 +54,28 @@ export function unmarshalNode(tree: Tree, address = TRANSFER_BUFFER): Node | nul
|
|||
}
|
||||
|
||||
export function marshalTreeCursor(cursor: TreeCursor, address = TRANSFER_BUFFER) {
|
||||
setValue(address + 0 * SIZE_OF_INT, cursor[0], 'i32');
|
||||
setValue(address + 1 * SIZE_OF_INT, cursor[1], 'i32');
|
||||
setValue(address + 2 * SIZE_OF_INT, cursor[2], 'i32');
|
||||
setValue(address + 3 * SIZE_OF_INT, cursor[3], 'i32');
|
||||
C.setValue(address + 0 * SIZE_OF_INT, cursor[0], 'i32');
|
||||
C.setValue(address + 1 * SIZE_OF_INT, cursor[1], 'i32');
|
||||
C.setValue(address + 2 * SIZE_OF_INT, cursor[2], 'i32');
|
||||
C.setValue(address + 3 * SIZE_OF_INT, cursor[3], 'i32');
|
||||
}
|
||||
|
||||
export function unmarshalTreeCursor(cursor: TreeCursor) {
|
||||
cursor[0] = getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, 'i32');
|
||||
cursor[1] = getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, 'i32');
|
||||
cursor[2] = getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
|
||||
cursor[3] = getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, 'i32');
|
||||
cursor[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, 'i32');
|
||||
cursor[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, 'i32');
|
||||
cursor[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
|
||||
cursor[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, 'i32');
|
||||
}
|
||||
|
||||
export function marshalPoint(address: number, point: Point): void {
|
||||
setValue(address, point.row, 'i32');
|
||||
setValue(address + SIZE_OF_INT, point.column, 'i32');
|
||||
C.setValue(address, point.row, 'i32');
|
||||
C.setValue(address + SIZE_OF_INT, point.column, 'i32');
|
||||
}
|
||||
|
||||
export function unmarshalPoint(address: number): Point {
|
||||
const result = {
|
||||
row: getValue(address, 'i32') >>> 0,
|
||||
column: getValue(address + SIZE_OF_INT, 'i32') >>> 0,
|
||||
row: C.getValue(address, 'i32') >>> 0,
|
||||
column: C.getValue(address + SIZE_OF_INT, 'i32') >>> 0,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
|
@ -83,16 +83,16 @@ export function unmarshalPoint(address: number): Point {
|
|||
export function marshalRange(address: number, range: Range): void {
|
||||
marshalPoint(address, range.startPosition); address += SIZE_OF_POINT;
|
||||
marshalPoint(address, range.endPosition); address += SIZE_OF_POINT;
|
||||
setValue(address, range.startIndex, 'i32'); address += SIZE_OF_INT;
|
||||
setValue(address, range.endIndex, 'i32'); address += SIZE_OF_INT;
|
||||
C.setValue(address, range.startIndex, 'i32'); address += SIZE_OF_INT;
|
||||
C.setValue(address, range.endIndex, 'i32'); address += SIZE_OF_INT;
|
||||
}
|
||||
|
||||
export function unmarshalRange(address: number): Range {
|
||||
const result = {} as Range;
|
||||
result.startPosition = unmarshalPoint(address); address += SIZE_OF_POINT;
|
||||
result.endPosition = unmarshalPoint(address); address += SIZE_OF_POINT;
|
||||
result.startIndex = getValue(address, 'i32') >>> 0; address += SIZE_OF_INT;
|
||||
result.endIndex = getValue(address, 'i32') >>> 0;
|
||||
result.startIndex = C.getValue(address, 'i32') >>> 0; address += SIZE_OF_INT;
|
||||
result.endIndex = C.getValue(address, 'i32') >>> 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ export function marshalEdit(edit: Edit, address = TRANSFER_BUFFER) {
|
|||
marshalPoint(address, edit.startPosition); address += SIZE_OF_POINT;
|
||||
marshalPoint(address, edit.oldEndPosition); address += SIZE_OF_POINT;
|
||||
marshalPoint(address, edit.newEndPosition); address += SIZE_OF_POINT;
|
||||
setValue(address, edit.startIndex, 'i32'); address += SIZE_OF_INT;
|
||||
setValue(address, edit.oldEndIndex, 'i32'); address += SIZE_OF_INT;
|
||||
setValue(address, edit.newEndIndex, 'i32'); address += SIZE_OF_INT;
|
||||
C.setValue(address, edit.startIndex, 'i32'); address += SIZE_OF_INT;
|
||||
C.setValue(address, edit.oldEndIndex, 'i32'); address += SIZE_OF_INT;
|
||||
C.setValue(address, edit.newEndIndex, 'i32'); address += SIZE_OF_INT;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue