Beispiel #1
0
/*
 * (S, N):
 *
 * N is bound to a number with the string representation S.
 */
void integer_of_string(LmnReactCxt *rc,
                       LmnMembrane *mem,
                       LmnAtom a0, LmnLinkAttr t0,
                       LmnAtom a1, LmnLinkAttr t1)
{
  long n;
  char *t;
  const char *s = (const char *)lmn_string_c_str(LMN_STRING(a0));
  t = NULL;
  n = strtol(s, &t, 10);
  if (t == NULL || s == t) {
    LmnSAtom a = lmn_mem_newatom(mem, lmn_functor_intern(ANONYMOUS,
                                                         lmn_intern("fail"),
                                                         1));
    lmn_mem_newlink(mem,
                    a1, t1, LMN_ATTR_GET_VALUE(t1),
                    LMN_ATOM(a), LMN_ATTR_MAKE_LINK(0), 0);
  } else { /* 変換できた */
    lmn_mem_newlink(mem,
                    a1, t1, LMN_ATTR_GET_VALUE(t1),
                    n, LMN_INT_ATTR, 0);
    lmn_mem_push_atom(mem, n, LMN_INT_ATTR);
  }

  lmn_mem_delete_atom(mem, a0, t0);
}
Beispiel #2
0
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);
  }