Skip to content

Commit 459057c

Browse files
committed
Remove prealloc stuff
1 parent 220b246 commit 459057c

2 files changed

Lines changed: 2 additions & 63 deletions

File tree

packages/wasm/runtime/ohmRuntime.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ let rightmostFailurePos: i32 = 0;
5050
let sp: usize = 0;
5151
let bindings: Array<i32> = new Array<i32>();
5252

53-
// Preallocated CST nodes for some common cases.
54-
let preallocAlnum1: i32 = 0;
55-
let preallocAny1: i32 = 0;
56-
let preallocLetter1: i32 = 0;
57-
let preallocLower1: i32 = 0;
58-
let preallocUpper1: i32 = 0;
59-
6053
@inline function max<T>(a: T, b: T): T {
6154
return a > b ? a : b;
6255
}
@@ -137,11 +130,6 @@ function resetParsingState(): void {
137130

138131
bindings = new Array<i32>();
139132
memory.fill(MEMO_START_OFFSET, 0, MEMO_COL_SIZE_BYTES * MAX_INPUT_LEN_BYTES);
140-
141-
// spaces = 2, alnum = 3, any = 4, letter = 5, lower = 6, upper = 7
142-
newTerminalNode(0, 1);
143-
preallocAlnum1 = newNonterminalNode(0, 1, 3, 0, -1);
144-
bindings.length = 0;
145133
}
146134

147135
export function match(startRuleId: i32): ApplyResult {
@@ -301,7 +289,3 @@ export function getCstRoot(): usize {
301289
// TODO: Figure out how to handle this w.r.t. leading and trailing space.
302290
return bindings[0];
303291
}
304-
305-
export function pushPreallocAlnum(): i32 {
306-
return bindings.push(preallocAlnum1);
307-
}

packages/wasm/src/index.js

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,6 @@ export class Compiler {
790790
// (global $~lib/rt/stub/offset (mut i32) (i32.const 0))
791791
// (global $~lib/native/ASC_RUNTIME i32 (i32.const 0))
792792
// (global $runtime/ohmRuntime/bindings (mut i32) (i32.const 0))
793-
// (global $runtime/ohmRuntime/preallocAlnum1 (mut i32) (i32.const 0))
794-
// (global $runtime/ohmRuntime/preallocAny1 (mut i32) (i32.const 0))
795-
// (global $runtime/ohmRuntime/preallocLetter1 (mut i32) (i32.const 0))
796-
// (global $runtime/ohmRuntime/preallocLower1 (mut i32) (i32.const 0))
797-
// (global $runtime/ohmRuntime/preallocUpper1 (mut i32) (i32.const 0))
798793
// (global $~lib/memory/__heap_base i32 (i32.const 1179884))
799794
asm.addGlobal('pos', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
800795
asm.addGlobal('rightmostFailurePos', w.valtype.i32, w.mut.var, () => asm.i32Const(-1));
@@ -806,11 +801,6 @@ export class Compiler {
806801
asm.addGlobal('__offset', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
807802
asm.addGlobal('__ASC_RUNTIME', w.valtype.i32, w.mut.const, () => asm.i32Const(0));
808803
asm.addGlobal('bindings', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
809-
asm.addGlobal('preallocAlnum1', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
810-
asm.addGlobal('preallocAny1', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
811-
asm.addGlobal('preallocLetter1', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
812-
asm.addGlobal('preallocLower1', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
813-
asm.addGlobal('preallocUpper1', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
814804
asm.addGlobal('__heap_base', w.valtype.i32, w.mut.var, () => asm.i32Const(67240172));
815805

816806
// Reserve a fixed number of imports for debug labels.
@@ -833,14 +823,8 @@ export class Compiler {
833823
const {grammar} = this;
834824

835825
const lookUpRule = name => {
836-
const isSyntactic = isSyntacticRule(name);
837-
if (name in grammar.rules) {
838-
return {...grammar.rules[name], isSyntactic};
839-
}
840-
// if (grammar.superGrammar) {
841-
// console.log('going to supergrammar');
842-
// return lookUpRule(name, grammar.superGrammar);
843-
// }
826+
assert(name in grammar.rules);
827+
return {...grammar.rules[name], isSyntactic: isSyntacticRule(name)};
844828
};
845829

846830
// Begin with all the rules in the grammar + all "special" rules.
@@ -1666,35 +1650,6 @@ export class Compiler {
16661650
asm.incPos();
16671651
});
16681652
}
1669-
1670-
emitSingleCharFastPath(ruleName) {
1671-
const {asm} = this;
1672-
this.maybeEmitSpaceSkipping();
1673-
1674-
const caseCb = (i, depth) => {
1675-
const c = String.fromCharCode(i);
1676-
if (
1677-
ruleName === 'alnum' &&
1678-
(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9'))
1679-
) {
1680-
asm.callPrebuiltFunc('pushPreallocAlnum');
1681-
// asm.newTerminalNodeWithSavedPos();
1682-
asm.localSet('ret');
1683-
asm.break(depth + 1);
1684-
} else {
1685-
asm.setRet(0);
1686-
asm.break(depth + 1);
1687-
}
1688-
};
1689-
asm.emit('fastpath');
1690-
asm.switch(
1691-
w.blocktype.empty,
1692-
() => asm.nextCharCode(),
1693-
128,
1694-
caseCb,
1695-
() => {},
1696-
);
1697-
}
16981653
}
16991654

17001655
// Memory layout:

0 commit comments

Comments
 (0)