main.ss
#lang scheme/base

(require (for-syntax "make.ss")
         (prefix-in ext: "extension.ss"))

(define (encode i)
  (cond
    ((string? i) (string->bytes/utf-8 i))
    ((bytes? i) i)
    ((path? i) (encode (path->string i)))
    ((number? i) (encode (number->string i)))))

(define (final-exec args)
  (apply ext:exec (map encode args)))

(define (with-exec proc)
  (let ((args #f))
    (let/ec avoid
      (let/ec escape
        (proc
         (λ (exe . new-args)
           (define path (find-executable-path exe))
           (when (not path)
             (error "Could not find an executable for" exe))
           (set! args (list* path exe new-args))
           (escape)))
        (avoid))
      (when args
        (final-exec args)))))

(provide with-exec)