Exemple #1
0
def jfun(f, *args, **kw):
  if hasattr(f, '__jeeves'):
    return f(*args, **kw)
  else:
    env = jeevesState.pathenv.getEnv()
    if len(args) > 0:
      return jfun2(f, args, kw, 0, partialEval(fexpr_cast(args[0]), env), [])
    else:
      it = kw.__iter__()
      try:
        fst = next(it)
      except StopIteration:
        return fexpr_cast(f())
      return jfun3(f, kw, it, fst, partialEval(fexpr_cast(kw[fst]), env), (), {})
Exemple #2
0
def mkSensitive(varLabel, vHigh, vLow):
  """Creates a sensitive value with two facets.

  :param varLabel: Label to associate with sensitive value.
  :type varLabel: Var
  :param vHigh: High-confidentiality facet for viewers with restricted access.
  :type vHigh: T
  :param vLow: Low-confidentiality facet for other viewers.
  :type vLow: T
  """

  if isinstance(varLabel, Var):
    return Facet(varLabel, fexpr_cast(vHigh), fexpr_cast(vLow))
  else:
    return JeevesLib.jif(varLabel, lambda:vHigh, lambda:vLow)
Exemple #3
0
def jfun3(f, kw, it, key, val, args_concrete, kw_concrete):
  if isinstance(val, Constant) or isinstance(val, FObject):
    kw_c = dict(kw_concrete)
    kw_c[key] = val.v
    try:
      next_key = next(it)
    except StopIteration:
      return fexpr_cast(f(*args_concrete, **kw_c))
    env = jeevesState.pathenv.getEnv()
    return jfun3(f, kw, it, next_key, partialEval(fexpr_cast(kw[next_key]), env), args_concrete, kw_c)
  else:
    with PositiveVariable(val.cond):
      thn = jfun3(f, kw, it, key, val.thn, args_concrete, kw_concrete)
    with NegativeVariable(val.cond):
      els = jfun3(f, kw, it, key, val.els, args_concrete, kw_concrete)
    return Facet(arg.cond, thn, els)
Exemple #4
0
def evalToConcrete(f):
    g = partialEval(fexpr_cast(f), jeevesState.pathenv.getEnv())
    if isinstance(g, Constant):
      return g.v
    elif isinstance(g, FObject):
      return g.v
    else:
      raise Exception("wow such error: evalToConcrete on non-concrete thingy-ma-bob")
Exemple #5
0
def jmap(iterable, mapper):
  if isinstance(iterable, JList2):
    return jmap_jlist2(iterable, mapper)
  if isinstance(iterable, FObject) and isinstance(iterable.v, JList2):
    return jmap_jlist2(iterable.v, mapper)

  iterable = partialEval(fexpr_cast(iterable), jeevesState.pathenv.getEnv())
  return FObject(JList(jmap2(iterable, mapper)))
Exemple #6
0
def jfun2(f, args, kw, i, arg, args_concrete):
  if isinstance(arg, Constant) or isinstance(arg, FObject):
    env = jeevesState.pathenv.getEnv()
    if i < len(args) - 1:
      return jfun2(f, args, kw, i+1, partialEval(fexpr_cast(args[i+1]), env), tuple(list(args_concrete) + [arg.v]))
    else:
      it = kw.__iter__()
      try:
        fst = next(it)
      except StopIteration:
        return fexpr_cast(f(*tuple(list(args_concrete) + [arg.v])))
      return jfun3(f, kw, it, fst, partialEval(fexpr_cast(kw[fst]), env), tuple(list(args_concrete) + [arg.v]), {})
  else:
    with PositiveVariable(arg.cond):
      thn = jfun2(f, args, kw, i, arg.thn, args_concrete)
    with NegativeVariable(arg.cond):
      els = jfun2(f, args, kw, i, arg.els, args_concrete)
    return Facet(arg.cond, thn, els)
Exemple #7
0
def liftTuple(t):
  t = fexpr_cast(t)
  if isinstance(t, FObject):
    return t.v
  elif isinstance(t, Facet):
    a = liftTuple(t.thn)
    b = liftTuple(t.els)
    return tuple([Facet(t.cond, a1, b1) for (a1, b1) in zip(a, b)])
  else:
    raise TypeError("bad use of liftTuple")
Exemple #8
0
def jif(cond, thn_fn, els_fn):
  condTrans = partialEval(fexpr_cast(cond), jeevesState.pathenv.getEnv())
  if condTrans.type != bool:
    raise TypeError("jif must take a boolean as a condition")
  return jif2(condTrans, thn_fn, els_fn)
Exemple #9
0
def mkSensitive(varLabel, vHigh, vLow):
  return Facet(varLabel, fexpr_cast(vHigh), fexpr_cast(vLow))
Exemple #10
0
def jmap(iterable, mapper):
  iterable = partialEval(fexpr_cast(iterable))
  return jmap2(iterable, mapper)