conductor.js
function run (f, p) {
    // handle let/mask pairs
    const view = []
    let n = 0
    for (let frame of p.s.stack) {
      if (frame.let === null) {
        n++
      } else if (frame.let !== undefined) {
        if (n === 0) {
          view.push(frame)
        } else {
          n--
        }
      }
    }

    // update value of topmost matching symbol on stack if any
    function set (symbol, value) {
      const element = view.find(element => element.let !== undefined && element.let[symbol] !== undefined)
      if (element !== undefined) element.let[symbol] = JSON.parse(JSON.stringify(value))
    }

    // collapse stack for invocation
    const env = view.reduceRight((acc, cur) => cur.let ? Object.assign(acc, cur.let) : acc, {})
    let main = '(function(){try{const require=arguments[2];'
    for (const name in env) main += `var ${name}=arguments[1]['${name}'];`
    main += `return eval((function(){return(${f})})())(arguments[0])}finally{`
    for (const name in env) main += `arguments[1]['${name}']=${name};`
    main += '}})'
    try {
      return (1, eval)(main)(p.params, env, require)
    } finally {
      for (const name in env) set(name, env[name])
    }
  }
function run (f, p) {
    // handle let/mask pairs
    const view = []
    let n = 0
    for (let frame of p.s.stack) {
      if (frame.let === null) {
        n++
      } else if (frame.let !== undefined) {
        if (n === 0) {
          view.push(frame)
        } else {
          n--
        }
      }
    }

    // update value of topmost matching symbol on stack if any
    function set (symbol, value) {
      const element = view.find(element => element.let !== undefined && element.let[symbol] !== undefined)
      if (element !== undefined) element.let[symbol] = JSON.parse(JSON.stringify(value))
    }

    // collapse stack for invocation
    const env = view.reduceRight((acc, cur) => cur.let ? Object.assign(acc, cur.let) : acc, {})
    let main = '(function(){try{const require=arguments[2];'
    for (const name in env) main += `var ${name}=arguments[1]['${name}'];`
    main += `return eval((function(){return(${f})})())(arguments[0])}finally{`
    for (const name in env) main += `arguments[1]['${name}']=${name};`
    main += '}})'
    try {
      return (1, eval)(main)(p.params, env, require)
    } finally {
      for (const name in env) set(name, env[name])
    }
  }
function run ( f , p ) { // handle let/mask pairs const view = [ ] let n = 0 for ( let frame of p . s . stack ) { if ( frame . let === null ) { n ++ } else if ( frame . let !== undefined ) { if ( n === 0 ) { view . push ( frame ) } else { n -- } } } // update value of topmost matching symbol on stack if any function set ( symbol , value ) { const element = view . find ( element => element . let !== undefined && element . let [ symbol ] !== undefined ) if ( element !== undefined ) element . let [ symbol ] = JSON . parse ( JSON . stringify ( value ) ) } // collapse stack for invocation const env = view . reduceRight ( ( acc , cur ) => cur . let ? Object . assign ( acc , cur . let ) : acc , { } ) let main = '(function(){try{const require=arguments[2];' for ( const name in env ) main += ` ${ name } ${ name } ` main += ` ${ f } ` for ( const name in env ) main += ` ${ name } ${ name } ` main += '}})' try { return ( 1 , eval ) ( main ) ( p . params , env , require ) } finally { for ( const name in env ) set ( name , env [ name ] ) } }
run function f on current stack
run function f on current stack