小编jus*_*tin的帖子

如何修改Erlang程序集?有资源吗?

我怀疑任何人都可以帮助解决这个问题,因为Erlang的编译文档中有以下内容:

请注意,汇编程序文件的格式未记录,并且可能在发行版之间更改 - 此选项主要用于内部调试.

...但为了以防万一,这里是故事的堆栈跟踪:

  • 使用['S']编译:file/2以生成汇编代码
  • 读取.S文件并创建一个键值数据结构,其中键是.S文件中的"函数"元组,值是函数的主体,即实现该函数的汇编指令.
  • 通过添加程序集来修改数据结构,以在某些函数中进行外部函数调用.
  • 崩溃......

不幸的是,我只是快速浏览了编译包含以下函数的模块时生成的.S文件,有和没有函数注释掉的第一个表达式:

spawn_worker(Which) ->
    %syner:sync_pt(),
    case Which of
            ?NAIVE -> spawn(err1, naive_worker_loop, [])
    end.
Run Code Online (Sandbox Code Playgroud)

当我这样做时,我认为唯一改变的是元组:

{call_ext,0,{extfunc,syner,sync_pt,0}}.

...所以我认为在程序集中注入一个函数调用所需的唯一东西就是添加那个元组...但是现在我必须实际注入元组...我看到生成的程序集有一些额外说明:

没有syner:sync_pt():

{function, spawn_worker, 1, 4}.
{label,3}.
    {func_info,{atom,err1},{atom,spawn_worker},1}.
{label,4}.
    {test,is_eq_exact,{f,5},[{x,0},{atom,naive}]}.
    {move,{atom,naive_worker_loop},{x,1}}.
    {move,nil,{x,2}}.
    {move,{atom,err1},{x,0}}.
    {call_ext_only,3,{extfunc,erlang,spawn,3}}.
{label,5}.
    {case_end,{x,0}}.
Run Code Online (Sandbox Code Playgroud)

使用syner:sync_pt():

{function, spawn_worker, 1, 4}.
{label,3}.
    {func_info,{atom,err1},{atom,spawn_worker},1}.
{label,4}.
    {allocate,1,1}.
    {move,{x,0},{y,0}}.
    {call_ext,0,{extfunc,syner,sync_pt,0}}.
    {test,is_eq_exact,{f,5},[{y,0},{atom,naive}]}.
    {move,{atom,naive_worker_loop},{x,1}}.
    {move,nil,{x,2}}.
    {move,{atom,err1},{x,0}}.
    {call_ext_last,3,{extfunc,erlang,spawn,3},1}.
{label,5}.
    {case_end,{y,0}}.
Run Code Online (Sandbox Code Playgroud)

我不能仅仅得出结论:

   {allocate,1,1}.
   {move,{x,0},{y,0}}.
   {call_ext,0,{extfunc,syner,sync_pt,0}}.
Run Code Online (Sandbox Code Playgroud)

我希望将每个函数注入一个外部函数调用,就可以了.

  1. 因为我不确定汇编代码是否适用于我想要注入的所有函数(例如{allocate,1,1}总是正常)
  2. 因为如果仔细查看程序集的其余部分,它会略有变化(例如{call_ext_only,3,{extfunc,erlang,spawn,3}}.更改为{call_ext_last,3,{extfunc,erlang,spawn, 3},1}.). …

erlang assembly

8
推荐指数
1
解决办法
1000
查看次数

为什么程序员"强烈建议不要进行解析转换"?

根据erl_id_trans文档:

强烈建议程序员不要进行解析转换,也不要对遇到的问题提供支持.

为什么强烈建议程序员不要使用parse_transform/2?这将不会得到支持吗?除了parse_transform/2之外,是否有一种机制可以在编译之前注入代码(运行时字节码修改)或修改源代码?

erlang parse-transform

6
推荐指数
1
解决办法
1038
查看次数

使用自定义onPress添加抽屉项目的简便方法?

我正在使用DrawerNavigator,只要我想导航到一个新的屏幕,一切都很好.

现在我想添加一个抽屉项目,它不会导航到新的屏幕,而只是触发一个动作(一般情况下).具体来说,我想使用'react-native'共享功能.

我让这个工作,但我认为解决方案不是很好.这是我到目前为止所得到的:

