UNPKG

ember-legacy-class-transform

Version:
63 lines 2.41 kB
import { APPEND_OPCODES } from '../../opcodes'; import { FALSE_REFERENCE, TRUE_REFERENCE } from '../../references'; import { ConcatReference } from '../expressions/concat'; APPEND_OPCODES.add(1 /* Helper */, (vm, { op1: _helper }) => { let stack = vm.stack; let helper = vm.constants.getFunction(_helper); let args = stack.pop(); let value = helper(vm, args); args.clear(); vm.stack.push(value); }); APPEND_OPCODES.add(2 /* Function */, (vm, { op1: _function }) => { let func = vm.constants.getFunction(_function); vm.stack.push(func(vm)); }); APPEND_OPCODES.add(5 /* GetVariable */, (vm, { op1: symbol }) => { let expr = vm.referenceForSymbol(symbol); vm.stack.push(expr); }); APPEND_OPCODES.add(4 /* SetVariable */, (vm, { op1: symbol }) => { let expr = vm.stack.pop(); vm.scope().bindSymbol(symbol, expr); }); APPEND_OPCODES.add(70 /* ResolveMaybeLocal */, (vm, { op1: _name }) => { let name = vm.constants.getString(_name); let locals = vm.scope().getPartialMap(); let ref = locals[name]; if (ref === undefined) { ref = vm.getSelf().get(name); } vm.stack.push(ref); }); APPEND_OPCODES.add(19 /* RootScope */, (vm, { op1: symbols, op2: bindCallerScope }) => { vm.pushRootScope(symbols, !!bindCallerScope); }); APPEND_OPCODES.add(6 /* GetProperty */, (vm, { op1: _key }) => { let key = vm.constants.getString(_key); let expr = vm.stack.pop(); vm.stack.push(expr.get(key)); }); APPEND_OPCODES.add(7 /* PushBlock */, (vm, { op1: _block }) => { let block = _block ? vm.constants.getBlock(_block) : null; vm.stack.push(block); }); APPEND_OPCODES.add(8 /* GetBlock */, (vm, { op1: _block }) => { vm.stack.push(vm.scope().getBlock(_block)); }); APPEND_OPCODES.add(9 /* HasBlock */, (vm, { op1: _block }) => { let hasBlock = !!vm.scope().getBlock(_block); vm.stack.push(hasBlock ? TRUE_REFERENCE : FALSE_REFERENCE); }); APPEND_OPCODES.add(10 /* HasBlockParams */, (vm, { op1: _block }) => { let block = vm.scope().getBlock(_block); let hasBlockParams = block && block.symbolTable.parameters.length; vm.stack.push(hasBlockParams ? TRUE_REFERENCE : FALSE_REFERENCE); }); APPEND_OPCODES.add(11 /* Concat */, (vm, { op1: count }) => { let out = []; for (let i = count; i > 0; i--) { out.push(vm.stack.pop()); } vm.stack.push(new ConcatReference(out.reverse())); });