source: src/tests/user_literals.c@ 866f560

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 866f560 was cd218e8, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

update tests after changing names of basic types, extending the IO test, and adding a literal test

  • Property mode set to 100644
File size: 2.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// user_literals.c --
8//
9// Author : Peter A. Buhr
10// Created On : Wed Sep 6 21:40:50 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Sep 9 08:31:32 2017
13// Update Count : 48
14//
15
16#include <fstream>
17#include <wchar.h>
18#include <uchar.h>
19
20int ?`s( int s ) { sout | "secs" | s | endl; return s; }
21int ?`m( int m ) { sout | "mins" | m | endl; return m * 60; }
22int ?`h( int h ) { sout | "hours" | h | endl; return h * 3600; }
23int ?`_A_( int x ) { sout | "_A_" | x | endl; return x; }
24int ?`__thingy_( int x ) { sout | "_thingy_" | x | endl; return x; }
25
26int ?`s( const char * s ) { sout | "secs" | s | endl; return 0; }
27int ?`m( const char16_t * m ) { sout | "mins" | m | endl; return 0;}
28int ?`h( const char32_t * h ) { sout | "hours" | h | endl; return 0; }
29int ?`_A_( const wchar_t * str ) { sout | "_A_" | str | endl; return 0; }
30int ?`__thingy_( const char * str ) { sout | "_thingy_" | str | endl; return 0; }
31
32
33struct Weight {
34 double stones;
35};
36void ?{}( Weight & w ) { w.stones = 0; } // operations
37void ?{}( Weight & w, double w ) { w.stones = w; }
38Weight ?+?( Weight l, Weight r ) { return (Weight){ l.stones + r.stones }; }
39ofstream * ?|?( ofstream * os, Weight w ) { return os | w.stones; }
40
41Weight ?`st( double w ) { return (Weight){ w }; } // backquote for user literals
42Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
43Weight ?`kg( double w ) { return (Weight) { w * 0.1575}; }
44
45
46int main() {
47 Weight w, hw = { 14 }; // 14 stone
48 w = 11`st + 1`lb;
49 sout | w | endl;
50 w = 70.3`kg;
51 sout | w | endl;
52 w = 155`lb;
53 sout | w | endl;
54 w = 0x_9b_u`lb; // hexadecimal unsigned weight (155)
55 sout | w | endl;
56 w = 0_233`lb; // octal weight (155)
57 sout | w | endl;
58 w = 5`st + 8`kg + 25`lb + hw;
59 sout | w | endl;
60
61// 0`secs;
62 1`s;
63 23`s;
64 23u`m;
65 23l`h;
66 23_ul`_A_;
67 1_234_LL`__thingy_;
68
69 0xff_ffl;
70 0xff_ff`s;
71 0xff_ffu`m;
72 0xff_ffl`h;
73 0xff_fful`_A_;
74 0xff_ffLL`__thingy_;
75
76 '\n'`s;
77 L'\n'`h;
78 u'\n'`m;
79 L_'\n'`_A_;
80 U_'\n'`__thingy_;
81
82 "abc"`s;
83 u"abc"`m;
84 U_"abc"`h;
85 L"abc"`_A_;
86 u8_"abc"`__thingy_;
87} // main
88
89// Local Variables: //
90// tab-width: 4 //
91// compile-command: "cfa user_literals.c" //
92// End: //
Note: See TracBrowser for help on using the repository browser.