Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | cleanup wrap/unwrap macros |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f53309743a0ae3a2bdccd8bc5cea8d0c |
User & Date: | grable 2018-11-01 04:38:02.936 |
Context
2018-11-01
| ||
04:39 | removed old todo check-in: 175cec980d user: grable tags: trunk | |
04:38 | cleanup wrap/unwrap macros check-in: f53309743a user: grable tags: trunk | |
04:30 | reworked wrap command for parity with unwrap, though pointer sizes remain check-in: 592303ad28 user: grable tags: trunk | |
Changes
Changes to jimff-commands.c.
︙ | ︙ | |||
488 489 490 491 492 493 494 495 496 497 498 499 500 501 | return JIM_ERR; err_not_dynamic_pointer: Jim_SetResultFormatted( ctx->interp, "%#s %s: argument #1 \"%#s\" is not a valid dynamic pointer", argv0, modes[mode], argv[1]); return JIM_ERR; } static int fn_pointer_unwrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) { Jim_Obj* argv0 = argv[0]; struct jimff_context* ctx = Jim_CmdPrivData(interp); int packed = 0; void* ptr; int size; int len; | > > > > > > > > > > > > > > > > > | 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | return JIM_ERR; err_not_dynamic_pointer: Jim_SetResultFormatted( ctx->interp, "%#s %s: argument #1 \"%#s\" is not a valid dynamic pointer", argv0, modes[mode], argv[1]); return JIM_ERR; } //NOTE: macros used by wrap/unwrap commands #define struct_ptr(t) ((t*)(ptr + offs)) #define struct_elem_ptr(t,sz) ({ t* _ptr = struct_ptr(t); offs += (sz); _ptr; }) #define struct_get(t) ({ t _val = *struct_ptr(t); offs += sizeof(t); _val; }) #define struct_set(t,v) ({*struct_ptr(t) = (v); offs += sizeof(t); }) #define struct_get_ptrflags(tag) ((*t == tag) ? JIMFF_DYNAMIC_POINTER_FLAGS : 0) #define struct_get_s( tag, type) ((*t == tag) ? struct_get(signed type) : struct_get(unsigned type)) #define struct_get_u( tag, type) ((*t == tag) ? struct_get(unsigned type) : struct_get(signed type)) #define struct_get_f(tag) ((*t == tag) ? struct_get(float) : struct_get(double)) #define struct_set_s( tag, type, val) ((*t == tag) ? struct_set( signed type, val) : struct_set( unsigned type, val)) #define struct_set_u( tag, type, val) ((*t == tag) ? struct_set( unsigned type, val) : struct_set( signed type, val)) #define struct_set_f( tag, val) ((*t == tag) ? struct_set( float, val) : struct_set( double, val)) static int fn_pointer_unwrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) { Jim_Obj* argv0 = argv[0]; struct jimff_context* ctx = Jim_CmdPrivData(interp); int packed = 0; void* ptr; int size; int len; |
︙ | ︙ | |||
533 534 535 536 537 538 539 | if(argc == 3) { list = Jim_NewListObj( interp, NULL, 0); } else { list = NULL; index = 3; } | | < < < < < < < < < < | 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | if(argc == 3) { list = Jim_NewListObj( interp, NULL, 0); } else { list = NULL; index = 3; } #define GET_ELEM(v) ({ lastobj = (v); \ if(list) Jim_ListAppendElement( interp, list, lastobj); \ else Jim_SetVariable( interp, argv[index++], lastobj); }) offs = 0; for( const char* t = typetag; *t;) { if(!list && index >= argc) { |
︙ | ︙ | |||
749 750 751 752 753 754 755 756 757 758 759 760 761 762 | err_structs_unsupported: Jim_SetResultFormatted( interp, "%#s: structs not supported", argv0); return JIM_ERR; err_too_many_args: Jim_SetResultFormatted( interp, "%#s: there are more arguments than elements in the typetag", argv0); return JIM_ERR; } //TODO: rework wrap command the same way as the new unwrap command, with array support. static int fn_pointer_wrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) { Jim_Obj* argv0 = argv[0]; struct jimff_context* ctx = Jim_CmdPrivData(interp); int packed = 0; | > > | 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | err_structs_unsupported: Jim_SetResultFormatted( interp, "%#s: structs not supported", argv0); return JIM_ERR; err_too_many_args: Jim_SetResultFormatted( interp, "%#s: there are more arguments than elements in the typetag", argv0); return JIM_ERR; #undef GET_ELEM } //TODO: rework wrap command the same way as the new unwrap command, with array support. static int fn_pointer_wrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) { Jim_Obj* argv0 = argv[0]; struct jimff_context* ctx = Jim_CmdPrivData(interp); int packed = 0; |
︙ | ︙ | |||
800 801 802 803 804 805 806 | if(argc == 4 && len > 1) { list = argv[3]; index = 0; } else { list = NULL; index = 3; } | < < < < < < | 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | if(argc == 4 && len > 1) { list = argv[3]; index = 0; } else { list = NULL; index = 3; } #define GET_ARG() (lastobj = (list ? Jim_ListGetIndex( interp, list, index++) : argv[index++])) offs = 0; for( const char* t = typetag; *t;) { if(list) { if(index >= Jim_ListLength( interp, list)) goto err_not_enough_args; |
︙ | ︙ | |||
1080 1081 1082 1083 1084 1085 1086 | Jim_SetResultFormatted( interp, "%#s: not enough arguments for typetag \"%#s\"", argv0, argv[2]); return JIM_ERR; err_too_many_args: Jim_SetResultFormatted( interp, "%#s: too many arguments for typetag \"%#s\"", argv0, argv[2]); return JIM_ERR; | < > > > > > > > > > > > > > > | 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 | Jim_SetResultFormatted( interp, "%#s: not enough arguments for typetag \"%#s\"", argv0, argv[2]); return JIM_ERR; err_too_many_args: Jim_SetResultFormatted( interp, "%#s: too many arguments for typetag \"%#s\"", argv0, argv[2]); return JIM_ERR; #undef GET_ARG } //NOTE: wrap/unwrap macros #define struct_ptr #define struct_elem_ptr #define struct_get #define struct_set #define struct_get_ptrflags #define struct_get_s #define struct_get_u #define struct_get_f #define struct_set_s #define struct_set_u #define struct_set_f // out of bounds checking used by various raw pointer commands, if len=0 it is ignored #define check_oob( name, ptr, size, offs, len) \ void* name ## _start = (ptr) + (offs); \ void* name ## _stop = (ptr) + (size); \ if(name ## _start < (ptr)) goto err_offset_oob; \ if(name ## _stop > (ptr)) { \ |
︙ | ︙ |