2019-07-07 07:23:10 +00:00
|
|
|
;;; comp.el --- compilation of Lisp code into native code -*- lexical-binding: t -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
;; Keywords: lisp
|
|
|
|
;; Package: emacs
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2019-07-13 13:48:02 +00:00
|
|
|
;;; Commentary:
|
2019-07-14 12:39:29 +00:00
|
|
|
;; This code is an attempt to make the pig fly.
|
|
|
|
;; Or, to put it another way to make a Carrera out of a turbocharged VW Bug.
|
2019-07-13 13:48:02 +00:00
|
|
|
|
2019-07-07 07:23:10 +00:00
|
|
|
;;; Code:
|
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(require 'bytecomp)
|
2019-07-08 09:37:17 +00:00
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'cl-extra)
|
|
|
|
(require 'subr-x)
|
2019-07-07 07:23:10 +00:00
|
|
|
|
|
|
|
(defgroup comp nil
|
|
|
|
"Emacs Lisp native compiler."
|
|
|
|
:group 'lisp)
|
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(defconst comp-debug t)
|
2019-07-07 07:23:10 +00:00
|
|
|
|
2019-07-14 22:58:03 +00:00
|
|
|
;; FIXME these has to be removed
|
2019-07-13 15:24:44 +00:00
|
|
|
(defvar comp-speed 2)
|
2019-07-14 22:58:03 +00:00
|
|
|
(defvar byte-compile-lap-output)
|
2019-07-13 15:24:44 +00:00
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(defconst comp-passes '(comp-recuparate-lap
|
|
|
|
comp-limplify)
|
|
|
|
"Passes to be executed in order.")
|
|
|
|
|
2019-07-07 19:49:11 +00:00
|
|
|
(defconst comp-known-ret-types '((Fcons . cons)))
|
|
|
|
|
2019-07-08 05:17:28 +00:00
|
|
|
(defconst comp-mostly-pure-funcs
|
|
|
|
'(% * + - / /= 1+ 1- < <= = > >= cons list % concat logand logcount logior
|
|
|
|
lognot logxor regexp-opt regexp-quote string-to-char string-to-syntax
|
|
|
|
symbol-name)
|
|
|
|
"Functions on witch we do constant propagation."
|
|
|
|
;; Is it acceptable to move into the compile time functions that are
|
|
|
|
;; allocating memory? (these are technically not side effect free)
|
|
|
|
)
|
|
|
|
|
2019-07-14 07:53:06 +00:00
|
|
|
(eval-when-compile
|
|
|
|
(defconst comp-op-stack-info
|
|
|
|
(cl-loop with h = (make-hash-table)
|
|
|
|
for k across byte-code-vector
|
|
|
|
for v across byte-stack+-info
|
|
|
|
when k
|
|
|
|
do (puthash k v h)
|
|
|
|
finally return h)
|
|
|
|
"Hash table lap-op -> stack adjustment."))
|
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(cl-defstruct comp-args
|
2019-07-08 13:29:32 +00:00
|
|
|
(min nil :type number
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Minimum number of arguments allowed.")
|
2019-07-08 13:29:32 +00:00
|
|
|
(max nil
|
|
|
|
:documentation "Maximum number of arguments allowed
|
2019-07-14 18:54:53 +00:00
|
|
|
To be used when ncall-conv is nil..")
|
2019-07-08 13:29:32 +00:00
|
|
|
(ncall-conv nil :type boolean
|
|
|
|
:documentation "If t the signature is:
|
2019-07-14 18:54:53 +00:00
|
|
|
(ptrdiff_t nargs, Lisp_Object *args)."))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-14 15:21:34 +00:00
|
|
|
(cl-defstruct (comp-block (:copier nil))
|
|
|
|
"A basic block."
|
|
|
|
(sp nil
|
2019-07-14 16:36:57 +00:00
|
|
|
:documentation "When non nil indicates its the sp value while entering
|
2019-07-14 18:54:53 +00:00
|
|
|
into it.")
|
2019-07-14 15:21:34 +00:00
|
|
|
(closed nil :type 'boolean
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "If the block was already closed."))
|
2019-07-14 15:21:34 +00:00
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(cl-defstruct (comp-func (:copier nil))
|
|
|
|
"Internal rapresentation for a function."
|
|
|
|
(symbol-name nil
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Function symbol's name.")
|
2019-07-08 10:11:34 +00:00
|
|
|
(c-func-name nil :type 'string
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "The function name in the native world.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(func nil
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Original form.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(byte-func nil
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Byte compiled version.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(ir nil
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Current intermediate rappresentation.")
|
2019-07-08 05:56:37 +00:00
|
|
|
(args nil :type 'comp-args)
|
2019-07-08 13:29:32 +00:00
|
|
|
(frame-size nil :type 'number)
|
2019-07-14 15:21:34 +00:00
|
|
|
(blocks (make-hash-table) :type 'hash-table
|
|
|
|
:documentation "Key is the basic block symbol value is a comp-block
|
2019-07-14 18:54:53 +00:00
|
|
|
structure.")
|
2019-07-14 12:39:29 +00:00
|
|
|
(lap-block (make-hash-table :test #'equal) :type 'hash-table
|
|
|
|
:documentation "Key value to convert from LAP label number to
|
2019-07-14 18:54:53 +00:00
|
|
|
LIMPLE basic block.")
|
2019-07-08 05:56:37 +00:00
|
|
|
(limple-cnt -1 :type 'number
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Counter to create ssa limple vars."))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-08 05:56:37 +00:00
|
|
|
(cl-defstruct (comp-mvar (:copier nil) (:constructor make--comp-mvar))
|
2019-07-07 19:49:11 +00:00
|
|
|
"A meta-variable being a slot in the meta-stack."
|
2019-07-09 20:28:29 +00:00
|
|
|
(id nil :type number
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "SSA number.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(slot nil :type fixnum
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Slot position.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(const-vld nil
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Valid signal for the following slot.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(constant nil
|
|
|
|
:documentation "When const-vld non nil this is used for constant
|
2019-07-14 18:54:53 +00:00
|
|
|
propagation.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(type nil
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "When non nil is used for type propagation."))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-14 15:33:18 +00:00
|
|
|
(cl-defstruct (comp-limplify (:copier nil))
|
2019-07-14 18:54:53 +00:00
|
|
|
"Support structure used during limplification."
|
2019-07-07 10:30:03 +00:00
|
|
|
(sp 0 :type 'fixnum
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Current stack pointer while walking LAP.")
|
2019-07-07 10:30:03 +00:00
|
|
|
(frame nil :type 'vector
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Meta-stack used to flat LAP.")
|
2019-07-14 16:36:57 +00:00
|
|
|
(block-name nil :type 'symbol
|
2019-07-14 18:54:53 +00:00
|
|
|
:documentation "Current basic block name."))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-14 18:54:53 +00:00
|
|
|
(defun comp-new-frame (size)
|
2019-07-09 16:09:47 +00:00
|
|
|
"Return a clean frame of meta variables of size SIZE."
|
|
|
|
(let ((v (make-vector size nil)))
|
|
|
|
(cl-loop for i below size
|
|
|
|
do (aset v i (make-comp-mvar :slot i)))
|
|
|
|
v))
|
|
|
|
|
2019-07-08 10:11:34 +00:00
|
|
|
(defun comp-c-func-name (symbol-function)
|
|
|
|
"Given SYMBOL-FUNCTION return a name suitable for the native code."
|
|
|
|
;; Unfortunatelly not all symbol names are valid as C function names...
|
2019-07-10 19:29:32 +00:00
|
|
|
;; Nassi's algorithm.
|
2019-07-08 10:11:34 +00:00
|
|
|
(let* ((orig-name (symbol-name symbol-function))
|
|
|
|
(crypted (cl-loop with str = (make-string (* 2 (length orig-name)) 0)
|
|
|
|
for j from 0 by 2
|
|
|
|
for i across orig-name
|
|
|
|
for byte = (format "%x" i)
|
|
|
|
do (aset str j (aref byte 0))
|
|
|
|
do (aset str (1+ j) (aref byte 1))
|
|
|
|
finally return str))
|
|
|
|
(human-readable (replace-regexp-in-string
|
2019-07-10 19:29:32 +00:00
|
|
|
"-" "_" orig-name))
|
|
|
|
(human-readable (replace-regexp-in-string
|
2019-07-14 19:10:56 +00:00
|
|
|
(rx (not (any "0-9a-z_"))) "" human-readable)))
|
2019-07-08 10:11:34 +00:00
|
|
|
(concat "F" crypted "_" human-readable)))
|
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(defun comp-decrypt-lambda-list (x)
|
|
|
|
"Decript lambda list X."
|
2019-07-08 13:29:32 +00:00
|
|
|
(let ((rest (not (= (logand x 128) 0)))
|
|
|
|
(mandatory (logand x 127))
|
|
|
|
(nonrest (ash x -8)))
|
|
|
|
(if (and (null rest)
|
|
|
|
(< nonrest 9)) ;; SUBR_MAX_ARGS
|
|
|
|
(make-comp-args :min mandatory
|
|
|
|
:max nonrest)
|
|
|
|
(make-comp-args :min mandatory
|
|
|
|
:ncall-conv t))))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-08 05:56:37 +00:00
|
|
|
(defun comp-recuparate-lap (func)
|
|
|
|
"Byte compile and recuparate LAP rapresentation for FUNC."
|
2019-07-07 10:30:03 +00:00
|
|
|
;; FIXME block timers here, otherwise we could spill the wrong LAP.
|
2019-07-08 05:56:37 +00:00
|
|
|
(setf (comp-func-byte-func func)
|
|
|
|
(byte-compile (comp-func-symbol-name func)))
|
2019-07-07 10:30:03 +00:00
|
|
|
(when comp-debug
|
|
|
|
(cl-prettyprint byte-compile-lap-output))
|
2019-07-09 20:28:29 +00:00
|
|
|
(let ((lambda-list (aref (comp-func-byte-func func) 0)))
|
|
|
|
(if (fixnump lambda-list)
|
|
|
|
(setf (comp-func-args func)
|
|
|
|
(comp-decrypt-lambda-list (aref (comp-func-byte-func func) 0)))
|
|
|
|
(error "Can't native compile a non lexical scoped function")))
|
2019-07-08 05:56:37 +00:00
|
|
|
(setf (comp-func-ir func) byte-compile-lap-output)
|
2019-07-08 13:29:32 +00:00
|
|
|
(setf (comp-func-frame-size func) (aref (comp-func-byte-func func) 3))
|
2019-07-08 05:56:37 +00:00
|
|
|
func)
|
|
|
|
|
2019-07-08 09:37:17 +00:00
|
|
|
(declare-function comp-init-ctxt "comp.c")
|
|
|
|
(declare-function comp-release-ctxt "comp.c")
|
|
|
|
(declare-function comp-add-func-to-ctxt "comp.c")
|
|
|
|
(declare-function comp-compile-and-load-ctxt "comp.c")
|
|
|
|
|
2019-07-08 05:56:37 +00:00
|
|
|
;; (defun comp-opt-call (inst)
|
|
|
|
;; "Optimize if possible a side-effect-free call in INST."
|
|
|
|
;; (cl-destructuring-bind (_ f &rest args) inst
|
|
|
|
;; (when (and (member f comp-mostly-pure-funcs)
|
|
|
|
;; (cl-every #'identity (mapcar #'comp-mvar-const-vld args)))
|
|
|
|
;; (apply f (mapcar #'comp-mvar-constant args)))))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-08 07:06:58 +00:00
|
|
|
;; Special vars used during limplifications
|
2019-07-14 18:54:53 +00:00
|
|
|
(defvar comp-pass)
|
2019-07-08 07:06:58 +00:00
|
|
|
(defvar comp-limple)
|
|
|
|
(defvar comp-func)
|
|
|
|
|
2019-07-08 07:29:13 +00:00
|
|
|
(cl-defun make-comp-mvar (&key slot const-vld constant type)
|
2019-07-09 20:28:29 +00:00
|
|
|
(make--comp-mvar :id (cl-incf (comp-func-limple-cnt comp-func))
|
2019-07-08 07:29:13 +00:00
|
|
|
:slot slot :const-vld const-vld :constant constant
|
|
|
|
:type type))
|
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(defmacro comp-sp ()
|
|
|
|
"Current stack pointer."
|
2019-07-14 18:54:53 +00:00
|
|
|
'(comp-limplify-sp comp-pass))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-14 07:53:06 +00:00
|
|
|
(defmacro comp-with-sp (sp &rest body)
|
|
|
|
"Execute BODY setting the stack pointer to SP.
|
2019-07-14 12:39:29 +00:00
|
|
|
Restore the original value afterwards."
|
2019-07-14 07:53:06 +00:00
|
|
|
(declare (debug (form body))
|
2019-07-14 12:39:29 +00:00
|
|
|
(indent defun))
|
|
|
|
(let ((sym (gensym)))
|
|
|
|
`(let ((,sym (comp-sp)))
|
|
|
|
(setf (comp-sp) ,sp)
|
|
|
|
(progn ,@body)
|
|
|
|
(setf (comp-sp) ,sym))))
|
2019-07-14 07:53:06 +00:00
|
|
|
|
2019-07-07 16:42:55 +00:00
|
|
|
(defmacro comp-slot-n (n)
|
|
|
|
"Slot N into the meta-stack."
|
2019-07-14 07:53:06 +00:00
|
|
|
(declare (debug (form)))
|
2019-07-14 18:54:53 +00:00
|
|
|
`(aref (comp-limplify-frame comp-pass) ,n))
|
2019-07-07 16:42:55 +00:00
|
|
|
|
2019-07-07 10:30:03 +00:00
|
|
|
(defmacro comp-slot ()
|
|
|
|
"Current slot into the meta-stack pointed by sp."
|
2019-07-07 16:42:55 +00:00
|
|
|
'(comp-slot-n (comp-sp)))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-07 19:49:11 +00:00
|
|
|
(defmacro comp-slot-next ()
|
|
|
|
"Slot into the meta-stack pointed by sp + 1."
|
|
|
|
'(comp-slot-n (1+ (comp-sp))))
|
|
|
|
|
2019-07-13 14:34:59 +00:00
|
|
|
(defun comp-emit (x)
|
|
|
|
"Emit X into current LIMPLE ir.."
|
|
|
|
(push x comp-limple))
|
|
|
|
|
|
|
|
(defun comp-emit-set-call (call)
|
2019-07-13 15:08:15 +00:00
|
|
|
"Emit CALL assigning the result the the current slot frame.
|
|
|
|
If the calle function is known to have a return type propagate it."
|
2019-07-13 09:33:15 +00:00
|
|
|
(cl-assert call)
|
2019-07-08 07:06:58 +00:00
|
|
|
(setf (comp-slot)
|
2019-07-08 07:29:13 +00:00
|
|
|
(make-comp-mvar :slot (comp-sp)
|
2019-07-13 15:08:15 +00:00
|
|
|
:type (when (> comp-speed 0)
|
|
|
|
(alist-get (cadr call)
|
|
|
|
comp-known-ret-types))))
|
2019-07-13 14:34:59 +00:00
|
|
|
(comp-emit (list 'set (comp-slot) call)))
|
2019-07-13 09:33:15 +00:00
|
|
|
|
2019-07-20 13:49:30 +00:00
|
|
|
(defmacro comp-emit-set-call-subr (subr-name sp-delta &optional c-fun-name)
|
2019-07-14 18:25:42 +00:00
|
|
|
"Emit a call for SUBR-NAME using C-FUN-NAME.
|
2019-07-20 13:49:30 +00:00
|
|
|
SP-DELTA is the stack adjustment.
|
|
|
|
If C-FUN-NAME is nil it will be guessed from SUBR-NAME."
|
2019-07-14 21:35:04 +00:00
|
|
|
(let ((subr (symbol-function subr-name))
|
2019-07-20 13:49:30 +00:00
|
|
|
(subr-str (symbol-name subr-name))
|
|
|
|
(nargs (1+ (- sp-delta))))
|
2019-07-14 21:35:04 +00:00
|
|
|
(cl-assert (subrp subr) nil
|
|
|
|
"%s not a subr" subr-str)
|
|
|
|
(let* ((arity (subr-arity subr))
|
|
|
|
(minarg (car arity))
|
|
|
|
(maxarg (cdr arity)))
|
|
|
|
(unless c-fun-name
|
|
|
|
(setq c-fun-name
|
|
|
|
(intern (concat "F"
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"-" "_"
|
|
|
|
subr-str)))))
|
2019-07-20 13:49:30 +00:00
|
|
|
(cl-assert (not (eq maxarg 'unevalled)) nil
|
|
|
|
"%s contains unevalled arg" subr-name)
|
|
|
|
(if (eq maxarg 'many)
|
|
|
|
;; callref case.
|
|
|
|
`(comp-emit-set-call (list 'callref ',c-fun-name ,nargs (comp-sp)))
|
|
|
|
;; Normal call.
|
|
|
|
(cl-assert (and (>= maxarg nargs) (<= minarg nargs))
|
|
|
|
(nargs maxarg minarg)
|
|
|
|
"Incoherent stack adjustment %d, maxarg %d minarg %d")
|
|
|
|
`(let* ((c-fun-name ',c-fun-name)
|
|
|
|
(slots (cl-loop for i from 0 below ,maxarg
|
|
|
|
collect (comp-slot-n (+ i (comp-sp))))))
|
|
|
|
(comp-emit-set-call `(call ,c-fun-name ,@slots)))))))
|
2019-07-14 18:25:42 +00:00
|
|
|
|
2019-07-20 17:26:30 +00:00
|
|
|
(defun comp-copy-slot (src-n &optional dst-n)
|
|
|
|
"Set slot number DST-N to slot number SRC-N as source.
|
|
|
|
If DST-N is specified use it otherwise assume it to be the current slot."
|
|
|
|
(comp-with-sp (if dst-n dst-n (comp-sp))
|
|
|
|
(let ((src-slot (comp-slot-n src-n)))
|
|
|
|
(cl-assert src-slot)
|
|
|
|
;; FIXME id should encrease here.
|
|
|
|
(setf (comp-slot)
|
|
|
|
(copy-sequence src-slot))
|
|
|
|
(setf (comp-mvar-slot (comp-slot)) (comp-sp))
|
|
|
|
(comp-emit (list 'set (comp-slot) src-slot)))))
|
2019-07-08 07:06:58 +00:00
|
|
|
|
2019-07-10 16:55:19 +00:00
|
|
|
(defun comp-emit-annotation (str)
|
|
|
|
"Emit annotation STR."
|
2019-07-13 14:34:59 +00:00
|
|
|
(comp-emit `(comment ,str)))
|
2019-07-10 16:55:19 +00:00
|
|
|
|
2019-07-14 18:25:42 +00:00
|
|
|
(defun comp-emit-set-const (val)
|
2019-07-13 16:28:00 +00:00
|
|
|
"Set constant VAL to current slot."
|
2019-07-09 20:28:29 +00:00
|
|
|
(setf (comp-slot) (make-comp-mvar :slot (comp-sp)
|
2019-07-08 07:06:58 +00:00
|
|
|
:const-vld t
|
2019-07-09 20:28:29 +00:00
|
|
|
:constant val))
|
2019-07-13 14:34:59 +00:00
|
|
|
(comp-emit (list 'setimm (comp-slot) val)))
|
2019-07-08 15:04:33 +00:00
|
|
|
|
2019-07-14 16:36:57 +00:00
|
|
|
(defun comp-mark-block-closed ()
|
|
|
|
"Mark current basic block as closed."
|
2019-07-14 18:54:53 +00:00
|
|
|
(setf (comp-block-closed (gethash (comp-limplify-block-name comp-pass)
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-func-blocks comp-func)))
|
|
|
|
t))
|
|
|
|
|
|
|
|
(defun comp-emit-jump (target)
|
|
|
|
"Emit an unconditional branch to block TARGET."
|
|
|
|
(comp-emit (list 'jump target))
|
|
|
|
(comp-mark-block-closed))
|
|
|
|
|
2019-07-14 15:21:34 +00:00
|
|
|
(defun comp-emit-block (block-name)
|
|
|
|
"Emit basic block BLOCK-NAME."
|
2019-07-14 16:36:57 +00:00
|
|
|
(let ((blocks (comp-func-blocks comp-func)))
|
|
|
|
;; In case does not exist register it into comp-func-blocks.
|
|
|
|
(unless (gethash block-name blocks)
|
|
|
|
(puthash block-name
|
|
|
|
(make-comp-block :sp (comp-sp))
|
|
|
|
blocks))
|
|
|
|
;; If we are abandoning an non closed basic block close it with a fall
|
|
|
|
;; through.
|
|
|
|
(when (and (not (eq block-name 'entry))
|
2019-07-14 18:54:53 +00:00
|
|
|
(not (comp-block-closed (gethash (comp-limplify-block-name comp-pass)
|
2019-07-14 16:36:57 +00:00
|
|
|
blocks))))
|
|
|
|
(comp-emit-jump block-name))
|
|
|
|
;; Every new block we are forced to wipe out all the frame.
|
|
|
|
;; This will be optimized by proper flow analysis.
|
2019-07-14 18:54:53 +00:00
|
|
|
(setf (comp-limplify-frame comp-pass)
|
|
|
|
(comp-new-frame (comp-func-frame-size comp-func)))
|
2019-07-14 16:36:57 +00:00
|
|
|
;; If we are landing here form a recorded branch adjust sp accordingly.
|
|
|
|
(setf (comp-sp)
|
|
|
|
(comp-block-sp (gethash block-name blocks)))
|
|
|
|
(comp-emit `(block ,block-name))
|
2019-07-14 18:54:53 +00:00
|
|
|
(setf (comp-limplify-block-name comp-pass) block-name)))
|
2019-07-14 16:36:57 +00:00
|
|
|
|
2019-07-21 07:48:52 +00:00
|
|
|
(defun comp-emit-cond-jump (target-offset lap-label negated)
|
2019-07-14 16:36:57 +00:00
|
|
|
"Emit a conditional jump to LAP-LABEL.
|
2019-07-21 07:48:52 +00:00
|
|
|
TARGET-OFFSET is the positive offset on the SP when branching to the target
|
|
|
|
block.
|
2019-07-14 16:36:57 +00:00
|
|
|
If NEGATED non nil negate the test condition."
|
2019-07-21 07:48:52 +00:00
|
|
|
(let ((blocks (comp-func-blocks comp-func))
|
|
|
|
(bb (comp-new-block-sym))) ;; Fall through block
|
2019-07-14 16:36:57 +00:00
|
|
|
(puthash bb
|
2019-07-21 07:48:52 +00:00
|
|
|
(make-comp-block :sp (comp-sp))
|
2019-07-14 16:36:57 +00:00
|
|
|
blocks)
|
2019-07-21 07:48:52 +00:00
|
|
|
(let ((target (comp-lap-to-limple-bb lap-label)))
|
|
|
|
(comp-emit (if negated
|
|
|
|
(list 'cond-jump (comp-slot-next) target bb)
|
|
|
|
(list 'cond-jump (comp-slot-next) bb target)))
|
|
|
|
(puthash target
|
|
|
|
(make-comp-block :sp (+ target-offset (comp-sp)))
|
|
|
|
blocks)
|
|
|
|
(comp-mark-block-closed))
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit-block bb)))
|
2019-07-14 12:39:29 +00:00
|
|
|
|
2019-07-13 16:28:00 +00:00
|
|
|
(defun comp-stack-adjust (n)
|
|
|
|
"Move sp by N."
|
|
|
|
(cl-incf (comp-sp) n))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-08 07:15:09 +00:00
|
|
|
(defun comp-limplify-listn (n)
|
2019-07-08 07:29:13 +00:00
|
|
|
"Limplify list N."
|
2019-07-14 07:53:06 +00:00
|
|
|
(comp-with-sp (1- n)
|
2019-07-13 14:34:59 +00:00
|
|
|
(comp-emit-set-call `(call Fcons
|
2019-07-14 07:53:06 +00:00
|
|
|
,(comp-slot)
|
|
|
|
,(make-comp-mvar :const-vld t
|
|
|
|
:constant nil))))
|
|
|
|
(cl-loop for sp from (+ (comp-sp) n -2) downto (comp-sp)
|
|
|
|
do (comp-with-sp sp
|
|
|
|
(comp-emit-set-call `(call Fcons
|
|
|
|
,(comp-slot)
|
|
|
|
,(comp-slot-next))))))
|
|
|
|
|
2019-07-14 12:39:29 +00:00
|
|
|
(defun comp-new-block-sym ()
|
|
|
|
"Return a symbol naming the next new basic block."
|
2019-07-14 15:21:34 +00:00
|
|
|
(intern (format "bb_%s" (hash-table-count (comp-func-blocks comp-func)))))
|
2019-07-14 12:39:29 +00:00
|
|
|
|
|
|
|
(defun comp-lap-to-limple-bb (n)
|
|
|
|
"Given the LAP label N return the limple basic block."
|
|
|
|
(let ((hash (comp-func-lap-block comp-func)))
|
|
|
|
(if-let ((bb (gethash n hash)))
|
|
|
|
;; If was already created return it.
|
|
|
|
bb
|
|
|
|
(let ((name (comp-new-block-sym)))
|
|
|
|
(puthash n name hash)
|
|
|
|
name))))
|
|
|
|
|
2019-07-14 07:53:06 +00:00
|
|
|
(defmacro comp-op-case (&rest cases)
|
2019-07-14 18:25:42 +00:00
|
|
|
"Expand CASES into the corresponding pcase.
|
2019-07-14 19:02:01 +00:00
|
|
|
This is responsible for generating the proper stack adjustment when known and
|
|
|
|
the annotation emission."
|
2019-07-14 07:53:06 +00:00
|
|
|
(declare (debug (body))
|
|
|
|
(indent defun))
|
2019-07-20 14:44:40 +00:00
|
|
|
(cl-labels ((op-to-fun (x)
|
|
|
|
;; Given the LAP op strip "byte-" to have the subr name.
|
|
|
|
(intern (replace-regexp-in-string "byte-" "" x)))
|
|
|
|
(body-eff (body op-name sp-delta)
|
|
|
|
;; Given the original body BODY compute the effective one.
|
2019-07-20 15:35:57 +00:00
|
|
|
;; When BODY is auto guess function name form the LAP bytecode
|
|
|
|
;; name. Othewise expect lname fnname.
|
2019-07-20 14:44:40 +00:00
|
|
|
(pcase (car body)
|
|
|
|
('auto
|
|
|
|
(list `(comp-emit-set-call-subr
|
|
|
|
,(op-to-fun op-name)
|
|
|
|
,sp-delta)))
|
|
|
|
((pred symbolp)
|
|
|
|
(list `(comp-emit-set-call-subr
|
|
|
|
,(car body)
|
|
|
|
,sp-delta
|
|
|
|
,(cadr body))))
|
|
|
|
(_ body))))
|
2019-07-14 21:35:04 +00:00
|
|
|
`(pcase op
|
|
|
|
,@(cl-loop for (op . body) in cases
|
|
|
|
for sp-delta = (gethash op comp-op-stack-info)
|
|
|
|
for op-name = (symbol-name op)
|
|
|
|
if body
|
|
|
|
collect `(',op
|
2019-07-20 15:35:57 +00:00
|
|
|
;; Log all LAP ops except the TAG one.
|
2019-07-14 21:35:04 +00:00
|
|
|
,(unless (eq op 'TAG)
|
|
|
|
`(comp-emit-annotation
|
|
|
|
,(concat "LAP op " op-name)))
|
2019-07-20 15:35:57 +00:00
|
|
|
;; Emit the stack adjustment if present.
|
2019-07-20 13:49:30 +00:00
|
|
|
,(when (and sp-delta (not (eq 0 sp-delta)))
|
2019-07-14 21:35:04 +00:00
|
|
|
`(comp-stack-adjust ,sp-delta))
|
2019-07-20 14:44:40 +00:00
|
|
|
,@(body-eff body op-name sp-delta))
|
2019-07-14 21:35:04 +00:00
|
|
|
else
|
|
|
|
collect `(',op (error ,(concat "Unsupported LAP op "
|
|
|
|
op-name))))
|
|
|
|
(_ (error "Unexpected LAP op %s" (symbol-name op))))))
|
2019-07-08 07:15:09 +00:00
|
|
|
|
2019-07-08 07:06:58 +00:00
|
|
|
(defun comp-limplify-lap-inst (inst)
|
2019-07-08 07:29:13 +00:00
|
|
|
"Limplify LAP instruction INST accumulating in `comp-limple'."
|
2019-07-14 08:57:46 +00:00
|
|
|
(let ((op (car inst))
|
|
|
|
(arg (if (consp (cdr inst))
|
|
|
|
(cadr inst)
|
|
|
|
(cdr inst))))
|
2019-07-14 07:53:06 +00:00
|
|
|
(comp-op-case
|
2019-07-14 12:39:29 +00:00
|
|
|
(TAG
|
|
|
|
(comp-emit-block (comp-lap-to-limple-bb arg)))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-stack-ref
|
2019-07-20 17:26:30 +00:00
|
|
|
(comp-copy-slot (- (comp-sp) arg 1)))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-varref
|
2019-07-13 16:28:00 +00:00
|
|
|
(comp-emit-set-call `(call Fsymbol_value ,(make-comp-mvar
|
|
|
|
:const-vld t
|
2019-07-14 08:57:46 +00:00
|
|
|
:constant arg))))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-varset
|
2019-07-13 14:34:59 +00:00
|
|
|
(comp-emit `(call set_internal
|
2019-07-13 15:24:44 +00:00
|
|
|
,(make-comp-mvar :const-vld t
|
2019-07-14 08:57:46 +00:00
|
|
|
:constant arg)
|
2019-07-13 14:34:59 +00:00
|
|
|
,(comp-slot))))
|
2019-07-14 19:26:20 +00:00
|
|
|
(byte-varbind
|
|
|
|
(comp-emit `(call specbind
|
|
|
|
,(make-comp-mvar :const-vld t
|
|
|
|
:constant arg)
|
|
|
|
,(comp-slot-next))))
|
2019-07-14 09:15:18 +00:00
|
|
|
(byte-call
|
|
|
|
(comp-stack-adjust (- arg))
|
|
|
|
(comp-emit-set-call `(callref Ffuncall ,(1+ arg) ,(comp-sp))))
|
2019-07-14 19:26:20 +00:00
|
|
|
(byte-unbind
|
|
|
|
(comp-emit `(call unbind_to
|
|
|
|
,(make-comp-mvar :const-vld t
|
|
|
|
:constant arg)
|
|
|
|
,(make-comp-mvar :const-vld t
|
|
|
|
:constant nil))))
|
2019-07-21 09:38:26 +00:00
|
|
|
(byte-pophandler
|
|
|
|
(comp-emit '(pop-handler)))
|
|
|
|
(byte-pushconditioncase
|
|
|
|
(let ((blocks (comp-func-blocks comp-func))
|
|
|
|
(fall-bb (comp-new-block-sym))) ;; Fall through block
|
|
|
|
(puthash fall-bb
|
|
|
|
(make-comp-block :sp (comp-sp))
|
|
|
|
blocks)
|
|
|
|
(let ((target (comp-lap-to-limple-bb (cl-third inst)))
|
|
|
|
(handler-type (cdr (last inst))))
|
|
|
|
(comp-emit (list 'push-handler (comp-slot-next)
|
|
|
|
handler-type
|
|
|
|
target
|
|
|
|
fall-bb))
|
|
|
|
(puthash target
|
|
|
|
(make-comp-block :sp (comp-sp))
|
|
|
|
blocks)
|
|
|
|
(comp-mark-block-closed))
|
|
|
|
(comp-emit-block fall-bb)))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-pushcatch)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-nth auto)
|
|
|
|
(byte-symbolp auto)
|
|
|
|
(byte-consp auto)
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-stringp auto)
|
|
|
|
(byte-listp auto)
|
|
|
|
(byte-eq auto)
|
|
|
|
(byte-memq auto)
|
2019-07-20 15:35:57 +00:00
|
|
|
(byte-not null Fnull)
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-car auto)
|
|
|
|
(byte-cdr auto)
|
|
|
|
(byte-cons auto)
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-list1
|
|
|
|
(comp-limplify-listn 1))
|
|
|
|
(byte-list2
|
|
|
|
(comp-limplify-listn 2))
|
|
|
|
(byte-list3
|
|
|
|
(comp-limplify-listn 3))
|
|
|
|
(byte-list4
|
|
|
|
(comp-limplify-listn 4))
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-length auto)
|
|
|
|
(byte-aref auto)
|
|
|
|
(byte-aset auto)
|
|
|
|
(byte-symbol-value auto)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-symbol-function auto)
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-set auto)
|
|
|
|
(byte-fset auto)
|
|
|
|
(byte-get auto)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-substring auto)
|
2019-07-14 08:57:46 +00:00
|
|
|
(byte-concat2
|
|
|
|
(comp-emit-set-call `(callref Fconcat 2 ,(comp-sp))))
|
|
|
|
(byte-concat3
|
|
|
|
(comp-emit-set-call `(callref Fconcat 3 ,(comp-sp))))
|
|
|
|
(byte-concat4
|
|
|
|
(comp-emit-set-call `(callref Fconcat 4 ,(comp-sp))))
|
2019-07-20 15:35:57 +00:00
|
|
|
(byte-sub1 1- Fsub1)
|
|
|
|
(byte-add1 1+ Fadd1)
|
|
|
|
(byte-eqlsign = Feqlsign)
|
2019-07-20 15:22:13 +00:00
|
|
|
(byte-gtr > Fgtr)
|
|
|
|
(byte-lss < Flss)
|
|
|
|
(byte-leq <= Fleq)
|
|
|
|
(byte-geq >= Fgeq)
|
2019-07-20 15:35:57 +00:00
|
|
|
(byte-diff - Fminus)
|
|
|
|
(byte-negate - Fminus)
|
2019-07-20 15:22:13 +00:00
|
|
|
(byte-plus + Fplus)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-max auto)
|
|
|
|
(byte-min auto)
|
2019-07-20 15:22:13 +00:00
|
|
|
(byte-mult * Ftimes)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-point auto)
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-goto-char auto)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-insert auto)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-point-max auto)
|
|
|
|
(byte-point-min auto)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-char-after auto)
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-following-char auto)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-preceding-char auto)
|
|
|
|
(byte-current-column auto)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-indent-to auto)
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-scan-buffer-OBSOLETE)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-eolp auto)
|
|
|
|
(byte-eobp auto)
|
|
|
|
(byte-bolp auto)
|
|
|
|
(byte-bobp auto)
|
|
|
|
(byte-current-buffer auto)
|
|
|
|
(byte-set-buffer auto)
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-save-current-buffer)
|
|
|
|
(byte-set-mark-OBSOLETE)
|
|
|
|
(byte-interactive-p-OBSOLETE)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-forward-char auto)
|
|
|
|
(byte-forward-word auto)
|
|
|
|
(byte-skip-chars-forward auto)
|
|
|
|
(byte-skip-chars-backward auto)
|
|
|
|
(byte-forward-line auto)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-char-syntax auto)
|
|
|
|
(byte-buffer-substring auto)
|
|
|
|
(byte-delete-region auto)
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-narrow-to-region)
|
|
|
|
(byte-widen)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-end-of-line auto)
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-constant2)
|
2019-07-14 12:39:29 +00:00
|
|
|
(byte-goto
|
2019-07-20 17:56:54 +00:00
|
|
|
(comp-emit-jump (comp-lap-to-limple-bb (cl-third inst))))
|
2019-07-14 12:39:29 +00:00
|
|
|
(byte-goto-if-nil
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit-cond-jump 0 (cl-third inst) nil))
|
2019-07-14 12:39:29 +00:00
|
|
|
(byte-goto-if-not-nil
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit-cond-jump 0 (cl-third inst) t))
|
2019-07-14 12:39:29 +00:00
|
|
|
(byte-goto-if-nil-else-pop
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit-cond-jump 1 (cl-third inst) nil))
|
2019-07-14 12:39:29 +00:00
|
|
|
(byte-goto-if-not-nil-else-pop
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit-cond-jump 1 (cl-third inst) t))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-return
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit (list 'return (comp-slot-next)))
|
|
|
|
(comp-mark-block-closed))
|
2019-07-14 21:35:04 +00:00
|
|
|
(byte-discard 'pass)
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-dup
|
2019-07-20 17:26:30 +00:00
|
|
|
(comp-copy-slot (1- (comp-sp))))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-save-excursion)
|
|
|
|
(byte-save-window-excursion-OBSOLETE)
|
|
|
|
(byte-save-restriction)
|
|
|
|
(byte-catch)
|
|
|
|
(byte-unwind-protect)
|
|
|
|
(byte-condition-case)
|
|
|
|
(byte-temp-output-buffer-setup-OBSOLETE)
|
|
|
|
(byte-temp-output-buffer-show-OBSOLETE)
|
|
|
|
(byte-unbind-all)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-set-marker auto)
|
|
|
|
(byte-match-beginning auto)
|
|
|
|
(byte-match-end auto)
|
|
|
|
(byte-upcase auto)
|
|
|
|
(byte-downcase auto)
|
2019-07-20 15:35:57 +00:00
|
|
|
(byte-string= string-equal Fstring_equal)
|
|
|
|
(byte-string< string-lessp Fstring_lessp)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-equal auto)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-nthcdr auto)
|
|
|
|
(byte-elt auto)
|
|
|
|
(byte-member auto)
|
|
|
|
(byte-assq auto)
|
|
|
|
(byte-nreverse auto)
|
|
|
|
(byte-setcar auto)
|
|
|
|
(byte-setcdr auto)
|
2019-07-20 15:35:57 +00:00
|
|
|
(byte-car-safe auto)
|
|
|
|
(byte-cdr-safe auto)
|
2019-07-20 14:34:37 +00:00
|
|
|
(byte-nconc auto)
|
2019-07-20 15:35:57 +00:00
|
|
|
(byte-quo / Fquo)
|
|
|
|
(byte-rem % Frem)
|
2019-07-14 22:58:03 +00:00
|
|
|
(byte-numberp auto)
|
|
|
|
(byte-integerp auto)
|
2019-07-20 16:50:41 +00:00
|
|
|
(byte-listN
|
2019-07-20 17:26:30 +00:00
|
|
|
(comp-stack-adjust (- 1 arg))
|
2019-07-20 16:50:41 +00:00
|
|
|
(comp-emit-set-call `(callref Flist ,arg ,(comp-sp))))
|
2019-07-14 08:57:46 +00:00
|
|
|
(byte-concatN
|
2019-07-20 17:26:30 +00:00
|
|
|
(comp-stack-adjust (- 1 arg))
|
2019-07-14 08:57:46 +00:00
|
|
|
(comp-emit-set-call `(callref Fconcat ,arg ,(comp-sp))))
|
2019-07-20 16:50:41 +00:00
|
|
|
(byte-insertN
|
2019-07-20 17:26:30 +00:00
|
|
|
(comp-stack-adjust (- 1 arg))
|
2019-07-20 16:50:41 +00:00
|
|
|
(comp-emit-set-call `(callref Finsert ,arg ,(comp-sp))))
|
2019-07-20 17:26:30 +00:00
|
|
|
(byte-stack-set
|
|
|
|
(comp-with-sp (1+ (comp-sp))
|
|
|
|
(comp-copy-slot (comp-sp) (- (comp-sp) arg))))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-stack-set2)
|
2019-07-20 17:26:30 +00:00
|
|
|
(byte-discardN
|
|
|
|
(comp-stack-adjust (- arg)))
|
2019-07-14 07:53:06 +00:00
|
|
|
(byte-switch)
|
|
|
|
(byte-constant
|
2019-07-20 16:50:41 +00:00
|
|
|
(comp-emit-set-const arg))
|
|
|
|
(byte-discardN-preserve-tos
|
|
|
|
(comp-stack-adjust (- arg))
|
2019-07-20 17:26:30 +00:00
|
|
|
(comp-copy-slot (+ arg (comp-sp)))))))
|
2019-07-07 10:30:03 +00:00
|
|
|
|
2019-07-08 05:56:37 +00:00
|
|
|
(defun comp-limplify (func)
|
2019-07-14 18:54:53 +00:00
|
|
|
"Given FUNC compute its LIMPLE ir."
|
2019-07-08 13:29:32 +00:00
|
|
|
(let* ((frame-size (comp-func-frame-size func))
|
2019-07-08 07:29:13 +00:00
|
|
|
(comp-func func)
|
2019-07-14 18:54:53 +00:00
|
|
|
(comp-pass (make-comp-limplify
|
|
|
|
:sp -1
|
|
|
|
:frame (comp-new-frame frame-size)))
|
2019-07-08 07:06:58 +00:00
|
|
|
(comp-limple ()))
|
2019-07-07 16:42:55 +00:00
|
|
|
;; Prologue
|
2019-07-13 09:33:15 +00:00
|
|
|
(comp-emit-block 'entry)
|
2019-07-10 19:29:32 +00:00
|
|
|
(comp-emit-annotation (concat "Lisp function: "
|
2019-07-10 16:55:19 +00:00
|
|
|
(symbol-name (comp-func-symbol-name func))))
|
2019-07-14 22:58:03 +00:00
|
|
|
(cl-loop for i below (comp-args-min (comp-func-args func))
|
2019-07-07 16:42:55 +00:00
|
|
|
do (progn
|
|
|
|
(cl-incf (comp-sp))
|
2019-07-11 20:39:42 +00:00
|
|
|
(push `(setpar ,(comp-slot) ,i) comp-limple)))
|
2019-07-14 16:36:57 +00:00
|
|
|
(comp-emit-jump 'body)
|
2019-07-08 15:04:33 +00:00
|
|
|
;; Body
|
2019-07-13 09:33:15 +00:00
|
|
|
(comp-emit-block 'body)
|
2019-07-08 07:06:58 +00:00
|
|
|
(mapc #'comp-limplify-lap-inst (comp-func-ir func))
|
|
|
|
(setf (comp-func-ir func) (reverse comp-limple))
|
2019-07-07 10:30:03 +00:00
|
|
|
(when comp-debug
|
2019-07-08 05:56:37 +00:00
|
|
|
(cl-prettyprint (comp-func-ir func)))
|
|
|
|
func))
|
2019-07-07 07:23:10 +00:00
|
|
|
|
|
|
|
(defun native-compile (fun)
|
2019-07-08 09:37:17 +00:00
|
|
|
"FUN is the function definition to be compiled into native code."
|
2019-07-07 07:23:10 +00:00
|
|
|
(if-let ((f (symbol-function fun)))
|
2019-07-07 10:30:03 +00:00
|
|
|
(progn
|
|
|
|
(when (byte-code-function-p f)
|
|
|
|
(error "Can't native compile an already bytecompiled function"))
|
2019-07-08 09:37:17 +00:00
|
|
|
(let ((func (make-comp-func :symbol-name fun
|
2019-07-08 10:11:34 +00:00
|
|
|
:func f
|
|
|
|
:c-func-name (comp-c-func-name fun))))
|
2019-07-08 09:37:17 +00:00
|
|
|
(mapc (lambda (pass)
|
|
|
|
(funcall pass func))
|
|
|
|
comp-passes)
|
|
|
|
;; Once we have the final LIMPLE we jump into C.
|
2019-07-08 13:29:32 +00:00
|
|
|
(comp-init-ctxt)
|
|
|
|
(comp-add-func-to-ctxt func)
|
|
|
|
(comp-compile-and-load-ctxt)
|
|
|
|
(comp-release-ctxt)))
|
2019-07-08 10:11:34 +00:00
|
|
|
(error "Trying to native compile something not a function")))
|
2019-07-07 07:23:10 +00:00
|
|
|
|
|
|
|
(provide 'comp)
|
|
|
|
|
|
|
|
;;; comp.el ends here
|