Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

newclay/lib-clay printing: printlnTo, printlnReprTo with-newline conv…

…enience functions; print, printRepr, println, printlnRepr to-stdout conveniences
  • Loading branch information...
commit 0e10e7903c1dfb5094167209cca7d5dfdf506003 1 parent 426b690
@jckarter jckarter authored
View
23 newclay/lib-clay/printing/printing.clay
@@ -1,5 +1,6 @@
import containers.(Container?);
import ctypes.(CChar, CString, CInt, CUInt);
+import io.stdio.(stdout);
import libc.stdio.(sprintf);
import meta.statics.(staticString?, staticStringConcat, staticInt?, staticName);
import strings.(String, String?);
@@ -43,6 +44,10 @@ overload printTo(ref sink:'S, forward ..objects) inline | PrintableSink?('S) {
printObject(sink, object);
}
+printlnTo(ref sink, forward ..objects) inline {
+ printTo(sink, ..objects, '\n');
+}
+
printReprTo(ref seq:'S, forward ..objects) inline | PrintableSinkSequence?('S) {
var seqSink = sink(seq);
printTo(seqSink, ..objects);
@@ -56,6 +61,24 @@ overload printReprTo(ref sink:'S, forward o1, forward ..os) inline | PrintableSi
}
overload printReprTo(ref sink:'S) inline | PrintableSink?('S) {}
+printlnReprTo(ref sink, forward ..objects) inline {
+ printReprTo(sink, ..objects);
+ printObject(sink, '\n');
+}
+
+print(forward ..objects) inline {
+ printTo(stdout, ..objects);
+}
+println(forward ..objects) inline {
+ printlnTo(stdout, ..objects);
+}
+printRepr(forward ..objects) inline {
+ printReprTo(stdout, ..objects);
+}
+printlnRepr(forward ..objects) inline {
+ printlnReprTo(stdout, ..objects);
+}
+
str['S](forward ..objects) inline {
var s = 'S();
printTo(s, ..objects);
View
8 newclay/test/printing/DefaultRepr/main.clay
@@ -1,5 +1,4 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(println, printlnRepr);
import unsafe.compositetypes.(CompositeType, initializeRecord);
import unsafe.valuesemantics.(destroy);
@@ -8,7 +7,6 @@ overload Unprintable() = initializeRecord(Unprintable);
overload destroy(ref x:Unprintable) {}
main() {
- printTo(stdout, Unprintable(), '\n');
- printReprTo(stdout, Unprintable());
- printTo(stdout, '\n');
+ println(Unprintable());
+ printlnRepr(Unprintable());
}
View
15 newclay/test/printing/MaybeRepr/main.clay
@@ -1,15 +1,10 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(printlnRepr);
import variants.(VariantType);
main() {
- printReprTo(stdout, just(1));
- printTo(stdout, '\n');
- printReprTo(stdout, nothing(Int));
- printTo(stdout, '\n');
- printReprTo(stdout, null(Int));
- printTo(stdout, '\n');
- printReprTo(stdout, nullOpaque());
- printTo(stdout, '\n');
+ printlnRepr(just(1));
+ printlnRepr(nothing(Int));
+ printlnRepr(null(Int));
+ printlnRepr(nullOpaque());
}
View
6 newclay/test/printing/NewTypeRepr/main.clay
@@ -1,10 +1,8 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(printlnRepr);
symbol Foo = NewType(Int);
main() {
- printReprTo(stdout, Foo(1));
- printTo(stdout, '\n');
+ printlnRepr(Foo(1));
}
View
65 newclay/test/printing/PrimitivesRepr/main.clay
@@ -1,50 +1,33 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(println, printlnRepr);
main() {
- printTo(stdout, "booleans:\n");
- printReprTo(stdout, true, false);
- printTo(stdout, "\n");
+ println("booleans:");
+ printlnRepr(true, false);
- printTo(stdout, "ascii characters:\n");
- printReprTo(stdout, '\x00', '\x1F', ' ', '\n', '\r', '\t', '\'', 'A', 'z', '\x7F');
- printTo(stdout, "\n");
+ println("ascii characters:");
+ printlnRepr('\x00', '\x1F', ' ', '\n', '\r', '\t', '\'', 'A', 'z', '\x7F');
- printTo(stdout, "unicode code points:\n");
- printReprTo(stdout, '\x80', '\xFF', '\u000100', '\u10FFFF');
- printTo(stdout, "\n");
+ println("unicode code points:");
+ printlnRepr('\x80', '\xFF', '\u000100', '\u10FFFF');
- printTo(stdout, "integers:\n");
- printReprTo(stdout, -0x8000_0000, 0, 1, 0x7FFF_FFFF);
- printTo(stdout, "\n");
- printReprTo(stdout, -128i8, 127i8, -32768i16, 32767i16);
- printTo(stdout, "\n");
- printReprTo(stdout, -0x8000_0000i32, 0x7FFF_FFFFi32);
- printTo(stdout, "\n");
- printReprTo(stdout, -0x8000_0000_0000_0000i64, 0x7FFF_FFFF_FFFF_FFFFi64);
- printTo(stdout, "\n");
- printReprTo(stdout, 255u8, 65535u16, 0xFFFF_FFFFu32, 0xFFFF_FFFF_FFFF_FFFFu64);
- printTo(stdout, "\n");
+ println("integers:");
+ printlnRepr(-0x8000_0000, 0, 1, 0x7FFF_FFFF);
+ printlnRepr(-128i8, 127i8, -32768i16, 32767i16);
+ printlnRepr(-0x8000_0000i32, 0x7FFF_FFFFi32);
+ printlnRepr(-0x8000_0000_0000_0000i64, 0x7FFF_FFFF_FFFF_FFFFi64);
+ printlnRepr(255u8, 65535u16, 0xFFFF_FFFFu32, 0xFFFF_FFFF_FFFF_FFFFu64);
- printTo(stdout, "float32s:\n");
- printReprTo(stdout, -3.0f, -1.0f, -0.0f, 0.0f, 1.0f, 3.0f);
- printTo(stdout, "\n");
- printReprTo(stdout, -0x0.000002p-126f, -0x1.FFFFFEp127f);
- printTo(stdout, "\n");
- printReprTo(stdout, 0x0.000002p-126f, 0x1.FFFFFEp127f);
- printTo(stdout, "\n");
+ println("float32s:");
+ printlnRepr(-3.0f, -1.0f, -0.0f, 0.0f, 1.0f, 3.0f);
+ printlnRepr(-0x0.000002p-126f, -0x1.FFFFFEp127f);
+ printlnRepr( 0x0.000002p-126f, 0x1.FFFFFEp127f);
- printTo(stdout, "float64s:\n");
- printReprTo(stdout, -3.0, -1.0, -0.0, 0.0, 1.0, 3.0);
- printTo(stdout, "\n");
- printReprTo(stdout, -0x0.0000_0000_0000_1p-1022, -0x1.FFFF_FFFF_FFFF_Fp1023);
- printTo(stdout, "\n");
- printReprTo(stdout, 0x0.0000_0000_0000_1p-1022, 0x1.FFFF_FFFF_FFFF_Fp1023);
- printTo(stdout, "\n");
+ println("float64s:");
+ printlnRepr(-3.0, -1.0, -0.0, 0.0, 1.0, 3.0);
+ printlnRepr(-0x0.0000_0000_0000_1p-1022, -0x1.FFFF_FFFF_FFFF_Fp1023);
+ printlnRepr( 0x0.0000_0000_0000_1p-1022, 0x1.FFFF_FFFF_FFFF_Fp1023);
- printTo(stdout, "statics:\n");
- printReprTo(stdout, #true, #100, #'x', #'\n', #"zombies\n");
- printTo(stdout, "\n");
- printReprTo(stdout, #Array, #Array[Int, 2], #prelude);
- printTo(stdout, "\n");
+ println("statics:");
+ printlnRepr(#true, #100, #'x', #'\n', #"zombies\n");
+ printlnRepr(#Array, #Array[Int, 2], #prelude);
}
View
15 newclay/test/printing/RecordRepr/main.clay
@@ -1,18 +1,13 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(printlnRepr);
symbol Empty = RecordType();
symbol Foo = RecordType(foo:Int, bar:Bool);
symbol Bar['T] = RecordType(foo:Int, bar:Bool, bas:'T);
main() {
- printReprTo(stdout, Empty());
- printTo(stdout, '\n');
- printReprTo(stdout, Foo(1, true));
- printTo(stdout, '\n');
- printReprTo(stdout, Bar[Char](1, true, '3'));
- printTo(stdout, '\n');
- printReprTo(stdout, Bar[StringConstant](1, true, "three"));
- printTo(stdout, '\n');
+ printlnRepr(Empty());
+ printlnRepr(Foo(1, true));
+ printlnRepr(Bar[Char](1, true, '3'));
+ printlnRepr(Bar[StringConstant](1, true, "three"));
}
View
17 newclay/test/printing/Statics/main.clay
@@ -1,13 +1,12 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(println);
main() {
- printTo(stdout, #"whimper", '\n');
- printTo(stdout, #'!', '\n');
- printTo(stdout, #100, '\n');
- printTo(stdout, #true, '\n');
- printTo(stdout, Array, '\n');
- printTo(stdout, Array[Int, 4], '\n');
- printTo(stdout, prelude, '\n');
+ println(#"whimper");
+ println(#'!');
+ println(#100);
+ println(#true);
+ println(Array);
+ println(Array[Int, 4]);
+ println(prelude);
}
View
18 newclay/test/printing/StringRepr/main.clay
@@ -1,16 +1,10 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(printlnRepr);
import strings.(String, RandomAccessString);
main() {
- printReprTo(stdout, "hello world");
- printTo(stdout, "\n");
- printReprTo(stdout, "\x00\x1F \n\r\t\'\"\x7F\x80\xFF\u10FFFF");
- printTo(stdout, "\n");
- printReprTo(stdout, "du février à l'août");
- printTo(stdout, "\n");
- printReprTo(stdout, String("hello world"));
- printTo(stdout, "\n");
- printReprTo(stdout, RandomAccessString("hello world"));
- printTo(stdout, "\n");
+ printlnRepr("hello world");
+ printlnRepr("\x00\x1F \n\r\t\'\"\x7F\x80\xFF\u10FFFF");
+ printlnRepr("du février à l'août");
+ printlnRepr(String("hello world"));
+ printlnRepr(RandomAccessString("hello world"));
}
View
12 newclay/test/printing/TupleRepr/main.clay
@@ -1,11 +1,7 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(printlnRepr);
main() {
- printReprTo(stdout, ());
- printTo(stdout, '\n');
- printReprTo(stdout, (1,));
- printTo(stdout, '\n');
- printReprTo(stdout, (1, true, "three", '4'));
- printTo(stdout, '\n');
+ printlnRepr(());
+ printlnRepr((1,));
+ printlnRepr((1, true, "three", '4'));
}
View
12 newclay/test/printing/VariantRepr/main.clay
@@ -1,15 +1,11 @@
-import io.stdio.(stdout);
-import printing.(printTo, printReprTo);
+import printing.(printlnRepr);
import variants.(VariantType);
symbol Foo = VariantType(Int, Char, StringConstant);
main() {
- printReprTo(stdout, Foo(1));
- printTo(stdout, '\n');
- printReprTo(stdout, Foo('2'));
- printTo(stdout, '\n');
- printReprTo(stdout, Foo("three"));
- printTo(stdout, '\n');
+ printlnRepr(Foo(1));
+ printlnRepr(Foo('2'));
+ printlnRepr(Foo("three"));
}
Please sign in to comment.
Something went wrong with that request. Please try again.