コード例 #1
0
 public ArgItem(ZilAtom atom, bool quoted, ZilObject defaultValue, ArgType type)
 {
     Atom         = atom;
     Quoted       = quoted;
     DefaultValue = defaultValue;
     Type         = type;
 }
コード例 #2
0
        public void TestINSERT()
        {
            // must have 2 args
            TestHelpers.EvalAndCatch <ArgumentCountError>("<INSERT>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<INSERT FOO>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<INSERT FOO BAR BAZ>");

            // 1st arg must be atom or string
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<INSERT 1 <ROOT>>");

            // 2nd arg must be oblist
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<INSERT FOO BAR>");

            // insert a new atom by name
            TestHelpers.EvalAndAssert("<SPNAME <INSERT \"FOO\" <ROOT>>>", ZilString.FromString("FOO"));

            // insert an atom currently on no oblist
            var ctx     = new Context();
            var newAtom = new ZilAtom("NEW-ATOM", null, StdAtom.None);

            ctx.SetLocalVal(ctx.GetStdAtom(StdAtom.ATOM), newAtom);
            TestHelpers.EvalAndAssert(ctx, "<INSERT .ATOM <MOBLIST BAR>>", newAtom);
            TestHelpers.EvalAndAssert(ctx, "NEW-ATOM!-BAR", newAtom);

            // can't insert an atom that's already on an oblist
            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<INSERT .ATOM <ROOT>>");

            // can't clobber an atom already in the oblist
            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<INSERT \"BAR\" <1 .OBLIST>>");
        }
コード例 #3
0
        public void TestSynonyms()
        {
            var ctx    = new Context();
            var syntax = ParseSyntax(ctx, "(LOOK (STARE GAZE) AT OBJECT = V-EXAMINE)");

            Assert.AreEqual("LOOK", syntax.Verb.Atom.ToString());
            Assert.IsTrue(ctx.ZEnvironment.VocabFormat.IsVerb(syntax.Verb));

            Assert.AreEqual(1, syntax.NumObjects);
            Assert.IsNotNull(syntax.Preposition1);
            Assert.AreEqual("AT", syntax.Preposition1.Atom.ToString());
            Assert.IsTrue(ctx.ZEnvironment.VocabFormat.IsPreposition(syntax.Preposition1));
            Assert.IsNull(syntax.FindFlag1);
            Assert.AreEqual(ScopeFlags.Original.Default, syntax.Options1);
            Assert.IsNull(syntax.Preposition2);
            Assert.IsNull(syntax.FindFlag2);
            Assert.AreEqual(ScopeFlags.Original.Default, syntax.Options2);

            Assert.AreEqual("V-EXAMINE", syntax.Action.ToString());
            Assert.IsNull(syntax.Preaction);
            Assert.AreEqual("V?EXAMINE", syntax.ActionName.ToString());

            Assert.AreEqual(2, syntax.Synonyms.Count);
            TestHelpers.AssertStructurallyEqual(ZilAtom.Parse("STARE", ctx), syntax.Synonyms[0]);
            TestHelpers.AssertStructurallyEqual(ZilAtom.Parse("GAZE", ctx), syntax.Synonyms[1]);
        }
コード例 #4
0
 public Operands([NotNull] Compilation compilation, [NotNull] IOperand[] values, [NotNull] bool[] temps, [NotNull] ZilAtom tempAtom)
 {
     this.compilation = compilation;
     this.values      = values;
     this.temps       = temps;
     this.tempAtom    = tempAtom;
 }
