1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

Shell: Add support for functions

This implementation does not have support for 'return' yet.
This commit is contained in:
AnotherTest 2020-09-13 15:54:33 +04:30 committed by Andreas Kling
parent 519aa2048a
commit d1550ea64f
6 changed files with 264 additions and 5 deletions

View file

@ -98,6 +98,10 @@ public:
void set_local_variable(const String&, RefPtr<AST::Value>);
void unset_local_variable(const String&);
void define_function(String name, Vector<String> argnames, RefPtr<AST::Node> body);
bool has_function(const String&);
bool invoke_function(const AST::Command&, int& retval);
struct LocalFrame {
HashMap<String, RefPtr<AST::Value>> local_variables;
};
@ -224,6 +228,13 @@ private:
bool m_should_ignore_jobs_on_next_exit { false };
pid_t m_pid { 0 };
struct ShellFunction {
String name;
Vector<String> arguments;
RefPtr<AST::Node> body;
};
HashMap<String, ShellFunction> m_functions;
Vector<LocalFrame> m_local_frames;
NonnullRefPtrVector<AST::Redirection> m_global_redirections;