Make-array in SBCL



make-array如何在SBCL中工作?C++中是否有一些等价的newdelete运算符,还是其他东西,也许是汇编程序级别?

我偷看了一下源头,但什么都不懂。

当使用从源代码编译的 SBCL 和像 Emacs/Slime 这样的环境时,可以使用M-. (元点(非常轻松地导航代码。基本上,make-array符号绑定到多个事物:deftransform定义和defundeftransform主要用于优化,因此最好先遵循该功能。

make-array函数委托给内部make-array%函数,这非常复杂:它检查参数,并根据这些参数调度到数组的不同专用实现:例如,位向量的实现方式与字符串不同。

如果你遵循simple-array的情况,你会发现一个调用allocate-vector-with-widetag的函数,而又调用allocate-vector

现在,allocate-vector绑定到多个对象、多个defoptimizers形式、一个函数和一个define-vop形式。

该功能仅是:

(defun allocate-vector (type length words)
(allocate-vector type length words))

即使它看起来像递归调用,也不是。

define-vop表单是一种定义如何编译allocate-vector的调用的方法。在函数中,以及任何调用allocate-vector的地方,编译器知道如何编写实现内置操作的程序集。但是,函数本身的定义是,因此有一个同名的入口点,以及一个包装该代码的函数对象。

define-vop依赖于 SBCL 中的域特定语言,该语言在汇编上抽象。如果遵循该定义,则可以为allocate-vector找到不同的vops(虚拟操作(,例如allocate-vector-on-heapallocate-vector-on-stack

堆上的分配转化为对calc-size-in-bytes的调用,对allocationput-header的调用,这很可能分配内存并标记它(我按照定义src/compiler/x86-64/alloc.lisp(。 如何分配(和垃圾回收(内存是另一个问题。

allocation使用%alloc-tramp发出汇编代码,进而执行以下操作:

(invoke-asm-routine 'call (if to-r11 'alloc-tramp-r11 'alloc-tramp) node)

显然有称为alloc-tramp-r11alloc-tramp的汇编例程,它们是预定义的汇编指令。一条评论说:

;;; Most allocation is done by inline code with sometimes help
;;; from the C alloc() function by way of the alloc-tramp
;;; assembly routine.

运行时有一个 C 代码基础,请参阅示例/src/runtime/alloc.c

-tramp后缀代表蹦床。

也看看src/runtime/x86-assem.S.

最新更新