コード例 #5
0
        public void TestBOUND_P()
        {
            var ctx = new Context();

            var whatever = new ZilFix(123);

            ctx.SetGlobalVal(ZilAtom.Parse("MY-TEST-GLOBAL", ctx), whatever);
            ctx.SetLocalVal(ZilAtom.Parse("MY-TEST-LOCAL", ctx), whatever);

            TestHelpers.EvalAndAssert(ctx, "<BOUND? MY-TEST-GLOBAL>", ctx.FALSE);
            TestHelpers.EvalAndAssert(ctx, "<BOUND? MY-TEST-LOCAL>", ctx.TRUE);
            TestHelpers.EvalAndAssert(ctx, "<BOUND? THIS-ATOM-HAS-NO-GVAL-OR-LVAL>", ctx.FALSE);

            TestHelpers.Evaluate(ctx, "<UNASSIGN MY-TEST-GLOBAL>");
            TestHelpers.EvalAndAssert(ctx, "<BOUND? MY-TEST-GLOBAL>", ctx.TRUE);

            TestHelpers.EvalAndAssert(ctx, "<PROG (FOO) <BOUND? FOO>>", ctx.TRUE);
            TestHelpers.EvalAndAssert(ctx, "<BOUND? FOO>", ctx.FALSE);

            // must have 1-2 arguments
            TestHelpers.EvalAndCatch <ArgumentCountError>("<BOUND?>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<BOUND? FOO BAR BAZ>");

            // 1st argument must be an atom
            TestHelpers.EvalAndCatch <InterpreterError>("<BOUND? \"FOO\">");

            // 2nd argument must be an ENVIRONMENT
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<BOUND? FOO BAR>");

            TestHelpers.EvalAndAssert(ctx,
                                      @"<DEFINE FOO (""AUX"" (X 123)) <BAR>>" +
                                      @"<DEFINE BAR (""BIND"" ENV ""AUX"" (Y 456)) (<BOUND? X> <BOUND? X .ENV> <BOUND? Y> <BOUND? Y .ENV>)>" +
                                      @"<FOO>",
                                      new ZilList(new[] { ctx.TRUE, ctx.TRUE, ctx.TRUE, ctx.FALSE }));
        }
コード例 #6
0
        public void TestUNASSIGN()
        {
            var ctx = new Context();

            var foo = ZilAtom.Parse("FOO", ctx);

            ctx.SetLocalVal(foo, new ZilFix(123));

            TestHelpers.Evaluate(ctx, "<UNASSIGN FOO>");
            TestHelpers.EvalAndAssert(ctx, "<ASSIGNED? FOO>", ctx.FALSE);
            TestHelpers.EvalAndCatch <InterpreterError>("<LVAL FOO>");

            // must have 1-2 arguments
            TestHelpers.EvalAndCatch <ArgumentCountError>("<UNASSIGN>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<UNASSIGN FOO BAR BAZ>");

            // 1st argument must be an atom
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<UNASSIGN \"FOO\">");

            // 2nd argument must be an ENVIRONMENT
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<UNASSIGN FOO BAR>");

            TestHelpers.EvalAndAssert(ctx,
                                      @"<DEFINE FOO (""AUX"" (X 123)) <BAR> <ASSIGNED? X>>" +
                                      @"<DEFINE BAR (""BIND"" ENV ""AUX"" (X 456)) <UNASSIGN X .ENV>>" +
                                      @"<FOO>",
                                      ctx.FALSE);
        }
コード例 #7
0
 public ZilGlobal([NotNull] ZilAtom name, [CanBeNull] ZilObject value, GlobalStorageType storageType = GlobalStorageType.Any)
 {
     Name        = name;
     Value       = value;
     StorageType = storageType;
     IsWord      = true;
 }
コード例 #8
0
        public void TestSET()
        {
            var ctx = new Context();

            var expected = new ZilFix(123);

            TestHelpers.EvalAndAssert(ctx, "<SET FOO 123>", expected);

            var stored = ctx.GetLocalVal(ZilAtom.Parse("FOO", ctx));

            TestHelpers.AssertStructurallyEqual(expected, stored);

            // must have 2-3 arguments
            TestHelpers.EvalAndCatch <ArgumentCountError>("<SET>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<SET FOO>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<SET FOO BAR BAZ QUUX>");

            // 1st argument must be an atom
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<SET \"FOO\" 5>");

            // 3rd argument must be an ENVIRONMENT
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<SET FOO 123 BAR>");

            TestHelpers.EvalAndAssert(
                @"<DEFINE FOO (""AUX"" (X 123)) <BAR> <* .X 2>>" +
                @"<DEFINE BAR (""BIND"" ENV ""AUX"" (X 456)) <SET X 10 .ENV>>" +
                @"<FOO>",
                new ZilFix(20));
        }
