Check-in [381dd22404]

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

Overview
Comment:added optional support for jimtcl varaccess, for better variables. though it requires a customized jimtcl
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:381dd22404f192d076bdae84ff00810d80252befdae435f7bb287a403cac48bf
User & Date: grable 2018-11-02 16:27:52
Context
2018-11-02
16:36
set varacces to disabled as default check-in: 3fde67ba9a user: grable tags: trunk
16:27
added optional support for jimtcl varaccess, for better variables. though it requires a customized jimtcl check-in: 381dd22404 user: grable tags: trunk
2018-11-01
19:24
added BlitzMax test to makefile check-in: a52e2db53b user: grable tags: trunk
Changes

Changes to jimff-commands.c.

208
209
210
211
212
213
214

215

216
217
218
219
220
221
222
...
302
303
304
305
306
307
308









309
310
311
312
313



314
315
316
317
318
319
320
321
322
		[JIMFF_SYM_FUNCTION] = "-function",
		[JIMFF_SYM_VARIABLE] = "-variable",
		[JIMFF_SYM_POINTER] = "-pointer",
		NULL,
	};
	static Jim_CmdProc* const symbolcmdfns[] = {
		[JIMFF_SYM_FUNCTION] = fn_symbol_call,

		[JIMFF_SYM_VARIABLE] = fn_symbol_set,

		/* pointers are objects set to variables instead of commands */
	};
	
	if(argc < 2) {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv, "?-function | -variable | -pointer? ?" JIMFF_SELFLIBRARY_NAME " | library? {name ?alias?} typetag");
		return JIM_ERR;
................................................................................
											argv0, name, lib ? lib->name : NULL);
		return JIM_ERR;
	} else if(sym == JIMFF_INVALID_TYPETAG) {
		Jim_SetResultFormatted( interp, "%#s: invalid typetag for symbol \"%s\"", argv0, name);
		return JIM_ERR;
	}
	









	if(symboltype == JIMFF_SYM_POINTER) {
		Jim_Obj* ptrobj = jimff_newpointer( ctx, sym->addr, sym->size, 0);
		Jim_SetVariableStr( interp, sym->name, ptrobj);
		Jim_SetResult( interp, ptrobj);
	} else {



		if(Jim_CreateCommand( interp, sym->name, symbolcmdfns[symboltype], sym, free_sym) != JIM_OK) return JIM_ERR;
		Jim_SetResultString( interp, sym->name, -1);
	}
	return JIM_OK;
}

static int fn_context_callback( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);







>

>







 







>
>
>
>
>
>
>
>
>
|
|
|
|
<
>
>
>
|
|







208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
332
333
334
335
		[JIMFF_SYM_FUNCTION] = "-function",
		[JIMFF_SYM_VARIABLE] = "-variable",
		[JIMFF_SYM_POINTER] = "-pointer",
		NULL,
	};
	static Jim_CmdProc* const symbolcmdfns[] = {
		[JIMFF_SYM_FUNCTION] = fn_symbol_call,
#ifndef JIMFF_ENABLE_JIM_VARACCESS
		[JIMFF_SYM_VARIABLE] = fn_symbol_set,
#endif
		/* pointers are objects set to variables instead of commands */
	};
	
	if(argc < 2) {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv, "?-function | -variable | -pointer? ?" JIMFF_SELFLIBRARY_NAME " | library? {name ?alias?} typetag");
		return JIM_ERR;
................................................................................
											argv0, name, lib ? lib->name : NULL);
		return JIM_ERR;
	} else if(sym == JIMFF_INVALID_TYPETAG) {
		Jim_SetResultFormatted( interp, "%#s: invalid typetag for symbol \"%s\"", argv0, name);
		return JIM_ERR;
	}
	
	switch(symboltype) {
#ifdef JIMFF_ENABLE_JIM_VARACCESS
		case JIMFF_SYM_VARIABLE: {
			Jim_Obj* varname = Jim_NewStringObj( interp, sym->name, -1);
			Jim_SetVariableAccess( interp, varname, jimff_varaccess, NULL, NULL, sym);
			Jim_SetResult( interp, varname);
			break;
		}
#endif
		case JIMFF_SYM_POINTER: {
			Jim_Obj* ptrobj = jimff_newpointer( ctx, sym->addr, sym->size, 0);
			Jim_SetVariableStr( interp, sym->name, ptrobj);
			Jim_SetResult( interp, ptrobj);

			break;
		}
		default:
			if(Jim_CreateCommand( interp, sym->name, symbolcmdfns[symboltype], sym, free_sym) != JIM_OK) return JIM_ERR;
			Jim_SetResultString( interp, sym->name, -1);
	}
	return JIM_OK;
}

static int fn_context_callback( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);

Changes to jimff-set.c.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77












#define jimff_get( interp, sym)	jimff_set( (interp), (sym), NULL)

JIMFF_API Jim_Obj* jimff_set( struct jimff_context* ctx, const struct jimff_symbol* sym, Jim_Obj* value) {
	assert( ctx );
	assert( sym );

	
#define DPFLAGS					((sym->typeinfo.typetag[0] == 'P') ? JIMFF_DYNAMIC_POINTER_FLAGS : 0)
	
#define SYMVAR(tag)				(((union jimff_result*)sym->addr)->tag)
	
#define GET_INT(tag)			Jim_NewIntObj( ctx->interp, SYMVAR(tag))
#define GET_FLOAT(tag)		Jim_NewDoubleObj( ctx->interp, SYMVAR(tag))
#define GET_STRING(tag)		Jim_NewStringObj( ctx->interp, SYMVAR(tag), -1)
................................................................................
													SYMVAR(tag) = tmp.p;																		\
												} else {																									\
													tmp.p = jimff_getpointer( ctx, value, &ptrsize, 0);								\
													if(ptrsize == -1) return NULL;																\
													if(sym->typeinfo.pointersizes[0] && sym->typeinfo.pointersizes[0] != ptrsize)return NULL;			\
													SYMVAR(tag) = tmp.p;																		\
												} })
												
	
	union jimff_result tmp = { 0 };
	int ptrsize;
	
	switch(sym->typeinfo.returntype) {
		case JIMFF_TYPE_VOID:			return NULL;
		case JIMFF_TYPE_CHAR:
................................................................................
		case JIMFF_TYPE_FLOAT:			if(value) SET_FLOAT(f); else return GET_FLOAT(f); break;
		case JIMFF_TYPE_DOUBLE:		if(value) SET_FLOAT(d); else return GET_FLOAT(d); break;
		case JIMFF_TYPE_VOIDP:			if(value) SET_VOIDP(p); else return GET_VOIDP(p); break;
		case JIMFF_TYPE_STRUCT:			return NULL;
	}
	
#undef SYMVAR
	#undef DPFLAGS
#undef GET_INT
#undef GET_FLOAT
#undef GET_STRING
#undef GET_POINTER
#undef GET_VOIDP
#undef SET_INT
#undef SET_FLOAT
#undef SET_VOIDP
	
	return value;
}


















<







 







<







 







|











>
>
>
>
>
>
>
>
>
>
>
5
6
7
8
9
10
11

12
13
14
15
16
17
18
..
33
34
35
36
37
38
39

40
41
42
43
44
45
46
..
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
86

#define jimff_get( interp, sym)	jimff_set( (interp), (sym), NULL)

JIMFF_API Jim_Obj* jimff_set( struct jimff_context* ctx, const struct jimff_symbol* sym, Jim_Obj* value) {
	assert( ctx );
	assert( sym );


#define DPFLAGS					((sym->typeinfo.typetag[0] == 'P') ? JIMFF_DYNAMIC_POINTER_FLAGS : 0)
	
#define SYMVAR(tag)				(((union jimff_result*)sym->addr)->tag)
	
#define GET_INT(tag)			Jim_NewIntObj( ctx->interp, SYMVAR(tag))
#define GET_FLOAT(tag)		Jim_NewDoubleObj( ctx->interp, SYMVAR(tag))
#define GET_STRING(tag)		Jim_NewStringObj( ctx->interp, SYMVAR(tag), -1)
................................................................................
													SYMVAR(tag) = tmp.p;																		\
												} else {																									\
													tmp.p = jimff_getpointer( ctx, value, &ptrsize, 0);								\
													if(ptrsize == -1) return NULL;																\
													if(sym->typeinfo.pointersizes[0] && sym->typeinfo.pointersizes[0] != ptrsize)return NULL;			\
													SYMVAR(tag) = tmp.p;																		\
												} })

	
	union jimff_result tmp = { 0 };
	int ptrsize;
	
	switch(sym->typeinfo.returntype) {
		case JIMFF_TYPE_VOID:			return NULL;
		case JIMFF_TYPE_CHAR:
................................................................................
		case JIMFF_TYPE_FLOAT:			if(value) SET_FLOAT(f); else return GET_FLOAT(f); break;
		case JIMFF_TYPE_DOUBLE:		if(value) SET_FLOAT(d); else return GET_FLOAT(d); break;
		case JIMFF_TYPE_VOIDP:			if(value) SET_VOIDP(p); else return GET_VOIDP(p); break;
		case JIMFF_TYPE_STRUCT:			return NULL;
	}
	
