关于erlang:apply/2/3
57 apply(Fun, Args) -> 58 apply(Fun,Args). 59 60 apply(Mod, Name, Args) -> 61 apply(Mod, Name, Args).
上面代码是erlang.erl文件里看到的。这里aplly/3方法里面又调用一次apply/3 请问是什么意思
老大: 在虚拟机里面实现的
langzhe: 谢谢
erlang.erl代码编译的时候 进行了特殊编译?所以再调用时候 不会默认调用erlang:apply/3?
老大: 恩
需要进一步 看看是怎么编译的?
apply is a built in function (BIF). It is implemented in C, not Erlang.
>
> apply is a built in function (BIF). It is implemented in C, not Erlang.
Does it work in a similar manner to that of Smalltalks, or differently?
In Smalltalks, `Boolean ifTrue: aBlock ifFalse: aBlock` literal forms
are usually compiled to call into native code directly, so the
implementation of this message in Smalltalk code in Smalltalk VMs looks
like this:
ifTrue:trueBlock ifFalse:falseBlock
^self ifTrue:[ trueBlock call ] ifFalse: [ falseBlock call ]
which looks like it would not work, but when the form
`var ifTrue:aBlockLiteral ifFalse:aBlockLiteral` is encountered the
Smalltalk compiler takes over and replaces this with native code. So the
Smalltalk implementation is only ever hit for non-literal sends (either
non-literal blocks, or usage of selectors), and its only role is to
redirect execution to the native version.
Is the purpose (and behavior) of the pure version of erlang:apply
similar?
----------引用Richard
It's a fairly common "bootstrapping" sort of thing.
Presumably
- when the compiler sees apply/2 or apply/3 in an expression
it generates special in-line code
- there needs to be a "real" function definition so that it
can be called indirectly itself, discoverable in the
module exports, traced if calls arrive that way in the
debugger, &c
apply的调用在beam加载的时候vm会调整相关的指令,实际上是在vm的opcode里面执行的。
专注高性能容错分布式服务器的研究和实现
http://blog.yufeng.info
上一篇: V8 Javascript 引擎设计理念
下一篇: CORBA定义
推荐阅读
-
[python] 在 python2和3中关于类继承的 super方法简要说明
-
关于iPad Air 2/Mini 3/Retina iMac行货的选购指南有哪些?
-
关于python3与python2同时存在情况下导入pyqt失败解决方法
-
关于python3与python2同时存在情况下导入pyqt失败解决方法
-
关于一道面试题【字符串 '1 + (5 - 2) * 3',怎么算出结果为10,'eval'除外】
-
python2与python3中关于对NaN类型数据的判断和转换方法
-
关于如何使`(a === 1 && a === 2 && a === 3)`返回`true`问题的思考
-
[python] 在 python2和3中关于类继承的 super方法简要说明
-
关于iPad Air 2/Mini 3/Retina iMac行货的选购指南有哪些?
-
关于python3与python2同时存在情况下导入pyqt失败解决方法