public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/
Date: Mon, 23 May 2011 14:34:19 +0000 (UTC)	[thread overview]
Message-ID: <ec95a2f25d72a177609b38cf72e01309039641c5.betelgeuse@gentoo> (raw)

commit:     ec95a2f25d72a177609b38cf72e01309039641c5
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri May 20 07:23:43 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 15:04:44 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ec95a2f2

Builtin: support let built-in

---
 Makefile.am                        |    2 +
 scripts/arithmetic_assignment.bash |    2 +-
 scripts/function_def.bash          |    4 +++
 scripts/function_def.bash.result   |    1 +
 src/builtins/let_builtin.cpp       |   37 ++++++++++++++++++++++++++++++++++++
 src/builtins/let_builtin.h         |   35 ++++++++++++++++++++++++++++++++++
 src/cppbash_builtin.cpp            |    4 ++-
 7 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index b680cd0..33dbe51 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,6 +179,8 @@ libcppbash_la_SOURCES = src/common.h \
 						src/builtins/source_builtin.cpp \
 						src/builtins/return_builtin.h \
 						src/builtins/return_builtin.cpp \
+						src/builtins/let_builtin.h \
+						src/builtins/let_builtin.cpp \
 						src/builtins/inherit_builtin.h \
 						src/builtins/inherit_builtin.cpp \
 						src/builtins/builtin_exceptions.h \

diff --git a/scripts/arithmetic_assignment.bash b/scripts/arithmetic_assignment.bash
index 27e2ee5..7f77ec7 100644
--- a/scripts/arithmetic_assignment.bash
+++ b/scripts/arithmetic_assignment.bash
@@ -11,4 +11,4 @@ FOO009="$((value^=5))"
 FOO010="$((value|=10))"
 FOO011=("CREATED" 2)
 FOO012="$((${FOO011[0]}=10))"
-value="$((100))"
+let "value=100"

diff --git a/scripts/function_def.bash b/scripts/function_def.bash
index bcf5a4b..60337ac 100644
--- a/scripts/function_def.bash
+++ b/scripts/function_def.bash
@@ -52,3 +52,7 @@ func_nested2() {
     func_nested1
 }
 func_nested2
+let() {
+    echo "overloaded let"
+}
+let "1 + 2"

diff --git a/scripts/function_def.bash.result b/scripts/function_def.bash.result
index 2c5783c..677c3d8 100644
--- a/scripts/function_def.bash.result
+++ b/scripts/function_def.bash.result
@@ -1,4 +1,5 @@
 hi 1
+overloaded let
 ARG1=100
 ARG2=2
 ARG3=3

diff --git a/src/builtins/let_builtin.cpp b/src/builtins/let_builtin.cpp
new file mode 100644
index 0000000..dc4be13
--- /dev/null
+++ b/src/builtins/let_builtin.cpp
@@ -0,0 +1,37 @@
+/*
+   Please use git log for copyright holder and year information
+
+   This file is part of libbash.
+
+   libbash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 2 of the License, or
+   (at your option) any later version.
+
+   libbash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with libbash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file let_builtin.h
+/// \author Mu Qiao
+/// \brief implementation for the let builtin
+///
+#include <boost/algorithm/string/join.hpp>
+
+#include "core/bash_ast.h"
+
+#include "builtins/let_builtin.h"
+
+int let_builtin::exec(const std::vector<std::string>& bash_args)
+{
+  std::string expression(boost::algorithm::join(bash_args, " "));
+  bash_ast ast(expression, &bash_ast::parser_arithmetics);
+  ast.interpret_with(_walker, &bash_ast::walker_arithmetics);
+
+  return ast.get_error_count();
+}

diff --git a/src/builtins/let_builtin.h b/src/builtins/let_builtin.h
new file mode 100644
index 0000000..9dba7d6
--- /dev/null
+++ b/src/builtins/let_builtin.h
@@ -0,0 +1,35 @@
+/*
+   Please use git log for copyright holder and year information
+
+   This file is part of libbash.
+
+   libbash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 2 of the License, or
+   (at your option) any later version.
+
+   libbash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with libbash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file let_builtin.h
+/// \brief implementation for the let builtin
+///
+#ifndef LIBBASH_BUILTINS_LET_BUILTIN_H_
+#define LIBBASH_BUILTINS_LET_BUILTIN_H_
+
+#include "cppbash_builtin.h"
+
+class let_builtin : public virtual cppbash_builtin
+{
+public:
+  BUILTIN_CONSTRUCTOR(let)
+  virtual int exec(const std::vector<std::string>& );
+};
+
+#endif

diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp
index aee18c9..7334a8e 100644
--- a/src/cppbash_builtin.cpp
+++ b/src/cppbash_builtin.cpp
@@ -27,6 +27,7 @@
 #include "builtins/boolean_builtins.h"
 #include "builtins/echo_builtin.h"
 #include "builtins/inherit_builtin.h"
+#include "builtins/let_builtin.h"
 #include "builtins/return_builtin.h"
 #include "builtins/source_builtin.h"
 
@@ -42,7 +43,8 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
       {":", boost::factory<true_builtin*>()},
       {"true", boost::factory<true_builtin*>()},
       {"false", boost::factory<false_builtin*>()},
-      {"return", boost::factory<return_builtin*>()}
+      {"return", boost::factory<return_builtin*>()},
+      {"let", boost::factory<let_builtin*>()},
   });
   return *p;
 }



             reply	other threads:[~2011-05-23 14:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 14:34 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-05-27 23:03 [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/ Petteri Räty
2011-06-02 11:48 Petteri Räty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ec95a2f25d72a177609b38cf72e01309039641c5.betelgeuse@gentoo \
    --to=betelgeuse@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox