Check-in [543cc53004]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added displaying of callback argument typetags to info command
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:543cc530048fbd1ec457d74744c22072ce4c4deddf8b04d4a89d8c750b2f7d88
User & Date: grable 2018-10-31 20:03:50
Context
2018-10-31
20:16
changes for testing callback typetags check-in: 87ae944ab1 user: grable tags: trunk
20:03
added displaying of callback argument typetags to info command check-in: 543cc53004 user: grable tags: trunk
19:42
fixed jimff_call: now using correct pointer size, and added callback typetag checking as well check-in: 73f8e5bc20 user: grable tags: trunk
Changes

Changes to jimff-callback.c.

44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	OBJ_SET_CALLBACK(obj);
	OBJ_CALLBACK(obj) = cb;
	OBJ_CALLBACK_EPOCH(obj) = ctx->epoch;
	
	return obj;
}


JIMFF_API struct jimff_callback* jimff_getcallback( struct jimff_context* ctx, Jim_Obj* obj) {
	assert( ctx );
	assert( obj );
	
#define PREFIXLEN	(sizeof(JIMFF_CALLBACK_OBJ_PREFIX) - 1)	
	
	struct jimff_callback* cb;
	int strl;
	const char* strp;

	if(OBJ_IS_CALLBACK(obj)) {
		if(OBJ_CALLBACK_EPOCH(obj) != ctx->epoch) return NULL;
		struct jimff_callback* cb = OBJ_CALLBACK(obj);
		//TODO: find a better way to compare callback typetags, especially now that typetags are preprocessed, it kinda useless
		//if(typetag && strcmp( typetag, cb->typeinfo.typetag)) return NULL;
		return cb;
	}

	//TODO: should we lookup both string representaions of a callbacks or at all?
	strp = Jim_GetString( obj, &strl);
	if(strl == 0) return NULL;
	cb = jimff_find_callback( ctx, strp);
	if(cb) goto got_callback;
	if(strl > PREFIXLEN && (cb = jimff_find_callback( ctx, strp + PREFIXLEN))) goto got_callback;
	return NULL;
	
got_callback:
	//if(typetag && strcmp( typetag, cb->typeinfo.typetag)) return NULL;
	//TODO: should we update the jimobj to a callback objtype on success?
	Jim_FreeIntRep( ctx->interp, obj);
	OBJ_SET_CALLBACK(obj);
	OBJ_CALLBACK(obj) = cb;
	OBJ_CALLBACK_EPOCH(obj) = ctx->epoch;
	return cb;
	







>












|
<
<
<











<







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64



65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
	OBJ_SET_CALLBACK(obj);
	OBJ_CALLBACK(obj) = cb;
	OBJ_CALLBACK_EPOCH(obj) = ctx->epoch;
	
	return obj;
}

//TODO: maybe add callback typechecking here
JIMFF_API struct jimff_callback* jimff_getcallback( struct jimff_context* ctx, Jim_Obj* obj) {
	assert( ctx );
	assert( obj );
	
#define PREFIXLEN	(sizeof(JIMFF_CALLBACK_OBJ_PREFIX) - 1)	
	
	struct jimff_callback* cb;
	int strl;
	const char* strp;

	if(OBJ_IS_CALLBACK(obj)) {
		if(OBJ_CALLBACK_EPOCH(obj) != ctx->epoch) return NULL;
		return OBJ_CALLBACK(obj);



	}

	//TODO: should we lookup both string representaions of a callbacks or at all?
	strp = Jim_GetString( obj, &strl);
	if(strl == 0) return NULL;
	cb = jimff_find_callback( ctx, strp);
	if(cb) goto got_callback;
	if(strl > PREFIXLEN && (cb = jimff_find_callback( ctx, strp + PREFIXLEN))) goto got_callback;
	return NULL;
	
got_callback:

	//TODO: should we update the jimobj to a callback objtype on success?
	Jim_FreeIntRep( ctx->interp, obj);
	OBJ_SET_CALLBACK(obj);
	OBJ_CALLBACK(obj) = cb;
	OBJ_CALLBACK_EPOCH(obj) = ctx->epoch;
	return cb;
	

Changes to jimff-commands.c.

4
5
6
7
8
9
10



11
12
13
14
15
16
17
...
677
678
679
680
681
682
683































684
685
686
687
688
689
690
...
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
...
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
 */

#define JIMFF_PACKAGE_NAME			"jimff"
#define JIMFF_PACKAGE_VERSION		"1.0"

#define JIMFF_COMMAND_NAME			"jimff"




#ifndef JIMFF_DISABLE_INFO_COMMAND
	#define __jimff_the_info_command(_)	_( info, fn_context_info, NULL )
#else
	#define __jimff_the_info_command(_)
#endif

//
................................................................................
	
err_length_oob:
	Jim_SetResultFormatted( interp, "%#s: length for pointer \"%#s\" is out of bounds", argv[0], argv[1]);
	return JIM_ERR;
}

