Skip to content

Commit

Permalink
Add fallback for AST interpreter
Browse files Browse the repository at this point in the history
so that if something can't be interpreted, it just uses the compiler
  • Loading branch information
Bike committed Apr 22, 2019
1 parent a2b3d47 commit df191d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
15 changes: 10 additions & 5 deletions src/lisp/kernel/cleavir/ast-interpreter.lisp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(defpackage #:interpret-ast
(:use #:cl)
(:export #:interpret)
(:shadow #:variable)
;; FIXME: lose this asap
(:export #:*system*))
(:export #:cannot-interpret #:cannot-interpret-ast)
(:shadow #:variable))

;;;; NOTE: Some methods in this file must be compiled with cleavir,
;;;; as they use cleavir special operators - metacircularity, eh?
Expand Down Expand Up @@ -50,20 +49,26 @@
;; Do actual work
(interpret-ast ast env)))

(define-condition cannot-interpret (error)
((ast :reader cannot-interpret-ast :initarg :ast))
(:report (lambda (condition stream)
(format stream "Interpreter not implemented for AST: ~a"
(cannot-interpret-ast condition)))))

;;; meat

(defgeneric interpret-ast (ast env))

(defmethod interpret-ast (ast env)
(declare (ignore env))
(error "AST interpreter not implemented for ~a" ast))
(error 'cannot-interpret :ast ast))

;;; distinguished only to make sure the input ast is correct
(defgeneric interpret-boolean (condition env))

(defmethod interpret-boolean (condition env)
(declare (ignore then else env))
(error "AST boolean interpreter not implemented for ~a" condition))
(error 'cannot-interpret :ast condition))

(defmethod interpret-ast ((ast cleavir-ast:immediate-ast) env)
(declare (ignore env))
Expand Down
7 changes: 6 additions & 1 deletion src/lisp/kernel/cleavir/setup.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ when this is t a lot of graphs will be generated.")
(cond (core:*use-interpreter-for-eval*
(core:interpret form (cleavir-env->interpreter env)))
(*use-ast-interpreter*
(ast-interpret-form form env))
(handler-case
(ast-interpret-form form env)
(interpret-ast:cannot-interpret (c)
(declare (ignore c))
;; If the AST interpreter doesn't work, fall back.
(cclasp-eval form env))))
(t
(cclasp-eval form env))))

Expand Down
21 changes: 0 additions & 21 deletions src/lisp/kernel/cmp/compile-file-parallel.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -370,27 +370,7 @@ Compile a lisp source file into an LLVM module."
(bformat t "conditions: %s%N" c)))
(compile-file-results output-path conditions))))))


(defun contains-defcallback-p (path)
(let ((data (with-open-file (stream path)
(let ((data (make-string (file-length stream))))
(read-sequence data stream)
data))))
(search "defcallback" data :test #'string-equal)))


(defvar *compile-file-parallel* nil)
#+(or)
(defun cl:compile-file (input-file &rest args)
"Ok, this is a horrible hack - if the file DOESN'T contain defcallback then compile-file-parallel it"
(if *compile-file-parallel*
(if (null (contains-defcallback-p input-file))
(apply #'compile-file-parallel input-file args)
(progn
(format t "!~%!~%!~% Falling back to compile-file-serial for ~s because it contains DEFCALLBACK~%!~%~~%"
input-file)
(apply #'compile-file-serial input-file args)))
(apply #'compile-file-serial input-file args)))

(defun cl:compile-file (input-file &rest args)
(if *compile-file-parallel*
Expand All @@ -399,5 +379,4 @@ Compile a lisp source file into an LLVM module."

(eval-when (:load-toplevel)
(setf *compile-file-parallel* t)
#-cst
(setf clasp-cleavir::*use-ast-interpreter* t))

0 comments on commit df191d3

Please # to comment.