From 5dbbcf87423edb96cde7dfe59a2c8ef0a9d8ae2f Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sun, 24 Jan 2010 12:56:45 +1000 Subject: Simplify and speed up expr *: Reuse the ParseTokenList/ScriptToken machinery for 'expr' *: This is simpler than managing separate opcode/obj arrays *: expr opcodes are now in the same namespace as token types *: expr identifies int and double during parsing *: Move the 'while' common expr optimisations into Jim_EvalExpression *: Add a special trueObj and falseObj to help with these boolean optimisations *: Add lazy versions as the byte code is created instead of at the end *: Avoid repeated conversion attempts to int *: Once an object fails conversion to int and succeeds conversion to double, invalidate the string rep so the int conversion attempt no longer happens *: Also, avoid converting non-ints to int in expression optimisation *: No need for a string token for SEP and EOL tokens *: Fix shimmering of int -> double *: When an int shimmers to a double during an expression, remember that the value was originally an int (via a new type, coerced double) --- jim.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'jim.h') diff --git a/jim.h b/jim.h index dc4adfa..6ff5e33 100644 --- a/jim.h +++ b/jim.h @@ -515,6 +515,8 @@ typedef struct Jim_Interp { Jim_Obj *freeList; /* Linked list of all the unused objects. */ Jim_Obj *currentScriptObj; /* Script currently in execution. */ Jim_Obj *emptyObj; /* Shared empty string object. */ + Jim_Obj *trueObj; /* Shared true int object. */ + Jim_Obj *falseObj; /* Shared false int object. */ unsigned jim_wide referenceNextId; /* Next id for reference. */ struct Jim_HashTable references; /* References hash table. */ jim_wide lastCollectId; /* reference max Id of the last GC @@ -549,6 +551,8 @@ typedef struct Jim_Interp { #define Jim_SetResultString(i,s,l) Jim_SetResult(i, Jim_NewStringObj(i,s,l)) #define Jim_SetResultInt(i,intval) Jim_SetResult(i, Jim_NewIntObj(i,intval)) #define Jim_SetEmptyResult(i) Jim_SetResult(i, (i)->emptyObj) +#define Jim_SetTrueResult(i) Jim_SetResult(i, (i)->trueObj) +#define Jim_SetFalseResult(i) Jim_SetResult(i, (i)->falseObj) #define Jim_GetResult(i) ((i)->result) #define Jim_CmdPrivData(i) ((i)->cmdPrivData) -- cgit v1.1