[Bf-blender-cvs] [f993594] object_nodes: Added "expressions" as a reduced definition of a function for evaluating instruction lists.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:42:47 CET 2015
Commit: f99359418ccbee7778f632af461fe7d652200707
Author: Lukas Tönne
Date: Thu Oct 8 10:36:30 2015 +0200
Branches: object_nodes
https://developer.blender.org/rBf99359418ccbee7778f632af461fe7d652200707
Added "expressions" as a reduced definition of a function for evaluating instruction lists.
===================================================================
A source/blender/blenvm/BVM_api.h
D source/blender/blenvm/BVM_function.h
D source/blender/blenvm/BVM_module.h
A source/blender/blenvm/BVM_types.h
M source/blender/blenvm/CMakeLists.txt
A source/blender/blenvm/intern/bvm_api.cc
A source/blender/blenvm/intern/bvm_expression.cc
A source/blender/blenvm/intern/bvm_expression.h
M source/blender/blenvm/intern/bvm_function.cc
A source/blender/blenvm/intern/bvm_function.h
M source/blender/blenvm/intern/bvm_module.cc
A source/blender/blenvm/intern/bvm_module.h
A source/blender/blenvm/intern/bvm_schedule.cc
A source/blender/blenvm/intern/bvm_schedule.h
A source/blender/blenvm/util/bvm_util_hash.h
A source/blender/blenvm/util/bvm_util_map.h
A source/blender/blenvm/util/bvm_util_string.h
===================================================================
diff --git a/source/blender/blenvm/BVM_module.h b/source/blender/blenvm/BVM_api.h
similarity index 65%
copy from source/blender/blenvm/BVM_module.h
copy to source/blender/blenvm/BVM_api.h
index 3e0cdfb..fbc454d 100644
--- a/source/blender/blenvm/BVM_module.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -25,23 +25,40 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef __BVM_MODULE_H__
-#define __BVM_MODULE_H__
+#ifndef __BVM_API_H__
+#define __BVM_API_H__
-/** \file BVM_module.h
+/** \file BVM_api.h
* \ingroup bvm
*/
-struct BVMFunction;
+#include "BVM_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
-typedef struct BVMModule {
- struct GHash *functions;
-} BVMModule;
+struct BVMContext;
+struct BVMExpression;
+struct BVMFunction;
+struct BVMModule;
-void BVM_module_init(struct BVMModule *lib);
-void BVM_module_free(struct BVMModule *lib);
+struct BVMModule *BVM_module_create(void);
+void BVM_module_free(struct BVMModule *mod);
struct BVMFunction *BVM_module_create_function(struct BVMModule *mod, const char *name);
bool BVM_module_delete_function(struct BVMModule *mod, const char *name);
-#endif /* __BVM_MODULE_H__ */
+/* ------------------------------------------------------------------------- */
+
+const char *BVM_function_name(const struct BVMFunction *fun);
+
+/* ------------------------------------------------------------------------- */
+
+void BVM_expression_eval(struct BVMExpression *expr, void *result);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BVM_API_H__ */
diff --git a/source/blender/blenvm/BVM_function.h b/source/blender/blenvm/BVM_types.h
similarity index 81%
copy from source/blender/blenvm/BVM_function.h
copy to source/blender/blenvm/BVM_types.h
index f8d657c..c4d44dc 100644
--- a/source/blender/blenvm/BVM_function.h
+++ b/source/blender/blenvm/BVM_types.h
@@ -25,17 +25,24 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef __BVM_FUNCTION_H__
-#define __BVM_FUNCTION_H__
+#ifndef __BVM_TYPES_H__
+#define __BVM_TYPES_H__
-/** \file BVM_function.h
+/** \file BVM_types.h
* \ingroup bvm
*/
-#include "DNA_defs.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
-typedef struct BVMFunction {
- char name[MAX_NAME];
-} BVMFunction;
+typedef enum BVMType {
+ BVM_FLOAT,
+ BVM_FLOAT3,
+} BVMType;
-#endif /* __BVM_FUNCTION_H__ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BVM_TYPES_H__ */
diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index 26a7147..39a78f5 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -25,6 +25,7 @@
set(INC
.
+ util
../blenlib
../makesdna
../../../intern/guardedalloc
@@ -34,11 +35,44 @@ set(INC_SYS
)
set(SRC
+ intern/bvm_api.cc
+ intern/bvm_expression.cc
intern/bvm_function.cc
intern/bvm_module.cc
+ intern/bvm_schedule.cc
- BVM_function.h
- BVM_module.h
+ intern/bvm_expression.h
+ intern/bvm_function.h
+ intern/bvm_module.h
+ intern/bvm_schedule.h
+
+ util/bvm_util_hash.h
+ util/bvm_util_map.h
+ util/bvm_util_string.h
+
+ BVM_api.h
+ BVM_types.h
)
+TEST_UNORDERED_MAP_SUPPORT()
+if(HAVE_STD_UNORDERED_MAP_HEADER)
+ if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
+ add_definitions(-DBVM_STD_UNORDERED_MAP)
+ else()
+ if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+ add_definitions(-DBVM_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
+ else()
+ add_definitions(-DBVM_NO_UNORDERED_MAP)
+ message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
+ endif()
+ endif()
+else()
+ if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+ add_definitions(-DBVM_TR1_UNORDERED_MAP)
+ else()
+ add_definitions(-DBVM_NO_UNORDERED_MAP)
+ message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
+ endif()
+endif()
+
blender_add_lib(bf_blenvm "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/blenvm/intern/bvm_function.cc b/source/blender/blenvm/intern/bvm_api.cc
similarity index 61%
copy from source/blender/blenvm/intern/bvm_function.cc
copy to source/blender/blenvm/intern/bvm_api.cc
index 7cabc58..441a497 100644
--- a/source/blender/blenvm/intern/bvm_function.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -25,11 +25,34 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/blenvm/intern/function.cc
+/** \file blender/blenvm/intern/bvm_api.cc
* \ingroup bvm
*/
#include "MEM_guardedalloc.h"
-#include "BVM_function.h"
+extern "C" {
+#include "BVM_api.h"
+}
+#include "bvm_expression.h"
+#include "bvm_function.h"
+#include "bvm_module.h"
+
+#define _MOD(mod) ((bvm::Module *)(mod))
+
+struct BVMModule *BVM_module_create(void)
+{ return (struct BVMModule *)(new bvm::Module()); }
+
+void BVM_module_free(BVMModule *mod)
+{ delete _MOD(mod); }
+
+struct BVMFunction *BVM_module_create_function(BVMModule *mod, const char *name)
+{ return (struct BVMFunction *)_MOD(mod)->create_function(name); }
+
+bool BVM_module_delete_function(BVMModule *mod, const char *name)
+{ return _MOD(mod)->remove_function(name); }
+
+#undef _MOD
+
+#undef _EXPR
diff --git a/source/blender/blenvm/intern/bvm_function.cc b/source/blender/blenvm/intern/bvm_expression.cc
similarity index 57%
copy from source/blender/blenvm/intern/bvm_function.cc
copy to source/blender/blenvm/intern/bvm_expression.cc
index 7cabc58..d71b0d2 100644
--- a/source/blender/blenvm/intern/bvm_function.cc
+++ b/source/blender/blenvm/intern/bvm_expression.cc
@@ -25,11 +25,48 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/blenvm/intern/function.cc
+/** \file bvm_expression.cc
* \ingroup bvm
*/
#include "MEM_guardedalloc.h"
-#include "BVM_function.h"
+#include "bvm_expression.h"
+namespace bvm {
+
+Expression::Expression()
+{
+}
+
+Expression::~Expression()
+{
+}
+
+void Expression::add_return_value(BVMType type, const string &name)
+{
+ ReturnValue rval;
+ rval.type = type;
+ rval.name = name;
+ return_values.push_back(rval);
+}
+
+size_t Expression::return_values_size() const
+{
+ return return_values.size();
+}
+
+const Expression::ReturnValue &Expression::return_value(size_t index) const
+{
+ return return_values[index];
+}
+
+const Expression::ReturnValue &Expression::return_value(const string &name) const
+{
+ for (ReturnValueList::const_iterator it = return_values.begin(); it != return_values.end(); ++it)
+ if ((*it).name == name)
+ return *it;
+ return *(return_values.end());
+}
+
+} /* namespace bvm */
diff --git a/source/blender/blenvm/BVM_module.h b/source/blender/blenvm/intern/bvm_expression.h
similarity index 53%
copy from source/blender/blenvm/BVM_module.h
copy to source/blender/blenvm/intern/bvm_expression.h
index 3e0cdfb..1401894 100644
--- a/source/blender/blenvm/BVM_module.h
+++ b/source/blender/blenvm/intern/bvm_expression.h
@@ -25,23 +25,52 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef __BVM_MODULE_H__
-#define __BVM_MODULE_H__
+#ifndef __BVM_EXPRESSION_H__
+#define __BVM_EXPRESSION_H__
-/** \file BVM_module.h
+/** \file bvm_expression.h
* \ingroup bvm
*/
-struct BVMFunction;
+#include <vector>
+#include <stdint.h>
-typedef struct BVMModule {
- struct GHash *functions;
-} BVMModule;
+#include "BVM_types.h"
+#include "bvm_util_string.h"
-void BVM_module_init(struct BVMModule *lib);
-void BVM_module_free(struct BVMModule *lib);
+namespace bvm {
-struct BVMFunction *BVM_module_create_function(struct BVMModule *mod, const char *name);
-bool BVM_module_delete_function(struct BVMModule *mod, const char *name);
+typedef int32_t Instruction;
+typedef std::vector<Instruction> InstructionList;
-#endif /* __BVM_MODULE_H__ */
+enum OpCode {
+ OP_NOOP = 0,
+ OP_END,
+ OP_JUMP,
+ OP_JUMP_IF_ZERO,
+ OP_JUMP_IF_ONE,
+};
+
+struct Expression {
+ struct ReturnValue {
+ BVMType type;
+ string name;
+ };
+ typedef std::vector<ReturnValue> ReturnValueList;
+
+ Expression();
+ ~Expression();
+
+ void add_return_value(BVMType type, const string &name = "");
+ size_t return_values_size() const;
+ const ReturnValue &return_value(size_t index) const;
+ const ReturnValue &return_value(const string &name) const;
+
+private:
+ ReturnValueList return_values;
+ InstructionList instructions;
+};
+
+} /* namespace bvm */
+
+#endif /* __BVM_EXPRESSION_H__ */
diff --git a/source/blender/blenvm/intern/bvm_function.cc b/source/blender/blenvm/intern/bvm_function.cc
index 7cabc58..94a1533 100644
--- a/source/blender/blenvm/intern/bvm_function.cc
+++ b/source/blender/blenvm/intern/bvm_function.cc
@@ -25,11 +25,14 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/blenvm/intern/function.cc
+/** \file bvm_function.cc
* \ingroup bvm
*/
#include "MEM_guardedalloc.h"
-#include "BVM_function.h"
+#include "bvm_function.h"
+namespace bvm {
+
+} /* namespace bvm */
diff --git a/source/blender/blenvm/BVM_function.h b/source/blender/blenvm/intern/bvm_function.h
similarity index 84%
copy from source/blender/blenvm/BVM_function.h
copy to source/blender/blenvm/intern/bvm_function.h
index f8d657c..1568d6e 100644
--- a/source/blender/blenvm/BVM_function.h
+++ b/source/blender/blenvm/intern/bvm_function.h
@@ -28,14 +28,23 @@
#ifndef __BVM_FUNCTION_H__
#define __BVM_FUNCTION_H__
-/** \file BVM_function.h
+/** \file bvm_function.h
* \ingroup bvm
*/
-#include "DNA_defs.h"
+#include "bvm_util_string.h"
-typedef struct BVMFunction {
- char name[MAX_NAME];
-} BVMFunction;
+namespace bvm {
+
+struct FunctionArgument {
+ string name;
+ bool is_return_value;
+};
+
+struct Function {
+ string name;
+};
+
+} /* namespace bvm */
#endif /* __BVM_FUNCTION_H__ */
diff --git a/source/blender/blenvm/intern/bvm_module.cc b/source/blender/blenvm/intern/bvm_module.cc
index cd61636..993b623 100644
--- a/source/blender/blenvm/intern/bvm_module.cc
+++ b/source/blender/blenvm/intern/bvm_module.cc
@@ -25,7 +25,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/blenvm/intern/module.cc
+/** \file bvm_module.cc
* \ingroup bvm
*/
@@ -39,42 +39,9 @@ extern "C" {
#include "MEM_guardedalloc.h"
-#include "BVM_function.h"
-#include "BVM_module.h"
+#include "bvm_function.h"
+#include "bvm_module.h"
-// forward declaration
-static void ghash_function_free(BVMFunction *fun);
+namespace bvm {
-void BVM_module_init(BVMModule *lib)
-{
- lib->f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list