* [gentoo-commits] proj/libbash:master commit in: src/builtins/
@ 2011-05-08 13:07 Petteri Räty
0 siblings, 0 replies; 5+ messages in thread
From: Petteri Räty @ 2011-05-08 13:07 UTC (permalink / raw
To: gentoo-commits
commit: 4e2bf0c6eb6f291a5d151d82c486c7fb73d7f33f
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu May 5 07:18:27 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 8 12:55:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4e2bf0c6
Builtin: cache AST inside source builtin
AST can be reused in order to improve the performance. Now we use
a static variable inside the source builtin to cache all the ASTs
created by the builtin. In future we may define rules to change the
internal behavior.
---
src/builtins/source_builtin.cpp | 18 +++++++++++++-----
1 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp
index d2b4bcb..6ba6b11 100644
--- a/src/builtins/source_builtin.cpp
+++ b/src/builtins/source_builtin.cpp
@@ -26,6 +26,7 @@
#include <fstream>
#include <string>
+#include <unordered_map>
#include "cppbash_builtin.h"
#include "core/interpreter.h"
@@ -34,17 +35,24 @@
int source_builtin::exec(const std::vector<std::string>& bash_args)
{
+ static std::unordered_map<std::string, std::shared_ptr<bash_ast>> ast_cache;
+
if(bash_args.size() == 0)
throw interpreter_exception("should provide one argument for source builtin");
// we need fix this to pass extra arguments as positional parameters
const std::string& path = bash_args[0];
- std::ifstream input(path);
- if(!input)
- throw interpreter_exception(path + " can't be read");
- bash_ast ast(input);
- ast.interpret_with(_walker);
+ auto& stored_ast = ast_cache[path];
+ if(!stored_ast)
+ {
+ std::ifstream input(path);
+ if(!input)
+ throw interpreter_exception(path + " can't be read");
+
+ stored_ast.reset(new bash_ast(input));
+ }
+ stored_ast->interpret_with(_walker);
return _walker.get_status();
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/
@ 2011-06-03 12:43 Petteri Räty
0 siblings, 0 replies; 5+ messages in thread
From: Petteri Räty @ 2011-06-03 12:43 UTC (permalink / raw
To: gentoo-commits
commit: e7167b283d8c523ae06ae94347e840cd2b1dba05
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 1 13:34:00 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 13:34:00 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=e7167b28
Builtin: make let call interpreter::eval_arithmetic
As we won't handle parser failure so it's safe to return 0 for this
built-in.
---
src/builtins/let_builtin.cpp | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/builtins/let_builtin.cpp b/src/builtins/let_builtin.cpp
index 43f28a3..97785ab 100644
--- a/src/builtins/let_builtin.cpp
+++ b/src/builtins/let_builtin.cpp
@@ -32,8 +32,7 @@
int let_builtin::exec(const std::vector<std::string>& bash_args)
{
std::string expression(boost::algorithm::join(bash_args, " "));
- bash_ast ast(std::stringstream(expression), &bash_ast::parser_arithmetics);
- ast.interpret_with(_walker, &bash_ast::walker_arithmetics);
+ _walker.eval_arithmetic(expression);
- return ast.get_error_count();
+ return 0;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/
@ 2011-06-15 21:18 Petteri Räty
0 siblings, 0 replies; 5+ messages in thread
From: Petteri Räty @ 2011-06-15 21:18 UTC (permalink / raw
To: gentoo-commits
commit: 797b43f26a5c387bbf1d2874fc22bf0eb56e3582
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 14 09:58:07 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 15 21:14:47 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=797b43f2
Builtin: cache parsing failures in source built-in
---
src/builtins/source_builtin.cpp | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp
index 8a1838b..b2bf2db 100644
--- a/src/builtins/source_builtin.cpp
+++ b/src/builtins/source_builtin.cpp
@@ -44,15 +44,25 @@ int source_builtin::exec(const std::vector<std::string>& bash_args)
// we need fix this to pass extra arguments as positional parameters
const std::string& path = bash_args[0];
- auto& stored_ast = ast_cache[path];
- if(!stored_ast)
- stored_ast.reset(new bash_ast(path));
+ auto stored_ast = ast_cache.find(path);
+ if(stored_ast == ast_cache.end())
+ {
+ // ensure the path is cached
+ auto iter = ast_cache.insert(make_pair(path, std::shared_ptr<bash_ast>()));
+ // this may throw exception
+ iter.first->second.reset(new bash_ast(path));
+ stored_ast = iter.first;
+ }
+ else if(!(stored_ast->second))
+ {
+ throw libbash::interpreter_exception(path + " cannot be fully parsed");
+ }
const std::string& original_path = _walker.resolve<std::string>("0");
try
{
_walker.define("0", path, true);
- stored_ast->interpret_with(_walker);
+ stored_ast->second->interpret_with(_walker);
}
catch(return_exception& e) {}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/
@ 2011-06-25 10:05 Petteri Räty
0 siblings, 0 replies; 5+ messages in thread
From: Petteri Räty @ 2011-06-25 10:05 UTC (permalink / raw
To: gentoo-commits
commit: 42a50c1fab4780fce1e8ba792d70af43d0da0cec
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 14:00:49 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 23 03:24:40 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=42a50c1f
Core: abstract the role of continue exception
---
src/builtins/builtin_exceptions.h | 46 +++++++++++++++++++++++++++++++-----
1 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/src/builtins/builtin_exceptions.h b/src/builtins/builtin_exceptions.h
index c20ce4c..c535417 100644
--- a/src/builtins/builtin_exceptions.h
+++ b/src/builtins/builtin_exceptions.h
@@ -39,26 +39,58 @@ public:
runtime_error("return exception"){}
};
-class continue_exception: public std::exception
+class loop_control_exception
{
int count;
+
+ virtual void rethrow() = 0;
+
+protected:
+ virtual ~loop_control_exception() {}
+
public:
- explicit continue_exception(int c): count(c)
- {
- if(c < 1)
- throw libbash::interpreter_exception("continue: argument should be greater than or equal to 1");
- }
+ explicit loop_control_exception(int c): count(c) {}
void rethrow_unless_correct_frame()
{
if(count != 1)
{
--count;
- throw *this;
+ rethrow();
}
}
};
+class continue_exception: public loop_control_exception
+{
+protected:
+ virtual void rethrow()
+ {
+ throw *this;
+ }
+
+public:
+ explicit continue_exception(int c): loop_control_exception(c) {
+ if(c < 1)
+ throw libbash::interpreter_exception("continue: argument should be greater than or equal to 1");
+ }
+};
+
+class break_exception: public loop_control_exception
+{
+protected:
+ virtual void rethrow()
+ {
+ throw *this;
+ }
+
+public:
+ explicit break_exception(int c): loop_control_exception(c) {
+ if(c < 1)
+ throw libbash::interpreter_exception("break: argument should be greater than or equal to 1");
+ }
+};
+
class suppress_output: public std::exception
{
};
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/
@ 2011-07-03 20:21 Petteri Räty
0 siblings, 0 replies; 5+ messages in thread
From: Petteri Räty @ 2011-07-03 20:21 UTC (permalink / raw
To: gentoo-commits
commit: fa602cbb0e6269ad93b47fb47eb3e5b660fc0929
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 28 12:33:04 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Jul 3 19:50:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=fa602cbb
Core: fix headers that don't follow the coding style
---
src/builtins/eval_builtin.h | 4 ++--
src/builtins/printf_builtin.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/builtins/eval_builtin.h b/src/builtins/eval_builtin.h
index ea2222c..ed910ea 100644
--- a/src/builtins/eval_builtin.h
+++ b/src/builtins/eval_builtin.h
@@ -21,8 +21,8 @@
/// \brief class that implements the eval builtin
///
-#ifndef LIBBASH_BUILTINS_eval_BUILTIN_H_
-#define LIBBASH_BUILTINS_eval_BUILTIN_H_
+#ifndef LIBBASH_BUILTINS_EVAL_BUILTIN_H_
+#define LIBBASH_BUILTINS_EVAL_BUILTIN_H_
#include "cppbash_builtin.h"
diff --git a/src/builtins/printf_builtin.h b/src/builtins/printf_builtin.h
index 07d5ac7..ec3ba72 100644
--- a/src/builtins/printf_builtin.h
+++ b/src/builtins/printf_builtin.h
@@ -20,8 +20,8 @@
/// \file printf_builtin.h
/// \brief implementation for the printf builtin
///
-#ifndef LIBBASH_BUILTINS_printf_BUILTIN_H_
-#define LIBBASH_BUILTINS_printf_BUILTIN_H_
+#ifndef LIBBASH_BUILTINS_PRINTF_BUILTIN_H_
+#define LIBBASH_BUILTINS_PRINTF_BUILTIN_H_
#include "cppbash_builtin.h"
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-03 20:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-08 13:07 [gentoo-commits] proj/libbash:master commit in: src/builtins/ Petteri Räty
-- strict thread matches above, loose matches on Subject: below --
2011-06-03 12:43 Petteri Räty
2011-06-15 21:18 Petteri Räty
2011-06-25 10:05 Petteri Räty
2011-07-03 20:21 Petteri Räty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox