add FFI macros and refactor binding codes