Sat, 06 Jun 2015 10:46:29 +0200
implemented some davql integer operations
libidav/davqlexec.c | file | annotate | diff | comparison | revisions |
--- a/libidav/davqlexec.c Fri Jun 05 10:44:21 2015 +0200 +++ b/libidav/davqlexec.c Sat Jun 06 10:46:29 2015 +0200 @@ -561,9 +561,18 @@ stack = realloc(stack, stsize * sizeof(DavQLStackObj)); \ } \ stack[stpos++] = obj; +#define DAVQL_PUSH_INT(intval) \ + { \ + DavQLStackObj intobj; \ + intobj.type = 0; \ + intobj.length = 0; \ + intobj.data.integer = intval; \ + DAVQL_PUSH(intobj); \ + } #define DAVQL_POP() stack[--stpos] DavQLStackObj obj; + int ret = 0; for(size_t i=0;i<count;i++) { DavQLCmd cmd = cmds[i]; switch(cmd.type) { @@ -656,44 +665,121 @@ DAVQL_PUSH(obj); break; } - case DAVQL_CMD_OP_UNARY_ADD: { - printf("uadd\n"); - break; - } + //case DAVQL_CMD_OP_UNARY_ADD: { + // printf("uadd\n"); + // break; + //} case DAVQL_CMD_OP_UNARY_SUB: { printf("usub\n"); + obj = DAVQL_POP(); + if(obj.type == 0) { + obj.data.integer = -obj.data.integer; + DAVQL_PUSH(obj); + } else { + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_UNARY_NEG: { printf("uneg\n"); + obj = DAVQL_POP(); + if(obj.type == 0) { + obj.data.integer = obj.data.integer == 0 ? 1 : 0; + DAVQL_PUSH(obj); + } else { + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_BINARY_ADD: { printf("add\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer + obj2.data.integer); + } else { + // TODO: string concat + } break; } case DAVQL_CMD_OP_BINARY_SUB: { printf("sub\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer - obj2.data.integer); + } else { + // error + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_BINARY_MUL: { printf("mul\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer * obj2.data.integer); + } else { + // error + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_BINARY_DIV: { printf("div\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer / obj2.data.integer); + } else { + // error + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_BINARY_AND: { printf("and\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer & obj2.data.integer); + } else { + // error + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_BINARY_OR: { printf("or\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer | obj2.data.integer); + } else { + // error + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_BINARY_XOR: { printf("xor\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer ^ obj2.data.integer); + } else { + // error + ret = -1; + i = count; // end loop + } break; } case DAVQL_CMD_OP_LOGICAL_NOT: { @@ -718,54 +804,68 @@ } case DAVQL_CMD_OP_EQ: { printf("eq\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer == obj2.data.integer); + } else { + // TODO: string compare + } break; } case DAVQL_CMD_OP_NEQ: { printf("neq\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer != obj2.data.integer); + } else { + // TODO: string compare + } break; } case DAVQL_CMD_OP_LT: { printf("lt\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer < obj2.data.integer); + } else { + // TODO: string compare + } break; } case DAVQL_CMD_OP_GT: { printf("gt\n"); DavQLStackObj obj2 = DAVQL_POP(); DavQLStackObj obj1 = DAVQL_POP(); - // result - obj.type = 0; - obj.length = 0; - - int64_t int1; - int64_t int2; - int isint = 1; - if(obj1.type == 0) { - int1 = obj1.data.integer; + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer > obj2.data.integer); } else { - isint = util_strtoint(obj1.data.string, &int1); + // TODO: string compare } - if(isint) { - if(obj2.type == 0) { - int2 = obj2.data.integer; - } else { - isint = util_strtoint(obj2.data.string, &int2); - } - if(isint) { - obj.data.integer = int1 > int2; - } - } - - // string compare - // TODO - DAVQL_PUSH(obj); break; } case DAVQL_CMD_OP_LE: { printf("le\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer <= obj2.data.integer); + } else { + // TODO: string compare + } break; } case DAVQL_CMD_OP_GE: { printf("ge\n"); + DavQLStackObj obj2 = DAVQL_POP(); + DavQLStackObj obj1 = DAVQL_POP(); + if(obj1.type == 0 && obj2.type == 0) { + DAVQL_PUSH_INT(obj1.data.integer >= obj2.data.integer); + } else { + // TODO: string compare + } break; } case DAVQL_CMD_OP_LIKE: { @@ -783,7 +883,6 @@ } } - int ret = 0; if(stpos == 1) { *result = stack[0]; } else {