1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
(* comment *)
#define pi 3.14
f(1)
#define f(x) x+pi
f(2)
#undef pi
f(3)
#ifdef g
"g" is defined
#else
"g" is not defined
#endif
#define a(x) b()
#define b(x) a()
a()
debug("a")
debug("b")
#define z 123
#define y z
#define x y
#if x lsl 1 = 2*123
#if 1 = 2
#error "test"
#endif
success
#else
failure
#endif
#define test_multiline \
"abc\
xyz
def" \
(* 123 \
789
456 *)
test_multiline
#define test_args(x, y) x y
test_args("a","b")
#define test_argc(x) x y
test_argc(aa\,bb)
#define test_esc(x) x
test_esc(\,\)\()
blah #define xyz
#ifdef xyz
#error "xyz should not have been defined"
#endif
#define sticky1(x) _
#define sticky2(x) sticky1()_ (* the 2 underscores should be space-separated *)
sticky2()
#define empty1
#define empty2 +empty1+ (* there should be some space between the pluses *)
empty2
(* (* nested comment with single single quote: ' *) "*)" *)
#define arg
obj
\# define arg
' (* lone single quote *)
#define one 1
one = 1
#undef x
#define x #
x is #
#undef one
#define one 1
#if (one+one = 100 + \
64 lsr 3 / 4 - lnot lnot 100) && \
1 + 3 * 5 = 16 && \
22 mod 7 = 1 && \
lnot 0 = 0xffffffffffffffff && \
-1 asr 100 = -1 && \
-1 land (1 lsl 1 lsr 1) = 1 && \
-1 lor 1 = -1 && \
-2 lxor 1 = -1 && \
lnot -1 = 0 && \
true && not false && defined one && \
(true || true && false)
good maths
#else
#error "math error"
#endif
#undef f
#undef g
#undef x
#undef y
#define trace(f) \
let f x = \
printf "call %s\n%!" STRINGIFY(f); \
let y = f x in \
printf "return %s\n%!" STRINGIFY(f); \
y \
;;
trace(g)
#define field(name,type) \
val mutable name : type option \
method CONCAT(get_, name) = name \
method CONCAT(set_, name) x = name <- Some x
class foo () =
object
field(field_1, int)
field(field_2, string)
end
#define DEBUG(x) \
(if !debug then \
eprintf "[debug] %s %i: " __FILE__ __LINE__; \
eprintf x; \
eprintf "\n")
DEBUG("test1 %i %i" x y)
DEBUG("test2 %i" x)
#include "incl.cppo"
# 123456
#789 "test"
#include "incl.cppo"
#define debug(s) Printf.eprintf "%S %i: %s\n%!" __FILE__ __LINE__ s
end
|