This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
146
unikernel/duniverse/cppo/test/test.cppo
Normal file
146
unikernel/duniverse/cppo/test/test.cppo
Normal file
|
|
@ -0,0 +1,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
|
||||
Loading…
Add table
Add a link
Reference in a new issue