argv added by nikola on Tue Aug 3 19:03:18 2021

;;; These aren't exported so it's fine 
(define make-pointervec (foreign-lambda* c-pointer ((int s))
						  "C_return(malloc(sizeof(void *) * s));"))
(define free! (foreign-lambda* void ((c-pointer ptr)) "free(ptr);"))
(define set-ptr! (foreign-lambda* void ((c-pointer vec) (int i) (c-pointer it))
				   "((void**)vec)[i] = it;"))
(define get-ptr (foreign-lambda* c-pointer ((c-pointer vec) (int i))
				  "C_return(((void**)vec)[i]);"))
(define strdup (foreign-lambda* c-pointer ((c-string str))
				 


(define (tcc-run! s argl)
  (let ((argc (length argl))
		(run (foreign-lambda* int ((TCCState s) (int ac) (c-pointer av))
			   "C_return(tcc_run(s, ac, av));")))
	(if (> argc 0)
	  (let ((argv (make-pointervec argc))) ; TODO: PROVERITI NULL
		(let loop ((l argl) (i 0))
		  (when (< i argc)
			(set-ptr! argv i (strdup (car l)))
			(loop (cdr l) (add1 i))))
		(let ((ret (run s argc argv)))
		  (let loop ((i 0))
			(when (< i argc)
			  (free! (get-ptr argv i))
			  (loop (add1 i))))
		  (free! argv)
		  ret))
	  (run s 0 #f))))