Пример #1
0
        static ZilObject PerformDefine([NotNull][ProvidesContext] Context ctx, [NotNull] ZilAtom name,
                                       [CanBeNull] ZilAtom activationAtom,
                                       [NotNull] ZilList argList, ZilDecl decl, [NotNull] ZilObject[] body, [NotNull] string subrName)
        {
            if (!ctx.AllowRedefine && ctx.GetGlobalVal(name) != null)
            {
                throw new InterpreterError(InterpreterMessages._0_Already_Defined_1, subrName, name.ToStringContext(ctx, false));
            }

            var func = new ZilFunction(
                subrName,
                name,
                activationAtom,
                argList,
                decl,
                body);

            ctx.SetGlobalVal(name, func);
            return(name);
        }
Пример #2
0
        public static ZilObject DEFMAC([NotNull] Context ctx, [NotNull] ZilAtom name,
                                       [CanBeNull][Optional] ZilAtom activationAtom, [ItemNotNull][NotNull] ZilList argList,
                                       [CanBeNull][Optional] ZilDecl decl, [NotNull][Required] ZilObject[] body)
        {
            if (!ctx.AllowRedefine && ctx.GetGlobalVal(name) != null)
            {
                throw new InterpreterError(InterpreterMessages._0_Already_Defined_1, "DEFMAC", name.ToStringContext(ctx, false));
            }

            var func = new ZilFunction(
                "DEFMAC",
                name,
                activationAtom,
                argList,
                decl,
                body);
            var macro = new ZilEvalMacro(func)
            {
                SourceLine = ctx.TopFrame.SourceLine
            };

            ctx.SetGlobalVal(name, macro);
            return(name);
        }