#ifndef JIMFF_DISABLE_INFO_COMMAND































static int fn_context_info( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	static const char * const infomodes[] = { "-help", "-libraries", "-symbols", "-functions", "-variables", "-callbacks", NULL };
	enum { INFO_HELP, INFO_LIBRARIES, INFO_SYMBOLS, INFO_FUNCTIONS, INFO_VARIABLES, INFO_CALLBACKS };

	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);		
	Jim_Obj* list = NULL;
................................................................................
				for JIMFF_LIST_EACH( lib, ctx->libs) {
					for JIMFF_LIST_EACH( sym, lib->syms) {
						if(sym->flags & JIMFF_FLAG_DELETED) continue;
						if((mode == INFO_SYMBOLS) ||
							(mode == INFO_FUNCTIONS && sym->tag == JIMFF_SYM_FUNCTION) || 
							(mode == INFO_VARIABLES && sym->tag == JIMFF_SYM_VARIABLE)) {
							Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, sym->name, -1));
							if(typetags) Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, sym->typeinfo.typetag, -1));
						}
					}
				}
			} else if(argc == 2) {
				struct jimff_library* lib;
				if(Jim_CompareStringImmediate( interp, argv[1], JIMFF_SELFLIBRARY_NAME)) {
					lib = jimff_find_library( ctx, NULL);
................................................................................
				list = Jim_NewListObj( interp, NULL, 0);
				for JIMFF_LIST_EACH( sym, lib->syms) {
					if(sym->flags & JIMFF_FLAG_DELETED) continue;
					if((mode == INFO_SYMBOLS) ||
						(mode == INFO_FUNCTIONS && sym->tag == JIMFF_SYM_FUNCTION) ||
						(mode == INFO_VARIABLES && sym->tag == JIMFF_SYM_VARIABLE)) {
						Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, sym->name, -1));
						if(typetags) Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, sym->typeinfo.typetag, -1));
					}
				}
			} else {
				goto wrongnumargs;
			}
			break;
			
		case INFO_CALLBACKS:
			if(argc != 1) goto wrongnumargs;
			list = Jim_NewListObj( interp, NULL, 0);
			for JIMFF_LIST_EACH( cb, ctx->cbs) {
				if(!(cb->flags & JIMFF_FLAG_REGISTERED)) continue;
				Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, cb->name, -1));
				if(typetags) Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, cb->typeinfo.typetag, -1));
				else if(commands) Jim_ListAppendElement( interp, list, cb->command ?: Jim_NewStringObj( interp, cb->name, -1));
			}
			break;
	}

done:
	if(list) {







>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|













|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
...
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
 */

#define JIMFF_PACKAGE_NAME			"jimff"
#define JIMFF_PACKAGE_VERSION		"1.0"

#define JIMFF_COMMAND_NAME			"jimff"

// set to 1 for space between typetag elements
#define JIMFF_INFO_PRETTY_TYPETAGS	0

#ifndef JIMFF_DISABLE_INFO_COMMAND
	#define __jimff_the_info_command(_)	_( info, fn_context_info, NULL )
#else
	#define __jimff_the_info_command(_)
#endif

//
................................................................................
	
err_length_oob:
	Jim_SetResultFormatted( interp, "%#s: length for pointer \"%#s\" is out of bounds", argv[0], argv[1]);
	return JIM_ERR;
}

