How to use @glimmer/opcode-compiler - 10 common examples

To help you get started, we’ve selected a few @glimmer/opcode-compiler 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 / integration-tests / lib / modes / jit / registry.ts View on Github external
): Option {
    let definitionHandle = this.lookupComponentHandle(name, referrer);

    if (definitionHandle === null) {
      return null;
    }

    let templateHandle = this.lookup('template-source', name, null);

    if (templateHandle === null) {
      throw new Error('BUG: missing dynamic layout');
    }

    // TODO: This whole thing probably should have a more first-class
    // structure.
    let template = unwrapTemplate(
      this.customCompilableTemplate(templateHandle, name, source => {
        let factory = createTemplate(source);
        return factory.create();
      })
    );

    return {
      handle: definitionHandle,
      capabilities: this.getCapabilities(definitionHandle),
      compilable: template.asWrappedLayout(),
    };

    // let handle = this.resolver.lookupComponentHandle(name, referrer);

    // if (handle === null) {
    //   return null;
github bakerac4 / glimmer-native / src / glimmer / context.ts View on Github external
export function Compilable(source: any) {
    // console.log('In Compilable: ' + source);
    const precompiled = precompile(source);
    // console.log('Precompiled');
    const component = Component(precompiled);
    // console.log(`Compiled Component: ${component}`);
    return component;
}
github bakerac4 / glimmer-native / dist / src / glimmer / context.js View on Github external
static lookupComponent(name) {
        // console.log(`lookupComponent: ${name}`);
        let component = ResolverDelegate.components[name];
        if (component === null) {
            return null;
        }
        // console.log(`component found: ${component}`);
        //source should now be compiled
        let { handle, source, capabilities } = component;
        return {
            handle,
            source,
            compilable: Component(source),
            capabilities
        };
    }
    static lookupModifier(name) {
github bakerac4 / glimmer-native / src / glimmer / context.ts View on Github external
static lookupComponent(name: any) {
        // console.log(`lookupComponent: ${name}`);
        let component = ResolverDelegate.components[name];
        if (component === null) {
            return null;
        }
        // console.log(`component found: ${component}`);
        //source should now be compiled
        let { handle, source, capabilities } = component;
        return {
            handle,
            source,
            compilable: Component(source),
            capabilities
        };
    }
github bakerac4 / glimmer-native / dist / src / glimmer / context.js View on Github external
export function Compilable(source) {
    // console.log('In Compilable: ' + source);
    const precompiled = precompile(source);
    // console.log('Precompiled');
    const component = Component(precompiled);
    // console.log(`Compiled Component: ${component}`);
    return component;
}
export class ResolverDelegate {
github glimmerjs / glimmer-vm / packages / @glimmer / runtime / lib / compiled / opcodes / partial.ts View on Github external
}

      if (evalScope) {
        for (let i = 0; i < partialSymbols.length; i++) {
          let name = partialSymbols[i];
          let symbol = i + 1;
          let value = evalScope[name];

          if (value !== undefined) partialScope.bind(symbol, value);
        }
      }

      partialScope.bindPartialMap(locals);

      vm.pushFrame(); // sp += 2
      vm.call(unwrapHandle(vmHandle!));
    }
  },
  'jit'
github bakerac4 / glimmer-native / dist / index.js View on Github external
const resolverDelegate = new ResolverDelegate();
        const resolver = new Resolver();
        Application.resolver = resolver;
        Application.resolverDelegate = resolverDelegate;
        //Order here is important due to handle's being generated by plugin
        this.parseTemplates(appFolder);
        // this.parseComponents(appFolder);
        this.registerState(components);
        setupGlimmer(resolverDelegate, resolver);
        this.registerHelpers(helpers);
        //-----------------------------------------------------------------
        Application.document = new DocumentNode();
        Application.rootFrame = createElement('Frame');
        Application.rootFrame.setAttribute('id', 'root');
        Application.document.appendChild(Application.rootFrame);
        Application.context = Context(GlimmerResolverDelegate);
    }
    static renderPage(name, containerElement, nextSibling = null, state) {
github bakerac4 / glimmer-native / index.ts View on Github external
const resolverDelegate = new ResolverDelegate();
        const resolver = new Resolver();
        Application.resolver = resolver;
        Application.resolverDelegate = resolverDelegate;
        //Order here is important due to handle's being generated by plugin
        this.parseTemplates(appFolder);
        // this.parseComponents(appFolder);
        this.registerState(components);
        setupGlimmer(resolverDelegate, resolver);
        this.registerHelpers(helpers);
        //-----------------------------------------------------------------
        Application.document = new DocumentNode();
        Application.rootFrame = createElement('Frame') as FrameElement;
        Application.rootFrame.setAttribute('id', 'root');
        Application.document.appendChild(Application.rootFrame);
        Application.context = Context(GlimmerResolverDelegate);
    }
github glimmerjs / glimmer-vm / packages / @glimmer / bundle-compiler / lib / bundle-compiler.ts View on Github external
let vmHandle:
      | number
      | { handle: number; errors: EncoderError[] }
      | undefined = this.compilerModuleLocatorResolver().getHandleByLocator(locator);
    if (vmHandle !== undefined) return vmHandle;

    // It's an error to try to compile a template that wasn't first added to the
    // bundle via the add() or addCompilableTemplate() methods.
    let compilableTemplate = expect(
      this.context.compilableTemplates.get(locator),
      `Can't compile a template that wasn't already added to the bundle (${locator.name} @ ${locator.module})`
    );

    // Compile the template, which writes opcodes to the heap and returns the VM
    // handle (the address of the compiled program in the heap).
    vmHandle = compilableTemplate.compile(syntaxCompilationContext(this.context, this.macros));

    if (typeof vmHandle !== 'number') {
      return vmHandle;
    }

    // Index the locator by VM handle and vice versa for easy lookups.
    this.compilerModuleLocatorResolver().setHandleByLocator(locator, vmHandle);

    return vmHandle;
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / compile.ts View on Github external
export function preprocess(
  template: string,
  meta?: AnnotatedModuleLocator
): Template {
  let wrapper = JSON.parse(rawPrecompile(template));
  let factory = templateFactory(wrapper);
  return factory.create(meta || DEFAULT_TEST_META);
}