#undef SYMVAR
#undef DPFLAGS
#undef GET_INT
#undef GET_FLOAT
#undef GET_STRING
#undef GET_POINTER
#undef GET_VOIDP
#undef SET_INT
#undef SET_FLOAT
#undef SET_VOIDP
	
	return value;
}

#ifdef JIMFF_ENABLE_JIM_VARACCESS
static Jim_Obj* jimff_varaccess( struct Jim_Interp* interp, struct Jim_Var* var, int set, Jim_Obj* name, Jim_Obj* value) {
	struct jimff_symbol* sym = var->privdata;
	if(set) {
		return jimff_set( sym->library->ctx, sym, value);
	} else {
		return jimff_get( sym->library->ctx, sym);
	}
}
#endif

Changes to jimff.c.

25
26
27
28
29
30
31



32
33
34
35
36
37
38

/****************************************************************************************************
 * jimff config
 */
 
// define this to disable the context info command
//#define JIMFF_DISABLE_INFO_COMMAND





/****************************************************************************************************
 * jimff misc
 */

#include "strrpbrk.c"







>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

/****************************************************************************************************
 * jimff config
 */
 
// define this to disable the context info command
//#define JIMFF_DISABLE_INFO_COMMAND

// define this to enable custom variable access in jimtcl
#define JIMFF_ENABLE_JIM_VARACCESS


/****************************************************************************************************
 * jimff misc
 */

#include "strrpbrk.c"

Changes to tests/jimff_test_all.tcl.

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
# testing functions
#
print "printed using:\t::print"
ff::print "printed using:\tff::print"
puts {}

#
# testing variables 
#


puts "test_var_i = [test_var_i]"
puts "test_var_f = [test_var_f]"
puts "test_var_z = \"[test_var_z]\""
puts "changing the variables..."
test_var_i 200
test_var_f 3.21
test_var_z "Goodbye World?"
puts "test_var_i = [test_var_i]"
puts "test_var_f = [test_var_f]"
puts "test_var_z = \"[test_var_z]\""













puts {}

#
# testing pointer variables and external pointers
#
puts "test_array size = [ff::pointer -size $test_array]"
puts "test_array = $test_array"







|

>
>
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>







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
86
87
88
89
# testing functions
#
print "printed using:\t::print"
ff::print "printed using:\tff::print"
puts {}

#
# testing variables, can be either a command or a variable if jimtcl varaccess is enabled
#
if {[exists -command test_var_i]} {
	puts "variables are commands"
	puts "test_var_i = [test_var_i]"
	puts "test_var_f = [test_var_f]"
	puts "test_var_z = \"[test_var_z]\""
	puts "changing the variables..."
	test_var_i 200
	test_var_f 3.21
	test_var_z "Goodbye World?"
	puts "test_var_i = [test_var_i]"
	puts "test_var_f = [test_var_f]"
	puts "test_var_z = \"[test_var_z]\""
} else {
	puts "variables are variables"
	puts "test_var_i = $test_var_i"
	puts "test_var_f = $test_var_f"
	puts "test_var_z = \"$test_var_z\""
	puts "changing the variables..."
	set test_var_i 200
	set test_var_f 3.21
	set test_var_z "Goodbye World?"
	puts "test_var_i = $test_var_i"
	puts "test_var_f = $test_var_f"
	puts "test_var_z = \"$test_var_z\""
}
puts {}

#
# testing pointer variables and external pointers
#
puts "test_array size = [ff::pointer -size $test_array]"
puts "test_array = $test_array"