Exemple #1
0
        public MatchModule()
        {
            AddWordHandler("()", compiler => compiler.Push(Unit.Value));

            // TODO: COMPLETE
            AddWordHandler("match", async compiler => {
                var value    = compiler.Pop();
                var patterns = compiler.TryPop <Ir.List>();
                if (patterns == null)
                {
                    throw new CompilerException("Match requires a list of patterns");
                }

                var vtype = value.Type;
                int size;
                if (value is Ir.List vlist)
                {
                    size = vlist.Count;
                }
                else if (vtype == typeof(Vec2))
                {
                    size = 2;
                }
                else if (vtype == typeof(Vec3))
                {
                    size = 3;
                }
                else if (vtype == typeof(Vec4))
                {
                    size = 4;
                }
                else
                {
                    size = -1;
                }

                var runtime     = false;
                Ir currentBlock = null;

                foreach (var(pattern, handler) in patterns.Where((_, i) => i % 2 == 0)
                         .Zip(patterns.Where((_, i) => i % 2 == 1)).Concat(patterns.Count % 2 == 0
                                                ? new (Ir, Ir)[0]
                                                : new[] { ((Ir)Unit.Value, patterns.Last()) }).Reverse())
Exemple #2
0
 public void Insert(int index, Ir item) => Elements.Insert(index, item);
Exemple #3
0
 public int IndexOf(Ir item) => Elements.IndexOf(item);
Exemple #4
0
 public bool Remove(Ir item) => Elements.Remove(item);
Exemple #5
0
 public bool Contains(Ir item) => Elements.Contains(item);
Exemple #6
0
 public void Add(Ir item) => Elements.Add(item);
Exemple #7
0
 public ValueToken(Ir value) : base(Location.Generated, Location.Generated, TokenType.Value, null, null) =>