public static ZilResult EXPAND([NotNull] Context ctx, [NotNull] ZilObject value) { var result = value.Expand(ctx); if (result.ShouldPass()) { return(result); } if ((ZilObject)result == value) { result = value.Eval(ctx); } return(result); }
public static ZilObject Unwrap([NotNull] this ZilObject zo, [NotNull] Context ctx) { var src = zo.SourceLine; using (DiagnosticContext.Push(src)) { while (true) { zo = (ZilObject)zo.Expand(ctx); switch (zo) { case ZilForm form when form.IsEmpty: return(ctx.FALSE); case ZilAdecl adecl: // TODO: check DECL zo = adecl.First; break; case IMayExpandAfterEvaluation expandAfter when expandAfter.ShouldExpandAfterEvaluation: // TODO: don't use Parse here zo = expandAfter.ExpandAfterEvaluation() .FirstOrCombine(zos => Program.Parse(ctx, src, "<BIND () {0:SPLICE}>", new ZilList(zos)) .Single()); break; case ZilMacroResult macroResult: zo = macroResult.Inner; break; default: return(zo); } } } }