#ifndef JIMFF_DISABLE_INFO_COMMAND
static Jim_Obj* jimff_typeinfo_typetag( Jim_Interp* interp, struct jimff_typeinfo* typeinfo, int pretty) {
	Jim_Obj* str = Jim_NewStringObj( interp, "", -1);
	int nump = 0;
	int numcb = 0;
	char buffer[256];
	for( int i=0; i<=typeinfo->argc; i++) {
		if(i > 0 && pretty) Jim_AppendString( interp, str, " ", 1);
		Jim_AppendString( interp, str, &typeinfo->typetag[i], 1);
		switch(typeinfo->typetag[i]) {
			case 'p':
			case 'P':
				if(typeinfo->pointersizes[nump] > 0) {
					sprintf( buffer, "%d", typeinfo->pointersizes[nump]);
					if(pretty) Jim_AppendString( interp, str, " ", 1);
					Jim_AppendString( interp, str, buffer, -1);
				}
				nump++;
				break;
			case 'x':
				if(typeinfo->callbacks[numcb] != NULL) {
					sprintf( buffer, "(%s)", typeinfo->callbacks[numcb]);
					if(pretty) Jim_AppendString( interp, str, " ", 1);
					Jim_AppendString( interp, str, buffer, -1);
				}
				numcb++;
				break;
		}
	}
	return str;
}

static int fn_context_info( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	static const char * const infomodes[] = { "-help", "-libraries", "-symbols", "-functions", "-variables", "-callbacks", NULL };
	enum { INFO_HELP, INFO_LIBRARIES, INFO_SYMBOLS, INFO_FUNCTIONS, INFO_VARIABLES, INFO_CALLBACKS };

	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);		
	Jim_Obj* list = NULL;
................................................................................
				for JIMFF_LIST_EACH( lib, ctx->libs) {
					for JIMFF_LIST_EACH( sym, lib->syms) {
						if(sym->flags & JIMFF_FLAG_DELETED) continue;
						if((mode == INFO_SYMBOLS) ||
							(mode == INFO_FUNCTIONS && sym->tag == JIMFF_SYM_FUNCTION) || 
							(mode == INFO_VARIABLES && sym->tag == JIMFF_SYM_VARIABLE)) {
							Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, sym->name, -1));
							if(typetags) Jim_ListAppendElement( interp, list, jimff_typeinfo_typetag( interp, &sym->typeinfo, JIMFF_INFO_PRETTY_TYPETAGS));
						}
					}
				}
			} else if(argc == 2) {
				struct jimff_library* lib;
				if(Jim_CompareStringImmediate( interp, argv[1], JIMFF_SELFLIBRARY_NAME)) {
					lib = jimff_find_library( ctx, NULL);
................................................................................
				list = Jim_NewListObj( interp, NULL, 0);
				for JIMFF_LIST_EACH( sym, lib->syms) {
					if(sym->flags & JIMFF_FLAG_DELETED) continue;
					if((mode == INFO_SYMBOLS) ||
						(mode == INFO_FUNCTIONS && sym->tag == JIMFF_SYM_FUNCTION) ||
						(mode == INFO_VARIABLES && sym->tag == JIMFF_SYM_VARIABLE)) {
						Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, sym->name, -1));
						if(typetags) Jim_ListAppendElement( interp, list, jimff_typeinfo_typetag( interp, &sym->typeinfo, JIMFF_INFO_PRETTY_TYPETAGS));
					}
				}
			} else {
				goto wrongnumargs;
			}
			break;
			
		case INFO_CALLBACKS:
			if(argc != 1) goto wrongnumargs;
			list = Jim_NewListObj( interp, NULL, 0);
			for JIMFF_LIST_EACH( cb, ctx->cbs) {
				if(!(cb->flags & JIMFF_FLAG_REGISTERED)) continue;
				Jim_ListAppendElement( interp, list, Jim_NewStringObj( interp, cb->name, -1));
				if(typetags) Jim_ListAppendElement( interp, list, jimff_typeinfo_typetag( interp, &cb->typeinfo, JIMFF_INFO_PRETTY_TYPETAGS));
				else if(commands) Jim_ListAppendElement( interp, list, cb->command ?: Jim_NewStringObj( interp, cb->name, -1));
			}
			break;
	}

done:
	if(list) {