How to use @glimmer/vm - 10 common examples

To help you get started, we’ve selected a few @glimmer/vm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
ReferenceCache,
  Revision,
  Tag
} from '@glimmer/reference';
import { initializeGuid, assert } from '@glimmer/util';
import { expectStackChange, CheckNumber, check, CheckInstanceof, CheckOption, CheckBlockSymbolTable, CheckHandle, CheckPrimitive } from '@glimmer/debug';
import { stackAssert } from './assert';
import { APPEND_OPCODES, UpdatingOpcode } from '../../opcodes';
import { PrimitiveReference } from '../../references';
import { CompilableTemplate } from '../../syntax/interfaces';
import { VM, UpdatingVM } from '../../vm';
import { Arguments } from '../../vm/arguments';
import { LazyConstants, PrimitiveType } from "@glimmer/program";
import { CheckReference } from './-debug-strip';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope());

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope());

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope());

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope());

APPEND_OPCODES.add(Op.Constant, (vm: VM & { constants: LazyConstants }, { op1: other }) => {
  vm.stack.push(vm.constants.getOther(other));
});

APPEND_OPCODES.add(Op.Primitive, (vm, { op1: primitive }) => {
  let stack = vm.stack;
  let flag = primitive & 7; // 111
  let value = primitive >> 3;
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
import { PrimitiveReference } from '../../references';
import { CompilableTemplate } from '../../syntax/interfaces';
import { VM, UpdatingVM } from '../../vm';
import { Arguments } from '../../vm/arguments';
import { LazyConstants, PrimitiveType } from "@glimmer/program";
import { CheckReference } from './-debug-strip';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope());

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope());

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope());

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope());

APPEND_OPCODES.add(Op.Constant, (vm: VM & { constants: LazyConstants }, { op1: other }) => {
  vm.stack.push(vm.constants.getOther(other));
});

APPEND_OPCODES.add(Op.Primitive, (vm, { op1: primitive }) => {
  let stack = vm.stack;
  let flag = primitive & 7; // 111
  let value = primitive >> 3;

  switch (flag) {
    case PrimitiveType.NUMBER:
      stack.push(value);
      break;
    case PrimitiveType.FLOAT:
      stack.push(vm.constants.getFloat(value));
      break;
    case PrimitiveType.STRING:
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
import { PrimitiveReference } from '../../references';
import { UpdatingVM } from '../../vm';
import { LazyConstants, PrimitiveType } from '@glimmer/program';
import { CheckReference, CheckScope } from './-debug-strip';
import { CONSTANTS } from '../../symbols';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(
  Op.Constant,
  (vm, { op1: other }) => {
    vm.stack.push((vm[CONSTANTS] as LazyConstants).getOther(other));
  },
  OpcodeKind.Mut
);

APPEND_OPCODES.add(
  Op.Primitive,
  (vm, { op1: primitive }) => {
    let stack = vm.stack;
    let flag = primitive & 7; // 111
    let value = primitive >> 3;

    switch (flag) {
      case PrimitiveType.NUMBER:
        stack.push(value);
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
let stack = vm.stack;
    let block = stack.pop | 0>();

    if (block) {
      stack.pushSmi(block.compile() as Recast);
    } else {
      stack.pushNull();
    }

    check(vm.stack.peek(), CheckOption(CheckNumber));
  },
  OpcodeKind.Mut
);

APPEND_OPCODES.add(
  Op.InvokeYield,
  vm => {
    let { stack } = vm;

    let handle = check(stack.pop(), CheckOption(CheckHandle));
    let scope = check(stack.pop(), CheckOption(CheckScope));
    let table = check(stack.pop(), CheckOption(CheckBlockSymbolTable));

    assert(
      table === null || (table && typeof table === 'object' && Array.isArray(table.parameters)),
      stackAssert('Option', table)
    );

    let args = check(stack.pop(), CheckInstanceof(ReadonlyArguments));

    if (table === null) {
      // To balance the pop{Frame,Scope}
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
let stack = vm.stack;
  let block = stack.pop | 0>();
  stack.push(block ? block.compile() : null);

  check(vm.stack.peek(), CheckOption(CheckNumber));
});

APPEND_OPCODES.add(Op.InvokeVirtual, vm => {
  vm.call(check(vm.stack.pop(), CheckHandle));
});

APPEND_OPCODES.add(Op.InvokeStatic, (vm, { op1: handle }) => {
  vm.call(handle as Recast);
});

APPEND_OPCODES.add(Op.InvokeYield, vm => {
  let { stack } = vm;

  let handle = check(stack.pop(), CheckOption(CheckHandle));
  let table = check(stack.pop(), CheckOption(CheckBlockSymbolTable));

  assert(table === null || (table && typeof table === 'object' && Array.isArray(table.parameters)), stackAssert('Option', table));

  let args = check(stack.pop(), CheckInstanceof(Arguments));

  if (table === null) {

    // To balance the pop{Frame,Scope}
    vm.pushFrame();
    let blockScope = vm.scope().getCallerScope()!;
    vm.pushScope(blockScope);
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
import { stackAssert } from './assert';
import { APPEND_OPCODES, UpdatingOpcode } from '../../opcodes';
import { PrimitiveReference } from '../../references';
import { CompilableTemplate } from '../../syntax/interfaces';
import { VM, UpdatingVM } from '../../vm';
import { Arguments } from '../../vm/arguments';
import { LazyConstants, PrimitiveType } from "@glimmer/program";
import { CheckReference } from './-debug-strip';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope());

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope());

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope());

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope());

APPEND_OPCODES.add(Op.Constant, (vm: VM & { constants: LazyConstants }, { op1: other }) => {
  vm.stack.push(vm.constants.getOther(other));
});

APPEND_OPCODES.add(Op.Primitive, (vm, { op1: primitive }) => {
  let stack = vm.stack;
  let flag = primitive & 7; // 111
  let value = primitive >> 3;

  switch (flag) {
    case PrimitiveType.NUMBER:
      stack.push(value);
      break;
    case PrimitiveType.FLOAT:
      stack.push(vm.constants.getFloat(value));
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
} from '@glimmer/debug';
import { stackAssert } from './assert';
import { APPEND_OPCODES, UpdatingOpcode, OpcodeKind } from '../../opcodes';
import { PrimitiveReference } from '../../references';
import { UpdatingVM } from '../../vm';
import { LazyConstants, PrimitiveType } from '@glimmer/program';
import { CheckReference, CheckScope } from './-debug-strip';
import { CONSTANTS } from '../../symbols';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(
  Op.Constant,
  (vm, { op1: other }) => {
    vm.stack.push((vm[CONSTANTS] as LazyConstants).getOther(other));
  },
  OpcodeKind.Mut
);

APPEND_OPCODES.add(
  Op.Primitive,
  (vm, { op1: primitive }) => {
    let stack = vm.stack;
    let flag = primitive & 7; // 111
    let value = primitive >> 3;
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
Tag
} from '@glimmer/reference';
import { initializeGuid, assert } from '@glimmer/util';
import { expectStackChange, CheckNumber, check, CheckInstanceof, CheckOption, CheckBlockSymbolTable, CheckHandle, CheckPrimitive } from '@glimmer/debug';
import { stackAssert } from './assert';
import { APPEND_OPCODES, UpdatingOpcode } from '../../opcodes';
import { PrimitiveReference } from '../../references';
import { CompilableTemplate } from '../../syntax/interfaces';
import { VM, UpdatingVM } from '../../vm';
import { Arguments } from '../../vm/arguments';
import { LazyConstants, PrimitiveType } from "@glimmer/program";
import { CheckReference } from './-debug-strip';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope());

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope());

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope());

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope());

APPEND_OPCODES.add(Op.Constant, (vm: VM & { constants: LazyConstants }, { op1: other }) => {
  vm.stack.push(vm.constants.getOther(other));
});

APPEND_OPCODES.add(Op.Primitive, (vm, { op1: primitive }) => {
  let stack = vm.stack;
  let flag = primitive & 7; // 111
  let value = primitive >> 3;

  switch (flag) {
    case PrimitiveType.NUMBER:
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
import { LazyConstants, PrimitiveType } from "@glimmer/program";
import { CheckReference } from './-debug-strip';

APPEND_OPCODES.add(Op.ChildScope, vm => vm.pushChildScope());

APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope());

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope());

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope());

APPEND_OPCODES.add(Op.Constant, (vm: VM & { constants: LazyConstants }, { op1: other }) => {
  vm.stack.push(vm.constants.getOther(other));
});

APPEND_OPCODES.add(Op.Primitive, (vm, { op1: primitive }) => {
  let stack = vm.stack;
  let flag = primitive & 7; // 111
  let value = primitive >> 3;

  switch (flag) {
    case PrimitiveType.NUMBER:
      stack.push(value);
      break;
    case PrimitiveType.FLOAT:
      stack.push(vm.constants.getFloat(value));
      break;
    case PrimitiveType.STRING:
      stack.push(vm.constants.getString(value));
      break;
    case PrimitiveType.BOOLEAN_OR_VOID:
      switch (value) {
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / vm.ts View on Github external
APPEND_OPCODES.add(Op.PopScope, vm => vm.popScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PushDynamicScope, vm => vm.pushDynamicScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(Op.PopDynamicScope, vm => vm.popDynamicScope(), OpcodeKind.Mut);

APPEND_OPCODES.add(
  Op.Constant,
  (vm, { op1: other }) => {
    vm.stack.push((vm[CONSTANTS] as LazyConstants).getOther(other));
  },
  OpcodeKind.Mut
);

APPEND_OPCODES.add(
  Op.Primitive,
  (vm, { op1: primitive }) => {
    let stack = vm.stack;
    let flag = primitive & 7; // 111
    let value = primitive >> 3;

    switch (flag) {
      case PrimitiveType.NUMBER:
        stack.push(value);
        break;
      case PrimitiveType.FLOAT:
        stack.push(vm[CONSTANTS].getNumber(value));
        break;
      case PrimitiveType.STRING:
        stack.push(vm[CONSTANTS].getString(value));
        break;
      case PrimitiveType.BOOLEAN_OR_VOID: