Beispiel #1
0
        public ZilAtom([NotNull] string text, [CanBeNull] ObList list, StdAtom stdAtom)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(text));
            }

            Text      = text;
            this.list = list;
            StdAtom   = stdAtom;
        }
Beispiel #2
0
        /* GetViaInner and SetViaInner disable DECL checking because user code may expect
         * property identifiers to be passed as FIXes instead of ATOMs. */
        ZilObject GetViaInner(StdAtom accessor)
        {
            var oldCheckDecls = ctx.CheckDecls;

            try
            {
                ctx.CheckDecls = false;
                var form = new ZilForm(new ZilObject[]
                {
                    ctx.GetStdAtom(accessor),
                    Inner
                });

                return((ZilObject)form.Eval(ctx));
            }
            finally
            {
                ctx.CheckDecls = oldCheckDecls;
            }
        }
Beispiel #3
0
        void SetViaInner(StdAtom accessor, ZilObject value)
        {
            var oldCheckDecls = ctx.CheckDecls;

            try
            {
                ctx.CheckDecls = false;
                var form = new ZilForm(new[]
                {
                    ctx.GetStdAtom(accessor),
                    Inner,
                    value
                });

                form.Eval(ctx);
            }
            finally
            {
                ctx.CheckDecls = oldCheckDecls;
            }
        }
Beispiel #4
0
        static ZilObject PerformUse([NotNull] Context ctx, [NotNull] string[] args, string name, StdAtom requiredPackageType)
        {
            if (!(ctx.GetLocalVal(ctx.GetStdAtom(StdAtom.OBLIST)) is ZilList obpath))
            {
                throw new InterpreterError(
                          InterpreterMessages._0_Value_Of_1_Must_Be_2,
                          "local",
                          "OBLIST",
                          "a list starting with 2 OBLISTs");
            }

            if (args.Length == 0)
            {
                return(ctx.TRUE);
            }

            var obpathList = obpath.ToList();

            foreach (var packageName in args)
            {
                if (!ctx.PackageObList.Contains(packageName))
                {
                    // try loading from file
                    PerformLoadFile(ctx, packageName, name);  // throws on failure
                }

                ObList externalObList = null;
                if (ctx.PackageObList.Contains(packageName))
                {
                    var packageNameAtom = ctx.PackageObList[packageName];
                    externalObList = ctx.GetProp(packageNameAtom, ctx.GetStdAtom(StdAtom.OBLIST)) as ObList;
                }

                if (externalObList == null)
                {
                    throw new InterpreterError(InterpreterMessages._0_Unrecognized_1_2, name, "package", packageName);
                }

                if (!(ctx.GetProp(externalObList, ctx.GetStdAtom(StdAtom.PACKAGE)) is ZilAtom pkgTypeAtom) ||
                    pkgTypeAtom.StdAtom != requiredPackageType)
                {
                    throw new InterpreterError(InterpreterMessages._0_Wrong_Package_Type_Expected_1, name, ctx.GetStdAtom(requiredPackageType).ToString());
                }

                if (!obpathList.Contains(externalObList))
                {
                    obpathList.Add(externalObList);
                }
            }

            ctx.SetLocalVal(ctx.GetStdAtom(StdAtom.OBLIST), new ZilList(obpathList));
            return(ctx.TRUE);
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new BuiltinTypeAttribute with the specified name and primitive type.
 /// </summary>
 /// <param name="name">The <see cref="StdAtom"/> representing the type name.</param>
 /// <param name="primType">The primitive type on which the type is based.</param>
 /// <remarks>A constructor or static method must be marked with
 /// <see cref="ChtypeMethodAttribute"/>.</remarks>
 public BuiltinTypeAttribute(StdAtom name, PrimType primType)
 {
     Name     = name;
     PrimType = primType;
 }
Beispiel #6
0
 public static Constraint OfType(StdAtom typeAtom) => new TypeConstraint(typeAtom);
Beispiel #7
0
 public TypeConstraint(StdAtom typeAtom)
 {
     TypeAtom = typeAtom;
 }
Beispiel #8
0
 public void VisitTypeConstraint(StdAtom type)
 {
     sb.Append(type.ToString().ToLowerInvariant());
 }
Beispiel #9
0
 public void VisitTypeConstraint(StdAtom type)
 {
     result = new JObject {
         ["constraint"] = "type", ["type"] = type.ToString()
     };
 }
Beispiel #10
0
 public void AddStdAtom([NotNull] string name, StdAtom stdAtom)
 {
     atoms.Add(name, new ZilAtom(name, null, stdAtom));
 }