static Value * _bool(const Ast *expr) { Value *rval = value_new(); char *s = expr->value; if(s[0] == 't' && s[1] == 'r' && s[2] == 'u' && s[3] == 'e' && s[4] == '\0') { // "true" value_set_bool(rval, true); } else if(s[0] == 'f' && s[1] == 'a' && s[2] == 'l' && s[3] == 's' && s[4] == 'e' && s[5] == '\0') { // "false" value_set_bool(rval, false); } else { assert(false); } return rval; }
static Value * _neq(const Ast *expr) { //Ast *op1 = expr->child; //Ast *op2 = expr->child->next; Value *rval = _eq(expr); value_set_bool(rval, !rval->as_bool); return rval; }
static Value * _not(const Ast *expr) { Ast *op1 = expr->child; Value *rval = eval(op1); value_set_bool(rval, !rval->as_bool); return rval; }
static Value * builtin_relation_is_bijective(Scope *args, MemorySpace *memspace) { Value *arg[] = { get_value_by_name(args, memspace, "0"), }; Value *rval = value_new(); value_set_bool(rval, rf_relation_is_bijective(arg[0]->as_Relation)); return rval; }
static Value * builtin_set_is_subset(Scope *args, MemorySpace *memspace) { Value *arg[] = { get_value_by_name(args, memspace, "0"), get_value_by_name(args, memspace, "1"), }; Value *rval = value_new(); value_set_bool(rval, rf_set_is_subset(arg[0]->as_Set, arg[1]->as_Set)); return rval; }
static Value * _gt(const Ast *expr) { Ast *op1 = expr->child; Ast *op2 = expr->child->next; Value *v1 = eval(op1); Value *v2 = eval(op2); Value *rval = v1; value_set_bool(rval, NATIVE_NUMBER(v1) > NATIVE_NUMBER(v2)); value_free(v2); return rval; }
static void _gui_enable_account_initialization(Config *config) { Section *root; Section *section; Value *value; root = config_get_root(config); if(!(section = section_find_first_child(root, "Global"))) { section = section_append_child(root, "Global"); } if(!(value = section_find_first_value(section, "first-account-initialized"))) { value = section_append_value(section, "first-account-initialization", VALUE_DATATYPE_BOOLEAN); } value_set_bool(value, TRUE); }
static Value * _eq(const Ast *expr) { Ast *op1 = expr->child; Ast *op2 = expr->child->next; Value *v1 = eval(op1); Value *v2 = eval(op2); Value *rval = v1; if(v1->type != v2->type) { value_set_bool(rval, false); } else { switch(v1->type) { case T_BOOL: value_set_bool(rval, v1->as_bool == v2->as_bool); break; case T_INT: value_set_bool(rval, v1->as_int == v2->as_int); break; case T_FLOAT: value_set_bool(rval, fabs((v1->as_float - v2->as_float)) < 0.05); break; case T_STRING: value_set_bool(rval, strcmp(v1->as_String, v2->as_String) == 0); break; case T_SET: value_set_bool(rval, rf_set_equal(v1->as_Set, v2->as_Set)); break; case T_R: value_set_bool(rval, rf_relation_equal(v1->as_Relation, v2->as_Relation)); break; } } value_free(v2); return rval; }