$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r73566 - in trunk/libs/spirit/example/qi/compiler_tutorial: conjure3 conjure_samples
From: joel_at_[hidden]
Date: 2011-08-05 23:38:29
Author: djowel
Date: 2011-08-05 23:38:28 EDT (Fri, 05 Aug 2011)
New Revision: 73566
URL: http://svn.boost.org/trac/boost/changeset/73566
Log:
More binary operators
Text files modified: 
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp         |     7 ++++                                    
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/lexer_def.hpp        |     6 ++++                                    
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/operators.cnj |    58 +++++++++++++++++++++++++++++++-------- 
   3 files changed, 59 insertions(+), 12 deletions(-)
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp	(original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/compiler.cpp	2011-08-05 23:38:28 EDT (Fri, 05 Aug 2011)
@@ -181,6 +181,13 @@
             case token_ids::minus: return builder.CreateSub(lhs, rhs, "subtmp");
             case token_ids::times: return builder.CreateMul(lhs, rhs, "multmp");
             case token_ids::divide: return builder.CreateSDiv(lhs, rhs, "divtmp");
+            case token_ids::mod: return builder.CreateSRem(lhs, rhs, "modtmp");
+
+            case token_ids::bit_or: return builder.CreateOr(lhs, rhs, "ortmp");
+            case token_ids::bit_xor: return builder.CreateXor(lhs, rhs, "xortmp");
+            case token_ids::bit_and: return builder.CreateAnd(lhs, rhs, "andtmp");
+            case token_ids::shift_left: return builder.CreateShl(lhs, rhs, "shltmp");
+            case token_ids::shift_right: return builder.CreateLShr(lhs, rhs, "shrtmp");
 
             case token_ids::equal: return builder.CreateICmpEQ(lhs, rhs, "eqtmp");
             case token_ids::not_equal: return builder.CreateICmpNE(lhs, rhs, "netmp");
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/lexer_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/lexer_def.hpp	(original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure3/lexer_def.hpp	2011-08-05 23:38:28 EDT (Fri, 05 Aug 2011)
@@ -41,6 +41,11 @@
                 (">>=",     token_ids::shift_right_assign)
                 ("\\|\\|",  token_ids::logical_or)
                 ("&&",      token_ids::logical_and)
+                ("\\|",     token_ids::bit_or)
+                ("\\^",     token_ids::bit_xor)
+                ("&",       token_ids::bit_and)
+                ("<<",      token_ids::shift_left)
+                (">>",      token_ids::shift_right)
                 ("==",      token_ids::equal)
                 ("!=",      token_ids::not_equal)
                 ("<",       token_ids::less)
@@ -51,6 +56,7 @@
                 ("\\-",     token_ids::minus)
                 ("\\*",     token_ids::times)
                 ("\\/",     token_ids::divide)
+                ("%",       token_ids::mod)
                 ("!",       token_ids::not_)
             ;
 
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/operators.cnj
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/operators.cnj	(original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/operators.cnj	2011-08-05 23:38:28 EDT (Fri, 05 Aug 2011)
@@ -1,77 +1,108 @@
 /* More operators tests */
 /* Conjure >=3 only!!! */
 
-int plus(x, y)
+// assign ops
+
+int aplus(x, y)
 {
     int t = x;
     t += y;
     return t;
 }
 
-int minus(x, y)
+int aminus(x, y)
 {
     int t = x;
     t -= y;
     return t;
 }
 
-int shl(x, y)
+int ashl(x, y)
 {
     int t = x;
     t <<= y;
     return t;
 }
 
-int div(x, y)
+int adiv(x, y)
 {
     int t = x;
     t /= y;
     return t;
 }
 
-int mult(x, y)
+int amult(x, y)
 {
     int t = x;
     t *= y;
     return t;
 }
 
-int mod(x, y)
+int amod(x, y)
 {
     int t = x;
     t %= y;
     return t;
 }
 
-int or(x, y)
+int aor(x, y)
 {
     int t = x;
     t |= y;
     return t;
 }
 
-int and(x, y)
+int aand(x, y)
 {
     int t = x;
     t &= y;
     return t;
 }
 
-int xor(x, y)
+int axor(x, y)
 {
     int t = x;
     t ^= y;
     return t;
 }
 
-int shr(x, y)
+int ashr(x, y)
 {
     int t = x;
     t >>= y;
     return t;
 }
 
-int main()
+// binary ops
+
+int plus(x, y)      { return x + y; }
+int minus(x, y)     { return x - y; }
+int shl(x, y)       { return x << y; }
+int div(x, y)       { return x / y; }
+int mult(x, y)      { return x * y; }
+int mod(x, y)       { return x % y; }
+int or(x, y)        { return x | y; }
+int and(x, y)       { return x & y; }
+int xor(x, y)       { return x ^ y; }
+int shr(x, y)       { return x >> y; }
+
+int assign()
+{
+    int a = aplus(2, 3);    // 5
+    int b = ashl(a, 2);     // 20
+    int c = aminus(b, 2);   // 18
+    int d = adiv(c, 2);     // 9
+    int e = amult(d, c);    // 162
+    int f = amod(e, 10);    // 2
+    int g = aor(f, 45);     // 47
+    int h = aand(g, 48);    // 32
+    int j = axor(h, h);     // 0
+    int k = aor(j, 65535);  // 65535
+    int l = ashr(k, 3);     // 8191
+    return l;
+}
+
+int binary()
 {
     int a = plus(2, 3);     // 5
     int b = shl(a, 2);      // 20
@@ -87,4 +118,7 @@
     return l;
 }
 
-
+int main()
+{
+    return assign() ^ binary();     // 0
+}
\ No newline at end of file