コード例 #9
0
        public Syntax(ISourceLine src, [NotNull] IWord verb, int numObjects, [CanBeNull] IWord prep1, [CanBeNull] IWord prep2,
                      byte options1, byte options2, [CanBeNull] ZilAtom findFlag1, [CanBeNull] ZilAtom findFlag2,
                      [NotNull] ZilAtom action, [CanBeNull] ZilAtom preaction, [NotNull] ZilAtom actionName,
                      [ItemNotNull][CanBeNull] IEnumerable <ZilAtom> synonyms = null)
        {
            SourceLine = src;

            Verb         = verb;
            NumObjects   = numObjects;
            Preposition1 = prep1;
            Preposition2 = prep2;
            Options1     = options1;
            Options2     = options2;
            FindFlag1    = findFlag1;
            FindFlag2    = findFlag2;
            Action       = action;
            Preaction    = preaction;
            ActionName   = actionName;

            if (synonyms == null)
            {
                Synonyms = EmptySynonyms;
            }
            else
            {
                Synonyms = new List <ZilAtom>(synonyms).AsReadOnly();
            }
        }
コード例 #10
0
        public void TestVALUE()
        {
            var ctx = new Context();
            var foo = ZilAtom.Parse("FOO", ctx);

            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<VALUE FOO>");

            ctx.SetGlobalVal(foo, new ZilFix(123));
            TestHelpers.EvalAndAssert(ctx, "<VALUE FOO>", new ZilFix(123));

            ctx.SetLocalVal(foo, new ZilFix(456));
            TestHelpers.EvalAndAssert(ctx, "<VALUE FOO>", new ZilFix(456));

            ctx.SetLocalVal(foo, null);
            TestHelpers.EvalAndAssert(ctx, "<VALUE FOO>", new ZilFix(123));

            ctx.SetGlobalVal(foo, null);
            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<VALUE FOO>");

            // must have 1-2 arguments
            TestHelpers.EvalAndCatch <ArgumentCountError>(ctx, "<VALUE>");
            TestHelpers.EvalAndCatch <ArgumentCountError>(ctx, "<VALUE FOO BAR BAZ>");

            // 1st argument must be an atom
            TestHelpers.EvalAndCatch <ArgumentTypeError>(ctx, "<VALUE 0>");

            // 2nd argument must be an ENVIRONMENT
            TestHelpers.EvalAndCatch <ArgumentTypeError>(ctx, "<VALUE FOO BAR>");

            TestHelpers.EvalAndAssert(
                @"<DEFINE FOO (""AUX"" (X 123)) <BAR>>" +
                @"<DEFINE BAR (""BIND"" ENV ""AUX"" (X 456)) <+ <VALUE X> <VALUE X .ENV>>>" +
                @"<FOO>",
                new ZilFix(579));
        }
コード例 #11
0
        public void TestPUTREST()
        {
            var ctx = new Context();

            TestHelpers.EvalAndAssert(ctx, "<PUTREST '(1 2 3) '(A B)>",
                                      new ZilList(new ZilObject[] {
                new ZilFix(1),
                ZilAtom.Parse("A", ctx),
                ZilAtom.Parse("B", ctx)
            }));

            TestHelpers.EvalAndAssert(ctx, "<PUTREST '<1 2 3> '(A B)>",
                                      new ZilForm(new ZilObject[] {
                new ZilFix(1),
                ZilAtom.Parse("A", ctx),
                ZilAtom.Parse("B", ctx)
            }));

            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<PUTREST <ASSOCIATIONS> '()>",
                                                        ex => !(ex is ArgumentDecodingError));

            TestHelpers.EvalAndCatch <ArgumentTypeError>("<PUTREST [1 2] [FOO]>");

            TestHelpers.EvalAndCatch <InterpreterError>("<PUTREST () (5)>");
        }
