示例#1
0
文件: nlmem.c 项目: lmntal/slim
void nlmem_copy(LmnReactCxtRef rc,
                LmnMembraneRef mem,
                LmnAtomRef a0, LmnLinkAttr t0,
                LmnAtomRef a1, LmnLinkAttr t1,
                LmnAtomRef a2, LmnLinkAttr t2)
{
  LmnMembraneRef org_mem, trg_mem;
  ProcessTableRef atom_map;
  lmn_interned_str copy_tag_name;
  LmnFunctor copy_tag_func;

  copy_tag_name = LMN_FUNCTOR_NAME_ID(LMN_SATOM_GET_FUNCTOR((LmnSymbolAtomRef)a1));
  copy_tag_func = lmn_functor_intern(ANONYMOUS, copy_tag_name, 3);
  org_mem = LMN_PROXY_GET_MEM(LMN_SATOM_GET_LINK((LmnSymbolAtomRef)a0, 0));
  trg_mem = lmn_mem_make();
  atom_map = lmn_mem_copy_cells(trg_mem, org_mem);
  lmn_mem_add_child_mem(mem, trg_mem);

  {
    AtomListEntryRef ent = lmn_mem_get_atomlist(org_mem, LMN_IN_PROXY_FUNCTOR);

    if (ent) {
      LmnSymbolAtomRef org_in, org_out, trg_in, trg_out;
      LmnSymbolAtomRef tag_atom;
      LmnWord t = 0;

      EACH_ATOM(org_in, ent, ({
        /* タグアトムを作り、リンクの接続を行う */
        proc_tbl_get_by_atom(atom_map, org_in, &t);
        trg_in = LMN_SATOM(t);
        org_out = LMN_SATOM(LMN_SATOM_GET_LINK(org_in, 0));
        trg_out = lmn_mem_newatom(mem, LMN_OUT_PROXY_FUNCTOR);
        lmn_newlink_in_symbols(trg_in, 0, trg_out, 0);
        tag_atom = lmn_mem_newatom(mem, copy_tag_func);
        lmn_relink_symbols(tag_atom, 2, org_out, 1);
        lmn_newlink_in_symbols(tag_atom, 0, org_out, 1);
        lmn_newlink_in_symbols(tag_atom, 1, trg_out, 1);
      }));
    }

    proc_tbl_free(atom_map);
    lmn_mem_delete_atom(mem, a1, t1);
    /* 第一引数に接続されたタグアトムと第三引数を接続する */
    lmn_mem_newlink(mem,
                    a2, t2, LMN_ATTR_GET_VALUE(t2),
                    LMN_SATOM_GET_LINK((LmnSymbolAtomRef)a0, 1), LMN_SATOM_GET_ATTR((LmnSymbolAtomRef)a0, 1),
                    2);
  }
示例#2
0
文件: translate.c 项目: onmsr/slim
void tr_instr_commit_ready(LmnReactCxt      *rc,
                           LmnRule          rule,
                           lmn_interned_str rule_name,
                           LmnLineNum       line_num,
                           LmnMembrane      **ptmp_global_root,
                           LmnRegister      **p_v_tmp,
                           unsigned int     *org_next_id)
{
  LMN_ASSERT(rule);
  lmn_rule_set_name(rule, rule_name);

  *org_next_id = env_next_id();

#ifdef KWBT_OPT
  if (lmn_env.opt_mode != OPT_NONE) {
    lmn_fatal("translter mode, optimize mode is not supported");
  }
#endif

  if (RC_GET_MODE(rc, REACT_PROPERTY)) {
    return;
  }

  if (RC_GET_MODE(rc, REACT_ND)) {
    if (RC_MC_USE_DMEM(rc)) {
      /* dmemインタプリタ(body命令)を書かないとだめだ */
      lmn_fatal("transalter mode, delta-membrane execution is not supported.");
    } else {
      LmnRegister *v, *tmp;
      ProcessTbl copymap;
      LmnMembrane *tmp_global_root;
      unsigned int i, warry_size_org, warry_use_org;

#ifdef PROFILE
      if (lmn_env.profile_level >= 3) {
        profile_start_timer(PROFILE_TIME__STATE_COPY_IN_COMMIT);
      }
#endif

      warry_size_org  = warry_size(rc);
      warry_use_org   = warry_use_size(rc);
      tmp_global_root = lmn_mem_copy_with_map(RC_GROOT_MEM(rc), &copymap);

      /** 変数配列および属性配列のコピー */
      v = lmn_register_make(warry_size_org);

      /** copymapの情報を基に変数配列を書換える */
#ifdef TIME_OPT
      for (i = 0; i < warry_use_org; i++) {
        LmnWord t;
        v[i].at = at(rc, i);
        v[i].tt = tt(rc, i);
        if (v[i].tt == TT_ATOM) {
          if (LMN_ATTR_IS_DATA(v[i].at)) {
            v[i].wt = (LmnWord)lmn_copy_data_atom((LmnAtom)wt(rc, i), (LmnLinkAttr)v[i].at);
          } else if (proc_tbl_get_by_atom(copymap, LMN_SATOM(wt(rc, i)), &t)) {
            v[i].wt = (LmnWord)t;
          } else {
            t = 0;
            lmn_fatal("implementation error");
          }
        }
        else if (v[i].tt == TT_MEM) {
          if (wt(rc, i) == (LmnWord)RC_GROOT_MEM(rc)) { /* グローバルルート膜 */
            v[i].wt = (LmnWord)tmp_global_root;
          } else if (proc_tbl_get_by_mem(copymap, (LmnMembrane *)wt(rc, i), &t)) {
            v[i].wt = (LmnWord)t;
          } else {
            t = 0;
            lmn_fatal("implementation error");
          }
        }
        else { /* TT_OTHER */
          v[i].wt = wt(rc, i);
        }
      }
#else
      for (i = 0; i < warry_size_org; i++) {
        v[i].at = at(rc, i);
        if (LMN_ATTR_IS_DATA(v[i].at)) {
          v[i].wt = (LmnWord)lmn_copy_data_atom((LmnAtom)wt(rc, i), (LmnLinkAttr)v[i].at);
        }
        else if (proc_tbl_get(copymap, wt(rc, i), &t)) {
          v[i].wt = t;
        }
        else if(wt(rc, i) == (LmnWord)RC_GROOT_MEM(rc)) { /* グローバルルート膜 */
          v[i].wt = (LmnWord)tmp_global_root;
        }
      }
#endif
      proc_tbl_free(copymap);

      /** SWAP */
      tmp = rc_warry(rc);
      rc_warry_set(rc, v);
#ifdef PROFILE
      if (lmn_env.profile_level >= 3) {
        profile_finish_timer(PROFILE_TIME__STATE_COPY_IN_COMMIT);
      }
#endif

      /* 処理中の変数を外へ持ち出す */
      *ptmp_global_root = tmp_global_root;
      *p_v_tmp = tmp;
    }
  }
}