const myContentComponent = props => (
    <ScrollView alwaysBounceVertical={false}>
        <SafeAreaView style={{ flex: 1 }} forceInset={{ top: 'always', horizontal: 'never' }}>
            <DrawerItems {...props} />
            <TouchableItem
                key="share"
                onPress={() => {
                    Share.share(
                        {
                            message: 'YO: this will be the text message',
                            url: 'http://tmp.com',
                            title: 'This will be the email title/subject',
                        },
                        {
                            // Android only:
                            dialogTitle: 'This will be the title in the dialog to choose means of sharing',
                        },
                    );
                    props.navigation.navigate('DrawerClose');
                }}
                delayPressIn={0}
            >
                <SafeAreaView forceInset={{ left: 'always', right: 'never', …
Run Code Online (Sandbox Code Playgroud)

react-navigation

6
推荐指数
1
解决办法
1903
查看次数

如何在MongoDB中不创建集合的情况下创建Mongoose模型?

我只想versioneditems在MongoDB中有一个集合,但是我需要同时注册VersionedItem模型和ItemPatch模型,因为我需要创建ItemPatches来填充VersionedItem

将没有单独的ItemPatch文档(它们嵌入在中VersionedItem)。除了在MongoDB中创建了一个额外的集合外,以下代码可以正常工作:

src / models / versionedItemFactory.js

const VersionedItemSchema = require('../schemas/VersionedItem');

module.exports = (db) => {
  var VersionedItemModel = db.model('VersionedItem', VersionedItemSchema);

  return VersionedItemModel;
};
Run Code Online (Sandbox Code Playgroud)

src / models / itemPatchFactory.js

const ItemPatchSchema = require('../schemas/ItemPatch');

module.exports = (db) => {
  var ItemPatchModel = db.model('ItemPatch', ItemPatchSchema);

  return ItemPatchModel;
};
Run Code Online (Sandbox Code Playgroud)

src / schemas / util / asPatch.js

var mongoose = require('mongoose');

module.exports = function _asPatch(schema) {

  return new mongoose.Schema({
    createdAt: …
Run Code Online (Sandbox Code Playgroud)

mongoose

5
推荐指数
1
解决办法
607
查看次数

匹配规范是否仅用于跟踪和从ets表中选择?它们可以用在案例表达中吗?

有没有办法使用匹配规范在函数的不同子句之间进行选择?我已经看到匹配规范仅用于跟踪或匹配ets表中的条目.

我想做的例子:

在用户提供的文件中:

Module(m1),  
Function(f1),  
Guard([ %% list of match specifications follows:  
  %% First (and only in this case) match spec:  
   { [{score, '$1', '$2', '$3'}, '$4'], 
       [{is_atom, '$1'}, {is_pid, '$2'}, {is_atom, '$3'}], 
     [true] }  
  ]).
Run Code Online (Sandbox Code Playgroud)

从这个文件我想生成代码.对我来说重要的是能够使用Guard中的匹配规范来过滤掉f1的子句,这样我就可以知道f1的第一个参数何时是形式的元组{score,First,Second,第三个}和is_atom(第一个),is_pid(第二个),is_atom(第三个).

有没有办法让我生成这样的代码:

case some_unknown_function(MatchSpec, F1Args) of
  true ->
    %% f1's clause matches the MatchSpec
    ;
  false ->
    %% f1's clause does not match the MatchSpec
end.
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.谢谢.

erlang

3
推荐指数
1
解决办法
457
查看次数

迭代器与迭代器

这个差异显着吗?是吗:

\n\n
    \n
  • 迭代器 = 迭代一组数据结构的某种抽象
  • \n
  • iteratee = 被迭代的实际数据结构
  • \n
\n\n

我正在阅读async的文档,并看到到处都有“iteratee”的使用。好吧,它不执行实际的迭代,因此迭代器不是它的正确名称。但根据我对上面“iteratee”的理解,它也不应该是一个函数(在我看来,iteratee = 数据结构 - 如果有的话,迭代器就是执行迭代的函数)。

\n\n

如果您不熟悉asynciteratee:它是一个带有 2 个参数的函数,您要迭代的集合中的下一个值,以及一个带有错误值和结果值的函数。您应该在 iteratee 中执行异步操作,然后使用错误或结果调用它的第二个参数(函数(err,结果))。

\n\n

(然后,您将另一个回调作为参数(除了 iteratee 之外)提供给您正在执行的任何操作(映射、过滤器等\xe2\x80\xa6),以处理在 iteratee 中调用异步操作的结果初始集合的元素)。

\n\n

只是好奇:“iteratee”这个名字正确吗?

\n

computer-science async.js

3
推荐指数
1
解决办法
937
查看次数