internal override void GenSlurpBytes(CodeBuffer cb, string b, string s, string l) { cb.Append("{\n"); cb.Append("int i = org.apache.hadoop.record.Utils.readVInt(" + b + ", " + s + ");\n" ); cb.Append("int z = org.apache.hadoop.record.Utils.getVIntSize(i);\n"); cb.Append(s + "+=z; " + l + "-=z;\n"); cb.Append("}\n"); }
public override void Write(CodeBuffer buf) { buf.Append("case ").Append(Exp).AppendLine(" of"); buf.Indent(); foreach (var(pred, body) in Cases) { buf.Append(pred).AppendLine(" ->"); buf.Indented(() => buf.AppendLine(body)); } buf.DeIndent(); }
internal override void GenCompareBytes(CodeBuffer cb) { cb.Append("{\n"); cb.Append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n"); cb.Append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n"); cb.Append("if (i1 != i2) {\n"); cb.Append("return ((i1-i2) < 0) ? -1 : 0;\n"); cb.Append("}\n"); cb.Append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n"); cb.Append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n"); cb.Append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n"); cb.Append("}\n"); }
internal override void GenCompareBytes(CodeBuffer cb) { cb.Append("{\n"); cb.Append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n"); cb.Append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n"); cb.Append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n"); cb.Append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n"); cb.Append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n"); cb.Append("int r1 = org.apache.hadoop.record.Utils.compareBytes(b1,s1,i1,b2,s2,i2);\n" ); cb.Append("if (r1 != 0) { return (r1<0)?-1:0; }\n"); cb.Append("s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n"); cb.Append("}\n"); }
// In Binary format, boolean is written as byte. true = 1, false = 0 internal override void GenCompareBytes(CodeBuffer cb) { cb.Append("{\n"); cb.Append("if (l1<1 || l2<1) {\n"); cb.Append("throw new java.io.IOException(\"Boolean is exactly 1 byte." + " Provided buffer is smaller.\");\n" ); cb.Append("}\n"); cb.Append("if (b1[s1] != b2[s2]) {\n"); cb.Append("return (b1[s1]<b2[s2])? -1 : 0;\n"); cb.Append("}\n"); cb.Append("s1++; s2++; l1--; l2--;\n"); cb.Append("}\n"); }
public override void Write(CodeBuffer buf) { buf.Append("type ").Append(Name).AppendLine(" ="); buf.Indented(() => { for (var i = 0; i < Alternatives.Count; i++) { var altName = Alternatives[i]; if (i > 0) { buf.Append("| ").AppendLine(altName); } else { buf.Indented(() => buf.AppendLine(altName)); } } }); }
public override void Write(CodeBuffer buf) { for (var i = 0; i < Exprs.Count; i++) { var expr = Exprs[i]; if (i == 0) { buf.AppendLine(expr.ToString()); continue; } buf.Append("|> ").AppendLine(expr); } }
public override void Write(CodeBuffer buf) { buf.Append("type alias ").Append(Name).AppendLine(" ="); buf.Indented(() => { var i = 0; foreach (var field in Fields) { if (i == 0) { buf.Append("{ "); } else { buf.Append(", "); } buf.Append(field.Key).Append(" : ").AppendLine(field.Value); i++; } buf.AppendLine("}"); }); }
// In Binary format, boolean is written as byte. true = 1, false = 0 internal override void GenSlurpBytes(CodeBuffer cb, string b, string s, string l) { cb.Append("{\n"); cb.Append("if (" + l + "<1) {\n"); cb.Append("throw new java.io.IOException(\"Boolean is exactly 1 byte." + " Provided buffer is smaller.\");\n" ); cb.Append("}\n"); cb.Append(s + "++; " + l + "--;\n"); cb.Append("}\n"); }
internal override void GenSlurpBytes(CodeBuffer cb, string b, string s, string l) { cb.Append("{\n"); cb.Append("if (" + l + "<4) {\n"); cb.Append("throw new java.io.IOException(\"Float is exactly 4 bytes." + " Provided buffer is smaller.\");\n" ); cb.Append("}\n"); cb.Append(s + "+=4; " + l + "-=4;\n"); cb.Append("}\n"); }
internal override void GenGetSet(CodeBuffer cb, string fname) { cb.Append("virtual const " + this.GetType() + "& get" + JType.ToCamelCase(fname) + "() const {\n"); cb.Append("return " + fname + ";\n"); cb.Append("}\n"); cb.Append("virtual " + this.GetType() + "& get" + JType.ToCamelCase(fname) + "() {\n" ); cb.Append("return " + fname + ";\n"); cb.Append("}\n"); }
public override void Write(CodeBuffer buf) { buf.Append("( "); buf.Append(Elements.ConvertAll(e => e.ToString()).Join(", ")); buf.Append(" )"); }
public override void Write(CodeBuffer buf) { buf.Append(Rator).Append(" ").Append(string.Join(' ', Rands.ConvertAll(n => $"({n})"))); }
internal override void GenHashCode(CodeBuffer cb, string fname) { string tmp = "Double.doubleToLongBits(" + fname + ")"; cb.Append(Consts.RioPrefix + "ret = (int)(" + tmp + "^(" + tmp + ">>>32));\n"); }
internal override void GenHashCode(CodeBuffer cb, string fname) { cb.Append(Consts.RioPrefix + "ret = (" + fname + ")?0:1;\n"); }
internal override void GenCompareBytes(CodeBuffer cb) { cb.Append("{\n"); cb.Append("if (l1<4 || l2<4) {\n"); cb.Append("throw new java.io.IOException(\"Float is exactly 4 bytes." + " Provided buffer is smaller.\");\n" ); cb.Append("}\n"); cb.Append("float f1 = org.apache.hadoop.record.Utils.readFloat(b1, s1);\n"); cb.Append("float f2 = org.apache.hadoop.record.Utils.readFloat(b2, s2);\n"); cb.Append("if (f1 != f2) {\n"); cb.Append("return ((f1-f2) < 0) ? -1 : 0;\n"); cb.Append("}\n"); cb.Append("s1+=4; s2+=4; l1-=4; l2-=4;\n"); cb.Append("}\n"); }
internal override void GenClone(CodeBuffer cb, string fname) { cb.Append(Consts.RioPrefix + "other." + fname + " = (" + this.GetType() + ") this." + fname + ".clone();\n"); }
internal override void GenHashCode(CodeBuffer cb, string fname) { cb.Append(Consts.RioPrefix + "ret = Float.floatToIntBits(" + fname + ");\n"); }
internal override void GenCompareBytes(CodeBuffer cb) { cb.Append("{\n"); cb.Append("if (l1<8 || l2<8) {\n"); cb.Append("throw new java.io.IOException(\"Double is exactly 8 bytes." + " Provided buffer is smaller.\");\n" ); cb.Append("}\n"); cb.Append("double d1 = org.apache.hadoop.record.Utils.readDouble(b1, s1);\n"); cb.Append("double d2 = org.apache.hadoop.record.Utils.readDouble(b2, s2);\n"); cb.Append("if (d1 != d2) {\n"); cb.Append("return ((d1-d2) < 0) ? -1 : 0;\n"); cb.Append("}\n"); cb.Append("s1+=8; s2+=8; l1-=8; l2-=8;\n"); cb.Append("}\n"); }
internal override void GenHashCode(CodeBuffer cb, string fname) { cb.Append(Consts.RioPrefix + "ret = (int) (" + fname + "^(" + fname + ">>>32));\n" ); }
public override void Write(CodeBuffer buf) { buf.Append($"\"{Content}\""); }
public override void Write(CodeBuffer buf) { buf.Append(Name); }
internal override void GenCompareTo(CodeBuffer cb, string fname, string other) { cb.Append(Consts.RioPrefix + "ret = (" + fname + " == " + other + ")? 0 : (" + fname + "?1:-1);\n"); }
internal override void GenClone(CodeBuffer cb, string fname) { cb.Append(Consts.RioPrefix + "other." + fname + " = this." + fname + ";\n"); }
internal override void GenEquals(CodeBuffer cb, string fname, string peer) { cb.Append(Consts.RioPrefix + "ret = " + fname + ".equals(" + peer + ");\n"); }