From b4d2239da227ce162bbe445d305f29f715a215ec Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 12 Jun 2019 11:22:28 +0200 Subject: [PATCH] submodule update: preprocessor: rework macroprocessor --- preprocessor | 2 +- tests/example1_macro.mod | 53 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/preprocessor b/preprocessor index 271a57980..ef62bc6c5 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 271a57980847fb0b7c4d5c0f78e339f21ec847ad +Subproject commit ef62bc6c505894ec6b92344281644369bc80b7ee diff --git a/tests/example1_macro.mod b/tests/example1_macro.mod index d032dcb48..0db3221ec 100644 --- a/tests/example1_macro.mod +++ b/tests/example1_macro.mod @@ -48,7 +48,7 @@ phi = 0.1; @#error "String problem" @#endif -@#define f(y, z) = "@{y}bar@{z}" +@#define f(y, z) = y + "bar" + z @#if f("foo", "baz") != "foobarbaz" @#error "Function problem" @#endif @@ -56,18 +56,18 @@ phi = 0.1; @#define x = 1:3 -@#define y = [ i in x ; i > 1 ] +@#define y = [ i in x when i > 1 ] @#if y != [ 2, 3 ] @# error "One-dimensional comprehension problem" @#endif -@#define z = [ (i,j) in x^2 ; i != j ] +@#define z = [ (i,j) in x^2 when i != j ] @#if z != [ (1,2), (1,3), (2,1), (2,3), (3,1), (3,2) ] @# error "Two-dimensional comprehension problem" @#endif @#define t = 2:4 -@#define tt = [ (i,j) in t^2 ; (i,j) in [ (k,l) in x^2 ; k != l ] ] +@#define tt = [ (i,j) in t^2 when (i,j) in [ (k,l) in x^2 when k != l ] ] @#if tt != [ (2,3), (3,2) ] @# error "Nested comprehension problem" @#endif @@ -112,3 +112,48 @@ stoch_simul; @#else @#error "IFDEF PROBLEM" @#endif + +@#define a = 1 +@#define f(x) = x + a +@#define a = 2 +@#define g(a) = f(1) + a +@#define a = 3 +@#define h(a) = g(2) + a + +@#if f(1) != 4 +@#error "Problem with functions 1" +@#endif + +@#if g(2) != 6 +@#error "Problem with functions 2" +@#endif + +@#if h(1) != 7 +@#error "Problem with functions 3" +@#endif + +@#if h(g(f(1))+1) != 15 +@#error "Problem with functions 4" +@#endif + +@#define zerotol = 1e-15 +@#if exp(ln(5)) <= 5-zerotol && exp(ln(5)) >= 5+zerotol +@#error "Problem with math functions" +@#endif + +@#if log(0) != -inf || 1/0 != inf +@#error "Problem with inf" +@#endif + +@#if 5 < nan +@#error "Problem with NaN comparison" +@#endif + +@#if 5 >= inf +@#error "Problem with inf comparison" +@#endif + +@#if "Aaaaaaaa" > "B" || "AA" != "AA" +@#error "String comparison" +@#endif +