コード例 #12
0
        public void TestGBOUND_P()
        {
            var ctx = new Context();

            var whatever = new ZilFix(123);

            ctx.SetGlobalVal(ZilAtom.Parse("MY-TEST-GLOBAL", ctx), whatever);
            ctx.SetLocalVal(ZilAtom.Parse("MY-TEST-LOCAL", ctx), whatever);

            TestHelpers.EvalAndAssert(ctx, "<GBOUND? MY-TEST-GLOBAL>", ctx.TRUE);
            TestHelpers.EvalAndAssert(ctx, "<GBOUND? MY-TEST-LOCAL>", ctx.FALSE);
            TestHelpers.EvalAndAssert(ctx, "<GBOUND? THIS-ATOM-HAS-NO-GVAL-OR-LVAL>", ctx.FALSE);

            TestHelpers.Evaluate(ctx, "<GUNASSIGN MY-TEST-GLOBAL>");
            TestHelpers.EvalAndAssert(ctx, "<GBOUND? MY-TEST-GLOBAL>", ctx.TRUE);

            TestHelpers.Evaluate(ctx, "<GDECL (ANOTHER-TEST-GLOBAL) ANY>");
            TestHelpers.EvalAndAssert(ctx, "<GBOUND? ANOTHER-TEST-GLOBAL>", ctx.TRUE);

            // TODO: test after GLOC

            // must have 1 argument
            TestHelpers.EvalAndCatch <InterpreterError>("<GBOUND?>");
            TestHelpers.EvalAndCatch <InterpreterError>("<GBOUND? FOO BAR>");

            // argument must be an atom
            TestHelpers.EvalAndCatch <InterpreterError>("<GBOUND? \"FOO\">");
        }
コード例 #13
0
        public static ZilResult REPLACE_DEFINITION([NotNull] Context ctx, [NotNull] ZilAtom name, [NotNull][Required] ZilObject[] body)
        {
            name = ctx.ZEnvironment.InternGlobalName(name);

            var replaceAtom = ctx.GetStdAtom(StdAtom.REPLACE_DEFINITION);
            var state       = ctx.GetProp(name, replaceAtom);

            if (state == null)
            {
                // store the replacement now, insert it at the DEFAULT-DEFINITION
                ctx.PutProp(name, replaceAtom, new ZilVector(body));
                return(name);
            }

            if (state == ctx.GetStdAtom(StdAtom.DELAY_DEFINITION))
            {
                // insert the replacement now
                ctx.PutProp(name, replaceAtom, replaceAtom);
                return(ZilObject.EvalProgram(ctx, body));
            }

            if (state == replaceAtom || state == ctx.GetStdAtom(StdAtom.DEFAULT_DEFINITION))
            {
                throw new InterpreterError(InterpreterMessages._0_Section_Has_Already_Been_Inserted_1, "REPLACE-DEFINITION", name);
            }

            if (state is ZilVector)
            {
                throw new InterpreterError(InterpreterMessages._0_Duplicate_Replacement_For_Section_1, "REPLACE-DEFINITION", name);
            }

            throw new InterpreterError(InterpreterMessages._0_Bad_State_1, "REPLACE-DEFINITION", state);
        }
コード例 #14
0
        static bool IsNonCircularAlias([NotNull] Context ctx, [NotNull] ZilAtom atom, out ZilObject decl)
        {
            var       seen     = new HashSet <ZilAtom>();
            var       declAtom = ctx.GetStdAtom(StdAtom.DECL);
            ZilObject value;

            do
            {
                seen.Add(atom);

                value = ctx.GetProp(atom, declAtom);
                atom  = value as ZilAtom;
            } while (atom != null && !seen.Contains(atom));

            if (atom != null)
            {
                // circular
                decl = null;
                return(false);
            }

            // noncircular, or not an alias
            decl = value;
            return(value != null);
        }
コード例 #15
0
        public void TestLVAL()
        {
            var ctx = new Context();

            var expected = new ZilFix(123);

            ctx.SetLocalVal(ZilAtom.Parse("FOO", ctx), expected);
            var actual = TestHelpers.Evaluate(ctx, "<LVAL FOO>");

            TestHelpers.AssertStructurallyEqual(expected, actual);

            // fails when undefined
            TestHelpers.EvalAndCatch <InterpreterError>("<LVAL TESTING-TESTING-THIS-ATOM-HAS-NO-LVAL>");

            // must have 1-2 arguments
            TestHelpers.EvalAndCatch <ArgumentCountError>("<LVAL>");
            TestHelpers.EvalAndCatch <ArgumentCountError>("<LVAL FOO BAR BAZ>");

            // 1st argument must be an atom
            TestHelpers.EvalAndCatch <InterpreterError>("<LVAL \"FOO\">");

            // 2nd argument must be an ENVIRONMENT
            TestHelpers.EvalAndCatch <ArgumentTypeError>("<LVAL FOO BAR>");

            TestHelpers.EvalAndAssert(
                @"<DEFINE FOO (""AUX"" (X 123)) <BAR>>" +
                @"<DEFINE BAR (""BIND"" ENV ""AUX"" (X 456)) <+ .X <LVAL X .ENV>>>" +
                @"<FOO>",
                new ZilFix(579));
        }
コード例 #16
0
        public void TestDEFINE()
        {
            var ctx = new Context();

            var expected = ZilAtom.Parse("FOO", ctx);

            TestHelpers.EvalAndAssert(ctx, "<DEFINE FOO (BAR) <> <> <>>", expected);

            var stored = ctx.GetGlobalVal(expected);

            Assert.IsInstanceOfType(stored, typeof(ZilFunction));

            // it's OK to redefine if .REDEFINE is true
            ctx.SetLocalVal(ctx.GetStdAtom(StdAtom.REDEFINE), ctx.TRUE);
            TestHelpers.EvalAndAssert(ctx, "<DEFINE FOO (REDEF1) <>>", expected);

            // ...but it's an error if false
            ctx.SetLocalVal(ctx.GetStdAtom(StdAtom.REDEFINE), null);
            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<DEFINE FOO (REDEF2) <>>");

            // must have at least 3 arguments
            TestHelpers.EvalAndCatch <InterpreterError>("<DEFINE>");
            TestHelpers.EvalAndCatch <InterpreterError>("<DEFINE FOO>");
            TestHelpers.EvalAndCatch <InterpreterError>("<DEFINE FOO (BAR)>");
        }
コード例 #17
0
        public void GetProp_Should_Return_Value_Stored_By_PutProp()
        {
            var ctx = new Context();

            TestHelpers.EvalAndAssert(ctx, "<PUTPROP FOO BAR 123>", ZilAtom.Parse("FOO", ctx));
            TestHelpers.EvalAndAssert(ctx, "<GETPROP FOO BAR>", new ZilFix(123));
        }
コード例 #18
0
        public void TestASSOCIATIONS_Et_Al()
        {
            var ctx = new Context();

            TestHelpers.EvalAndCatch <ArgumentCountError>(ctx, "<ASSOCIATIONS FOO>");

            // there should be some initial associations
            var zo = TestHelpers.Evaluate(ctx, "<ASSOCIATIONS>");

            Assert.IsInstanceOfType(zo, typeof(ZilAsoc));

            // clear all associations
            TestHelpers.Evaluate(ctx,
                                 @"<REPEAT ((A <ASSOCIATIONS>) N)
                    <OR .A <RETURN>>
                    <SET N <NEXT .A>>
                    <PUTPROP <ITEM .A> <INDICATOR .A>>
                    <SET A .N>>");

            // no more associations
            TestHelpers.EvalAndAssert(ctx, "<ASSOCIATIONS>", ctx.FALSE);

            // set one
            TestHelpers.Evaluate(ctx, "<PUTPROP FOO BAR BAZ>");

            // verify
            TestHelpers.EvalAndAssert(ctx, "<TYPE <SET A <ASSOCIATIONS>>>", ctx.GetStdAtom(StdAtom.ASOC));
            TestHelpers.EvalAndAssert(ctx, "<ITEM .A>", ZilAtom.Parse("FOO", ctx));
            TestHelpers.EvalAndAssert(ctx, "<INDICATOR .A>", ZilAtom.Parse("BAR", ctx));
            TestHelpers.EvalAndAssert(ctx, "<AVALUE .A>", ZilAtom.Parse("BAZ", ctx));
            TestHelpers.EvalAndAssert(ctx, "<NEXT .A>", ctx.FALSE);
        }
コード例 #19
0
        public void MakeSynonym(IWord synonym, IWord original)
        {
            var nsyn = (NewParserWord)synonym;

            nsyn.Classification = 0;
            nsyn.Flags          = 0;
            nsyn.SemanticStuff  = ZilAtom.Parse("W?" + original.Atom.Text, ctx);
        }
コード例 #20
0
 void DefineFlagAlias([NotNull] ZilAtom alias, [NotNull] ZilAtom original)
 {
     if (!Flags.ContainsKey(alias))
     {
         var fb = Flags[original];
         Constants.Add(alias, fb);
     }
 }
コード例 #21
0
 public static ZilResult PROG([NotNull] Context ctx,
                              [CanBeNull][Optional] ZilAtom activationAtom,
                              BindingParams.BindingList bindings,
                              [CanBeNull][Optional] ZilDecl bodyDecl,
                              [NotNull][Required] ZilObject[] body)
 {
     return(PerformProg(ctx, activationAtom, bindings, bodyDecl, body, "PROG", false, true));
 }
コード例 #22
0
        public void PutProp_Should_Return_Old_Value_When_Clearing()
        {
            var ctx = new Context();

            TestHelpers.EvalAndAssert(ctx, "<PUTPROP FOO BAR 123>", ZilAtom.Parse("FOO", ctx));
            TestHelpers.EvalAndAssert(ctx, "<PUTPROP FOO BAR>", new ZilFix(123));
            TestHelpers.EvalAndAssert(ctx, "<GETPROP FOO BAR>", ctx.FALSE);
        }
コード例 #23
0
 public ZilRoutine([CanBeNull] ZilAtom name, [CanBeNull] ZilAtom activationAtom,
                   [NotNull] IEnumerable <ZilObject> argspec, [ItemNotNull][NotNull] IEnumerable <ZilObject> body, RoutineFlags flags)
 {
     Name      = name;
     ArgSpec   = ArgSpec.Parse("ROUTINE", name, activationAtom, argspec);
     this.body = body.ToArray();
     Flags     = flags;
 }
コード例 #24
0
 public static ZilObject APPLYTYPE([NotNull] Context ctx, [NotNull] ZilAtom atom,
                                   [CanBeNull][Decl("<OR ATOM APPLICABLE>")] ZilObject handler = null)
 {
     return(PerformTypeHandler(ctx, atom, handler,
                               "APPLYTYPE",
                               (c, a) => c.GetApplyType(a),
                               (c, a, h) => c.SetApplyType(a, h)));
 }
コード例 #25
0
 public Loop(BoundedLoopContext blc, ZilAtom atom, ZilObject start, ZilObject end, ZilObject inc)
     : base(blc)
 {
     this.atom  = atom;
     this.start = start;
     this.end   = end;
     this.inc   = inc;
 }
コード例 #26
0
        static ZilObject MakeDefstructAccessMacro([NotNull] Context ctx, [NotNull] ZilAtom structName, DefStructDefaults defaults,
                                                  DefStructField field)
        {
            // {0} = field name
            // {1} = struct name
            // {2} = PUT atom
            // {3} = NTH atom
            // {4} = offset
            // {5} = field decl
            const string SFullCheckTemplate  = @"
<DEFMAC {0} ('S ""OPT"" 'NV)
    <COND (<ASSIGNED? NV>
           <FORM {2} <CHTYPE [.S {1}] ADECL> {4} <CHTYPE [.NV <QUOTE {5}>] ADECL>>)
          (T
           <CHTYPE [<FORM {3} <CHTYPE [.S {1}] ADECL> {4}> <QUOTE {5}>] ADECL>)>>
";
            const string SFieldCheckTemplate = @"
<DEFMAC {0} ('S ""OPT"" 'NV)
    <COND (<ASSIGNED? NV>
           <FORM {2} .S {4} <CHTYPE [.NV <QUOTE {5}>] ADECL>>)
          (T
           <CHTYPE [<FORM {3} .S {4}> <QUOTE {5}>] ADECL>)>>
";
            const string SNoCheckTemplate    = @"
<DEFMAC {0} ('S ""OPT"" 'NV)
    <COND (<ASSIGNED? NV>
           <FORM {2} .S {4} .NV>)
          (T
           <FORM {3} .S {4}>)>>
";

            string template;

            if (defaults.SuppressDecl)
            {
                template = SNoCheckTemplate;
            }
            else if (defaults.SuppressType)
            {
                template = SFieldCheckTemplate;
            }
            else
            {
                template = SFullCheckTemplate;
            }

            return(Program.Parse(
                       ctx,
                       template,
                       field.Name,
                       structName,
                       field.PutFunc,
                       field.NthFunc,
                       new ZilFix(field.Offset),
                       field.Decl)
                   .Single());
        }
コード例 #27
0
 public OutputElement(OutputElementType type, ZilAtom constant, [CanBeNull] ZilAtom variable = null,
                      [CanBeNull] ZilAtom partOfSpeech = null, [CanBeNull] ZilFix fix = null)
 {
     Type         = type;
     Constant     = constant;
     Variable     = variable;
     PartOfSpeech = partOfSpeech;
     Fix          = fix;
 }
コード例 #28
0
        public static ZilObject TYPEPRIM([NotNull] Context ctx, [NotNull] ZilAtom type)
        {
            if (!ctx.IsRegisteredType(type))
            {
                throw new InterpreterError(InterpreterMessages._0_Unrecognized_1_2, "TYPEPRIM", "type", type.ToStringContext(ctx, false));
            }

            return(ctx.GetStdAtom(PrimTypeToType(ctx.GetTypePrim(type))));
        }
コード例 #29
0
        public void Test_PUT_DECL()
        {
            // <PUT-DECL atom decl> establishes an alias for the decl
            TestHelpers.EvalAndCatch <InterpreterError>(ctx, "<DECL? T BOOLEAN>");
            TestHelpers.EvalAndAssert(ctx, "<PUT-DECL BOOLEAN '<OR ATOM FALSE>>", ZilAtom.Parse("BOOLEAN", ctx));
            TestHelpers.EvalAndAssert(ctx, "<DECL? T BOOLEAN>", ctx.TRUE);

            // StructureTests.TestOFFSET tests GET-DECL for OFFSETs
        }
コード例 #30
0
        static ZilFix TranslateType([NotNull] Context ctx, [NotNull] ZilAtom type)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (type.StdAtom)
            {
            case StdAtom.TADJ:
                type = ctx.GetStdAtom(StdAtom.ADJ);
                break;

            case StdAtom.TOBJECT:
                type = ctx.GetStdAtom(StdAtom.NOUN);
                break;

            case StdAtom.TPREP:
                type = ctx.GetStdAtom(StdAtom.PREP);
                break;

            case StdAtom.TDIR:
                type = ctx.GetStdAtom(StdAtom.DIR);
                break;

            case StdAtom.TVERB:
                type = ctx.GetStdAtom(StdAtom.VERB);
                break;
            }

            ZilFix classification;

            switch (type.StdAtom)
            {
            case StdAtom.BUZZ:
            case StdAtom.TBUZZ:
            case StdAtom.TZERO:
                classification = ZilFix.Zero;
                break;

            default:
                // call user-provided <GET-CLASSIFICATION type>
                var form = new ZilForm(new ZilObject[]
                {
                    ctx.GetStdAtom(StdAtom.GET_CLASSIFICATION),
                    type
                });

                classification = (ZilObject)form.Eval(ctx) as ZilFix;

                if (classification == null)
                {
                    throw new InterpreterError(InterpreterMessages._0_1_Must_Return_2, "NEW-ADD-WORD", "GET-CLASSIFICATION", "a FIX");
                }

                break;
            }

            return(classification);
        }