예제 #1
0
파일: flay.c 프로젝트: aaronlifton/urbit
/* _flay_main(): flay, with loop control.
*/
static u4_type
_flay_main(u4_milr m,
           u4_bag  hed,
           u4_type naf)
{
  u4_noun p_naf, q_naf;

  if (   u4_n_atom(naf)
      || u4_b_p(naf, u4_atom_cube, 0) 
      || u4_b_pq(naf, u4_atom_bone, &p_naf, &q_naf) 
      || u4_b_pq(naf, u4_atom_cone, &p_naf, &q_naf) 
      || u4_b_pq(naf, u4_atom_pair, &p_naf, &q_naf) )
  {
    return naf;
  }
  else if ( u4_b_pq(naf, u4_atom_fork, &p_naf, &q_naf) ) {
    return _mill_eith(m, _flay_main(m, hed, p_naf), 
                         _flay_main(m, hed, q_naf));
  }
  else if ( u4_b_pq(naf, u4_atom_fuse, &p_naf, &q_naf) ) {
    return _mill_both(m, _flay_main(m, hed, p_naf), 
                         _flay_main(m, hed, q_naf));
  }
  else if ( u4_b_pq(naf, u4_atom_post, &p_naf, &q_naf) ) {
    if ( u4_bag_in(naf, hed) ) {
      return naf;
    }
    else {
      hed = u4_bag_add(m->lane, naf, hed);
      {
        u4_type tey = _mill_repo(m, p_naf, q_naf);
        u4_type mal = _flay_main(m, hed, tey);
   
        return (u4_n_eq(tey, mal) ? naf : mal);
      }
    }
  }
  else {
    return _flay_main(m, hed, _mill_reap(m, naf));
  }

}
예제 #2
0
파일: safe.c 프로젝트: aaronlifton/urbit
/* _mill_safe_in(): check type, with recursion control.
*/
u4_t
_mill_safe_in(u4_milr m,
              u4_bag  gil,
              u4_type naf,
              u4_gene dug)
{
  u4_lane lane = m->lane;
  u4_noun fid  = u4_k_cell(lane, naf, dug);

  /* Memoization.  Can we do this without gil?  Yes.
  */
  {
    if ( u4_bag_in(fid, m->tyx) ) {
      return 1;
    }
    else {
      u4_t t = _safe_loop(m, gil, naf, dug);

      u4_assert(t);
      m->tyx = u4_bag_add(lane, fid, m->tyx);
      return 1;
    }
  }
}
예제 #3
0
파일: repo.c 프로젝트: mbrubeck/urbit
/* _mill_repo(): replay load.
*/
u4_type
_mill_repo(u4_milr m,
           u4_type tip,
           u4_gene gen)
{
  u4_lane lane = m->lane;
  u4_noun fad = u4_k_cell(lane, tip, gen);
  u4_noun fan;
  u4_type pol;

  if ( u4_bag_in(fad, m->fan) ) {
    // printf("inference recursion\n");
    // abort();

    return _mill_fail(m, "repo: inference recursion");
  }

  fan = m->fan;
  m->fan = u4_bag_add(lane, fad, m->fan);
  pol = _mill_play(m, gen, tip);
  m->fan = fan;

  return pol;
}
예제 #4
0
파일: safe.c 프로젝트: aaronlifton/urbit
/* _safe_loop(): check type, inside memoization.
*/
static u4_t
_safe_loop(u4_milr m,
           u4_bag  gil,
           u4_type naf,
           u4_gene dug)
{
  u4_lane lane = m->lane;

  /* Recursion control.
  */
  {
    u4_noun mel = u4_k_cell(lane, naf, dug);

    if ( u4_bag_in(mel, gil) ) {
      /* Conservative search.
      */
      return 1;
    }
    else {
      gil = u4_bag_add(lane, mel, gil);
    }
  }

  /* Core semantics.
  */
  {
    u4_noun p_dug, q_dug, r_dug;

    if ( u4_b_fork(dug, &p_dug, &q_dug) ) {
      return _mill_safe_in(m, gil, naf, p_dug) && 
             _mill_safe_in(m, gil, naf, q_dug);
    }

    else if ( u4_b_pq(dug, u4_atom_bend, &p_dug, &q_dug) ) {
      return _mill_suss(m, gil, naf, p_dug, q_dug);
    }

    else if ( u4_b_pq(dug, u4_atom_cast, &p_dug, &q_dug) ) {
      if ( !_mill_safe_in(m, gil, naf, p_dug) || 
           !_mill_safe_in(m, gil, naf, q_dug) )
      {
        return 0;
      }
      else {
        u4_type lup = _mill_play(m, naf, p_dug);
        u4_type tog = _mill_play(m, naf, q_dug);

        if ( !_mill_cong(m, lup, tog) ) {
          // u4_burp(lane, "cast: lup", _mill_dump(m, lup));
          // u4_burp(lane, "cast: tog", _mill_dump(m, tog));

          _mill_fail(m, "cast infraction");
          return 0;
        }
        return 1;
      }
    }
  
    else if ( u4_b_pq(dug, u4_atom_coat, &p_dug, &q_dug) ) {
      return _mill_safe_in(m, gil, naf, q_dug);
    }

    else if ( u4_b_p(dug, u4_atom_dbug, &p_dug) ) {
      u4_t gaf;

      m->rux = u4_op_inc(lane, m->rux);
      gaf = _mill_safe_in(m, gil, naf, p_dug);
      m->rux = u4_op_dec(lane, m->rux);

      return gaf;
    }

    else if ( u4_b_pqr(dug, u4_atom_if, &p_dug, &q_dug, &r_dug) ) {
      if ( !_mill_safe_in(m, gil, naf, p_dug) ) {
        return 0;
      }
      else {
        u4_type lag = _mill_play(m, naf, p_dug);

        if ( !_mill_cong(m, _flag(lane), lag) ) {
          return _mill_fail(m, "if abuse");
        }
        else {
          u4_loaf ruf = _mill_hunt(m, naf, p_dug);
          u4_type sec = u4_ch(ruf);
          u4_form nak = u4_ct(ruf);
    
          if ( u4_n_eq(u4_noun_1, u4_ch(nak)) ) {
            if ( u4_n_eq(u4_noun_0, u4_ct(nak)) ) {
              return _mill_safe_in(m, gil, naf, q_dug);
            } else {
              return _mill_safe_in(m, gil, naf, r_dug);
            }
          }
          else {
            return _mill_safe_in(m, gil, _mill_both(m, sec, naf), q_dug) && 
                   _mill_safe_in(m, gil, naf, r_dug);
          }
        }
      }
    }
  
    else if ( u4_b_pq(dug, u4_atom_like, &p_dug, &q_dug) ) {
      if ( !_mill_safe_in(m, gil, naf, p_dug) || 
           !_mill_safe_in(m, gil, naf, q_dug) )
      {
        return 0;
      }
      else {
#if 0
        u4_type fez = _mill_play(m, naf, p_dug);
        u4_type gar = _mill_play(m, naf, q_dug);

        if ( !_mill_cong(m, fez, gar) && !_mill_orth(m, fez, gar) ) {
          _mill_fail(m, "like confusion");
          return 0;
        }
#endif
        return 1;
      }
    }

    else if ( u4_b_p(dug, u4_atom_limb, &p_dug) ) {
      return 1;
    }

    else if ( u4_b_pq(dug, u4_atom_link, &p_dug, &q_dug)) {
      if ( !_mill_safe_in(m, gil, naf, p_dug) ) {
        return 0;
      }
      else return _mill_safe_in(m, gil, _mill_play(m, naf, p_dug), q_dug);
    }

    else if ( u4_b_p(dug, u4_atom_load, &p_dug) ) {
      u4_type roz = u4_k_trel(lane, u4_atom_cone, naf, p_dug);

      return _main_load(m, gil, roz, p_dug);
    }
  
    else if (u4_b_pq(dug, u4_atom_look, &p_dug, &q_dug) ) {
      return _mill_peek(m, gil, naf, p_dug, q_dug);
    }

    else if ( u4_b_pq(dug, u4_atom_raw, &p_dug, &q_dug) ) {
      if ( !_mill_safe_in(m, gil, naf, q_dug) ) {
        return 0;
      }
      else {
        if ( u4_n_eq(u4_noun_3, p_dug) || u4_n_eq(u4_noun_4, p_dug) ) {
          return 1;
        }
        else if ( u4_n_eq(u4_noun_5, p_dug) ) {
          u4_type poz = _mill_play(m, naf, q_dug);

          if ( !_mill_cong(m, u4_atom_atom, poz) ) {
            return _mill_fail(m, "raw bump");
          }
          else return 1;
        }
        else if ( u4_n_eq(u4_noun_6, p_dug) ) {
          u4_type lem = u4_k_trel
            (lane, u4_atom_pair, u4_atom_blur, u4_atom_blur);
          u4_type poz = _mill_play(m, naf, q_dug);

          if ( !_mill_cong(m, lem, poz) ) {
            return _mill_fail(m, "raw same");
          }
          else return 1;
        }
        else return u4_trip;
      }
    }
  
    else if ( u4_b_p(dug, u4_atom_rock, &p_dug) ) {
      return 1;
    }

    else if ( u4_b_pq(dug, u4_atom_site, &p_dug, &q_dug) ) {
      u4_noun fob = m->zud;
      u4_t    gaf;

      m->zud = p_dug;
      gaf = _mill_safe_in(m, gil, naf, q_dug);
      m->zud = fob;

      return gaf;
    }

    else if ( u4_b_pq(dug, u4_atom_spot, &p_dug, &q_dug) ) {
      u4_noun fob = m->nix;
      u4_t    gaf;

      m->nix = p_dug;
      gaf = _mill_safe_in(m, gil, naf, q_dug);
      m->nix = fob;

      return gaf;
    }
  
    else if ( u4_b_pqr(dug, u4_atom_sure, &p_dug, &q_dug, &r_dug) ) {
      if ( !_mill_safe_in(m, gil, naf, p_dug) || 
           !_mill_safe_in(m, gil, naf, q_dug) )
      {
        return 0;
      }
      else {
        u4_type lop = _mill_play(m, naf, p_dug);
        u4_type huq = _mill_play(m, naf, q_dug);

        if ( !_mill_cong(m, huq, lop) ) {
          return _mill_fail(m, "sure violation");
        }
        else {
          return _mill_safe_in(m, gil, naf, r_dug);
        }
      }
    }
  
    else {
      return _mill_safe_in(m, gil, naf, _mill_open(m, dug));
    }
  }
}
예제 #5
0
파일: seal.c 프로젝트: aaronlifton/urbit
/* _seal_main(): as _mill_seal(), with gil.
*/
static u4_loaf
_seal_main(u4_milr m,
           u4_bag  gil,
           u4_mold typ)
{
  u4_lane lane = m->lane;
  u4_noun p_typ, q_typ;

  // %atom
  // %blur
  //
  if ( u4_n_eq(u4_atom_atom, typ) ||
       u4_n_eq(u4_atom_blur, typ) ||
       u4_n_eq(u4_atom_blot, typ) ) 
  {
    return u4_noun_0;
  }

  // [%cell p=mold q=mold]
  //
  else if ( u4_b_pq(typ, u4_atom_cell, &p_typ, &q_typ) ) {
    return u4_bag_cat(lane, _seal_main(m, gil, p_typ),
                            _seal_main(m, gil, q_typ));
  }

  // [%mono p=mold q=bush+[mark mold]]
  //
  else if ( u4_b_pq(typ, u4_atom_mono, &p_typ, &q_typ) ||
            u4_b_pq(typ, u4_atom_poly, &p_typ, &q_typ) ) {
    return _seal_main(m, gil, p_typ);
  }

  // [%cube p=noun]
  // 
  else if ( u4_b_p(typ, u4_atom_cube, &p_typ) ) {
    return u4_noun_0;
  }

  // [%face p=mark q=mold]
  //
  else if ( u4_b_pq(typ, u4_atom_face, &p_typ, &q_typ) ) {
    return _seal_main(m, gil, q_typ);
  }

  // [%fork p=mold q=mold]
  //
  else if ( u4_b_pq(typ, u4_atom_fork, &p_typ, &q_typ) ) {
    return u4_bag_cat(lane, _seal_main(m, gil, p_typ),
                            _seal_main(m, gil, q_typ));
  }

  // [%fuse p=mold q=mold]
  //
  else if ( u4_b_pq(typ, u4_atom_fuse, &p_typ, &q_typ) ) {
    return u4_bag_cat(lane, _seal_main(m, gil, p_typ),
                            _seal_main(m, gil, q_typ));
  }

  // [%hold p=mold q=gene]
  //
  else if ( u4_b_pq(typ, u4_atom_hold, &p_typ, &q_typ) ) {
    if ( u4_bag_in(typ, gil) ) {
      return u4_k_trel(lane, typ, u4_noun_0, u4_noun_0);
    } 
    else {
      return _seal_main
        (m, u4_bag_add(lane, typ, gil),
            _mill_repo(m, p_typ, q_typ));
    }
  }

  else {
    u4_bug("strange mold", typ);
    return u4_trip;
  }
}