Exemplo n.º 1
0
        protected override string Translate(Computation.Rand node, CLike.Context context)
        {
            if (node.Empty)
            {
                return("");
            }

            StringBuilder ret = new StringBuilder();

            foreach (Computation.Rand.IndexRange range in node.Ranges(context.Program.StateTable))
            {
                ret.AppendFormat("\tfor ({0} = {1}; i <= {2}; ++i)",
                                 context.DeclareValueVariable("int", "i"),
                                 range.Start,
                                 range.End);

                ret.AppendLine();
                ret.AppendLine("\t{");

                ret.AppendFormat("\t\t{0}[i] = Cdn.Math.rand();",
                                 context.This(context.Program.StateTable));
                ret.AppendLine();
                ret.AppendLine("\t}");
            }

            ret.Append("}");

            return(ret.ToString());
        }
Exemplo n.º 2
0
        protected override string Translate(Computation.Rand node, CLike.Context context)
        {
            if (node.Empty)
            {
                return("");
            }

            StringBuilder ret = new StringBuilder();

            ret.AppendLine("{");
            ret.AppendLine("\tint i;");
            ret.AppendLine();

            foreach (Computation.Rand.IndexRange range in node.Ranges(context.Program.StateTable))
            {
                ret.AppendFormat("\tfor (i = {0}; i <= {1}; ++i)", range.Start, range.End);
                ret.AppendLine();
                ret.AppendLine("\t{");

                if (Cdn.RawC.Options.Instance.Validate)
                {
                    if (context.Program.NodeIsInitialization(node))
                    {
                        ret.AppendLine();
                        ret.AppendFormat("\t\tinitstate (rand_seeds[i - {0}], rand_states[i - {0}], sizeof(RandState));",
                                         range.ZeroOffset);
                    }
                    else
                    {
                        ret.AppendFormat("\t\tsetstate (rand_states[i - {0}]);", range.ZeroOffset);
                    }

                    ret.AppendLine();
                }

                ret.AppendFormat("\t\t{0}[i] = CDN_MATH_RAND ();",
                                 context.Program.StateTable.Name);
                ret.AppendLine();
                ret.AppendLine("\t}");
            }

            ret.Append("}");

            return(ret.ToString());
        }
Exemplo n.º 3
0
 protected virtual string Translate(Computation.Rand node, Context context)
 {
     throw new Exception("Random numbers are not supporter for this format.");
 }