diff options
Diffstat (limited to 'modules/gdscript/gd_script.h')
-rw-r--r-- | modules/gdscript/gd_script.h | 217 |
1 files changed, 33 insertions, 184 deletions
diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 663fc985a7..f052d13685 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -32,185 +32,7 @@ #include "script_language.h" #include "io/resource_loader.h" #include "io/resource_saver.h" -#include "os/thread.h" -#include "pair.h" -class GDInstance; -class GDScript; - - - -class GDFunction { -public: - - enum Opcode { - OPCODE_OPERATOR, - OPCODE_EXTENDS_TEST, - OPCODE_SET, - OPCODE_GET, - OPCODE_SET_NAMED, - OPCODE_GET_NAMED, - OPCODE_ASSIGN, - OPCODE_ASSIGN_TRUE, - OPCODE_ASSIGN_FALSE, - OPCODE_CONSTRUCT, //only for basic types!! - OPCODE_CONSTRUCT_ARRAY, - OPCODE_CONSTRUCT_DICTIONARY, - OPCODE_CALL, - OPCODE_CALL_RETURN, - OPCODE_CALL_BUILT_IN, - OPCODE_CALL_SELF, - OPCODE_CALL_SELF_BASE, - OPCODE_YIELD, - OPCODE_YIELD_SIGNAL, - OPCODE_YIELD_RESUME, - OPCODE_JUMP, - OPCODE_JUMP_IF, - OPCODE_JUMP_IF_NOT, - OPCODE_JUMP_TO_DEF_ARGUMENT, - OPCODE_RETURN, - OPCODE_ITERATE_BEGIN, - OPCODE_ITERATE, - OPCODE_ASSERT, - OPCODE_BREAKPOINT, - OPCODE_LINE, - OPCODE_END - }; - - enum Address { - ADDR_BITS=24, - ADDR_MASK=((1<<ADDR_BITS)-1), - ADDR_TYPE_MASK=~ADDR_MASK, - ADDR_TYPE_SELF=0, - ADDR_TYPE_CLASS=1, - ADDR_TYPE_MEMBER=2, - ADDR_TYPE_CLASS_CONSTANT=3, - ADDR_TYPE_LOCAL_CONSTANT=4, - ADDR_TYPE_STACK=5, - ADDR_TYPE_STACK_VARIABLE=6, - ADDR_TYPE_GLOBAL=7, - ADDR_TYPE_NIL=8 - }; - - struct StackDebug { - - int line; - int pos; - bool added; - StringName identifier; - }; - -private: -friend class GDCompiler; - - StringName source; - - mutable Variant nil; - mutable Variant *_constants_ptr; - int _constant_count; - const StringName *_global_names_ptr; - int _global_names_count; - const int *_default_arg_ptr; - int _default_arg_count; - const int *_code_ptr; - int _code_size; - int _argument_count; - int _stack_size; - int _call_size; - int _initial_line; - bool _static; - GDScript *_script; - - StringName name; - Vector<Variant> constants; - Vector<StringName> global_names; - Vector<int> default_arguments; - Vector<int> code; -#ifdef DEBUG_ENABLED - CharString func_cname; - const char*_func_cname; -#endif - -#ifdef TOOLS_ENABLED - Vector<StringName> arg_names; -#endif - - List<StackDebug> stack_debug; - - _FORCE_INLINE_ Variant *_get_variant(int p_address,GDInstance *p_instance,GDScript *p_script,Variant &self,Variant *p_stack,String& r_error) const; - _FORCE_INLINE_ String _get_call_error(const Variant::CallError& p_err, const String& p_where,const Variant**argptrs) const; - - -public: - - struct CallState { - - GDInstance *instance; - Vector<uint8_t> stack; - int stack_size; - Variant self; - uint32_t alloca_size; - GDScript *_class; - int ip; - int line; - int defarg; - Variant result; - - }; - - _FORCE_INLINE_ bool is_static() const { return _static; } - - const int* get_code() const; //used for debug - int get_code_size() const; - Variant get_constant(int p_idx) const; - StringName get_global_name(int p_idx) const; - StringName get_name() const; - int get_max_stack_size() const; - int get_default_argument_count() const; - int get_default_argument_addr(int p_idx) const; - GDScript *get_script() const { return _script; } - - void debug_get_stack_member_state(int p_line,List<Pair<StringName,int> > *r_stackvars) const; - - _FORCE_INLINE_ bool is_empty() const { return _code_size==0; } - - int get_argument_count() const { return _argument_count; } - StringName get_argument_name(int p_idx) const { -#ifdef TOOLS_ENABLED - ERR_FAIL_INDEX_V(p_idx,arg_names.size(),StringName()); - return arg_names[p_idx]; -#endif - return StringName(); - - } - Variant get_default_argument(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx,default_arguments.size(),Variant()); - return default_arguments[p_idx]; - } - - Variant call(GDInstance *p_instance,const Variant **p_args, int p_argcount,Variant::CallError& r_err,CallState *p_state=NULL); - - GDFunction(); -}; - - -class GDFunctionState : public Reference { - - OBJ_TYPE(GDFunctionState,Reference); -friend class GDFunction; - GDFunction *function; - GDFunction::CallState state; - Variant _signal_callback(const Variant** p_args, int p_argcount, Variant::CallError& r_error); -protected: - static void _bind_methods(); -public: - - bool is_valid() const; - Variant resume(const Variant& p_arg=Variant()); - GDFunctionState(); - ~GDFunctionState(); -}; - - +#include "gd_function.h" class GDNativeClass : public Reference { OBJ_TYPE(GDNativeClass,Reference); @@ -258,7 +80,7 @@ friend class GDScriptLanguage; Set<StringName> members; //members are just indices to the instanced script. Map<StringName,Variant> constants; - Map<StringName,GDFunction> member_functions; + Map<StringName,GDFunction*> member_functions; Map<StringName,MemberInfo> member_indices; //members are just indices to the instanced script. Map<StringName,Ref<GDScript> > subclasses; Map<StringName,Vector<StringName> > _signals; @@ -285,6 +107,7 @@ friend class GDScriptLanguage; String source; String path; String name; + SelfList<GDScript> script_list; GDInstance* _create_instance(const Variant** p_args,int p_argcount,Object *p_owner,bool p_isref,Variant::CallError &r_error); @@ -317,7 +140,7 @@ public: const Map<StringName,Ref<GDScript> >& get_subclasses() const { return subclasses; } const Map<StringName,Variant >& get_constants() const { return constants; } const Set<StringName>& get_members() const { return members; } - const Map<StringName,GDFunction>& get_member_functions() const { return member_functions; } + const Map<StringName,GDFunction*>& get_member_functions() const { return member_functions; } const Ref<GDNativeClass>& get_native() const { return native; } virtual bool has_script_signal(const StringName& p_signal) const; @@ -328,7 +151,7 @@ public: Ref<GDScript> get_base() const; const Map<StringName,MemberInfo>& debug_get_member_indices() const { return member_indices; } - const Map<StringName,GDFunction>& debug_get_member_functions() const; //this is debug only + const Map<StringName,GDFunction*>& debug_get_member_functions() const; //this is debug only StringName debug_get_member_by_index(int p_idx) const; Variant _new(const Variant** p_args,int p_argcount,Variant::CallError& r_error); @@ -343,7 +166,7 @@ public: virtual void set_source_code(const String& p_code); virtual void update_exports(); - virtual Error reload(); + virtual Error reload(bool p_keep_state=false); virtual String get_node_type() const; void set_script_path(const String& p_path) { path=p_path; } //because subclasses need a path too... @@ -357,18 +180,24 @@ public: virtual ScriptLanguage *get_language() const; GDScript(); + ~GDScript(); }; class GDInstance : public ScriptInstance { friend class GDScript; friend class GDFunction; friend class GDFunctions; +friend class GDCompiler; Object *owner; Ref<GDScript> script; +#ifdef DEBUG_ENABLED + Map<StringName,int> member_indices_cache; //used only for hot script reloading +#endif Vector<Variant> members; bool base_ref; + void _ml_call_reversed(GDScript *sptr,const StringName& p_method,const Variant** p_args,int p_argcount); public: @@ -385,7 +214,7 @@ public: virtual void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); virtual void call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount); - Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; } + Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; } virtual void notification(int p_notification); @@ -395,6 +224,7 @@ public: void set_path(const String& p_path); + void reload_members(); GDInstance(); ~GDInstance(); @@ -431,8 +261,19 @@ class GDScriptLanguage : public ScriptLanguage { void _add_global(const StringName& p_name,const Variant& p_value); + Mutex *lock; + +friend class GDScript; + + SelfList<GDScript>::List script_list; +friend class GDFunction; + + SelfList<GDFunction>::List function_list; + bool profiling; + uint64_t script_frame_time; public: + int calls; bool debug_break(const String& p_error,bool p_allow_continue=true); @@ -547,11 +388,19 @@ public: virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1); virtual String debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems=-1,int p_max_depth=-1); + virtual void reload_all_scripts(); + virtual void frame(); virtual void get_public_functions(List<MethodInfo> *p_functions) const; virtual void get_public_constants(List<Pair<String,Variant> > *p_constants) const; + virtual void profiling_start(); + virtual void profiling_stop(); + + virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr,int p_info_max); + virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr,int p_info_max); + /* LOADER FUNCTIONS */ virtual void get_recognized_extensions(List<String> *p_extensions) const; |