Skip to content

Commit

Permalink
Remove register indirection
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Nov 3, 2024
1 parent 4c2520d commit 74a32c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
7 changes: 4 additions & 3 deletions packages/@glimmer/runtime/lib/vm/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { unwrap } from '@glimmer/debug-util';
import { createDebugAliasRef, UNDEFINED_REFERENCE, valueForRef } from '@glimmer/reference';
import { dict, EMPTY_STRING_ARRAY, emptyArray, enumerate } from '@glimmer/util';
import { CONSTANT_TAG } from '@glimmer/validator';
import { $sp } from '@glimmer/vm';

import type { EvaluationStack } from './stack';

Expand All @@ -43,7 +44,7 @@ export class VMArgumentsImpl implements VMArguments {
public blocks = new BlockArgumentsImpl();

empty(stack: EvaluationStack): this {
let base = stack.$sp + 1;
let base = stack.registers[$sp] + 1;

this.named.empty(stack, base);
this.positional.empty(stack, base);
Expand Down Expand Up @@ -71,7 +72,7 @@ export class VMArgumentsImpl implements VMArguments {

let named = this.named;
let namedCount = names.length;
let namedBase = stack.$sp - namedCount + 1;
let namedBase = stack.registers[$sp] - namedCount + 1;

named.setup(stack, namedBase, namedCount, names, atNames);

Expand Down Expand Up @@ -112,7 +113,7 @@ export class VMArgumentsImpl implements VMArguments {

positional.base += offset;
named.base += offset;
stack.$sp += offset;
stack.registers[$sp] += offset;
}
}

Expand Down
38 changes: 13 additions & 25 deletions packages/@glimmer/runtime/lib/vm/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { LowLevelRegisters } from './low-level';
import { initializeRegistersWithSP } from './low-level';

export interface EvaluationStack {
$sp: number;
readonly registers: LowLevelRegisters;

push(value: unknown): void;
dup(position?: number): void;
Expand Down Expand Up @@ -35,59 +35,47 @@ export default class EvaluationStackImpl implements EvaluationStack {
return stack;
}

readonly #registers: LowLevelRegisters;
readonly registers: LowLevelRegisters;

// fp -> sp
constructor(
private stack: unknown[] = [],
registers: LowLevelRegisters
) {
this.#registers = registers;
this.registers = registers;

if (LOCAL_DEBUG) {
Object.seal(this);
}
}

get registers(): LowLevelRegisters {
return this.#registers;
}

get $sp(): number {
return this.#registers[$sp];
}

set $sp(sp: number) {
this.#registers[$sp] = sp;
}

push(value: unknown): void {
this.stack[++this.$sp] = value;
this.stack[++this.registers[$sp]] = value;
}

dup(position = this.$sp): void {
this.stack[++this.$sp] = this.stack[position];
dup(position = this.registers[$sp]): void {
this.stack[++this.registers[$sp]] = this.stack[position];
}

copy(from: number, to: number): void {
this.stack[to] = this.stack[from];
}

pop<T>(n = 1): T {
let top = this.stack[this.$sp] as T;
this.$sp -= n;
let top = this.stack[this.registers[$sp]] as T;
this.registers[$sp] -= n;
return top;
}

peek<T>(offset = 0): T {
return this.stack[this.$sp - offset] as T;
return this.stack[this.registers[$sp] - offset] as T;
}

get<T>(offset: number, base = this.#registers[$fp]): T {
get<T>(offset: number, base = this.registers[$fp]): T {
return this.stack[base + offset] as T;
}

set(value: unknown, offset: number, base = this.#registers[$fp]) {
set(value: unknown, offset: number, base = this.registers[$fp]) {
this.stack[base + offset] = value;
}

Expand All @@ -96,7 +84,7 @@ export default class EvaluationStackImpl implements EvaluationStack {
}

capture(items: number): unknown[] {
let end = this.$sp + 1;
let end = this.registers[$sp] + 1;
let start = end - items;
return this.stack.slice(start, end);
}
Expand All @@ -106,6 +94,6 @@ export default class EvaluationStackImpl implements EvaluationStack {
}

toArray() {
return this.stack.slice(this.#registers[$fp], this.#registers[$sp] + 1);
return this.stack.slice(this.registers[$fp], this.registers[$sp] + 1);
}
}

0 comments on commit 74a32c5

Please sign in to comment.