Changes in uspace/app/sbi/src/run_expr.c [051b3db8:c5cb943d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run_expr.c
r051b3db8 rc5cb943d 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 113 113 static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res); 114 114 static void run_call_args(run_t *run, list_t *args, list_t *arg_vals); 115 static void run_destroy_arg_vals(list_t *arg_vals);116 115 117 116 static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res); … … 201 200 rdata_address_t *address; 202 201 rdata_addr_var_t *addr_var; 203 rdata_addr_prop_t *addr_prop;204 rdata_aprop_named_t *aprop_named;205 rdata_deleg_t *deleg_p;206 202 rdata_value_t *value; 207 203 rdata_var_t *var; … … 338 334 break; 339 335 case sc_var: 340 case sc_prop: 341 #ifdef DEBUG_RUN_TRACE 342 if (sym->sc == sc_var) 343 printf("Referencing member variable.\n"); 344 else 345 printf("Referencing unqualified property.\n"); 346 #endif 347 /* There should be no global variables or properties. */ 336 #ifdef DEBUG_RUN_TRACE 337 printf("Referencing member variable.\n"); 338 #endif 339 /* There should be no global variables. */ 348 340 assert(csi != NULL); 349 341 350 342 if (symbol_search_csi(run->program, csi, nameref->name) 351 343 == NULL && !stree_symbol_is_static(sym)) { 352 /* Symbolis not in the current object. */344 /* Variable is not in the current object. */ 353 345 printf("Error: Cannot access non-static member " 354 346 "variable '"); … … 360 352 } 361 353 362 /*363 * Determine object in which the symbol resides364 */365 354 if (stree_symbol_is_static(sym)) { 366 355 /* 367 * Class object368 356 * XXX This is too slow! 369 357 * … … 377 365 aobj = sobj->u.object_v; 378 366 } else { 379 /* 380 * Instance object. Currently we don't support 381 * true inner classes, thus we know the symbol is 382 * in the active object (there is no dynamic parent). 383 */ 384 sobj = proc_ar->obj; 385 aobj = sobj->u.object_v;; 367 aobj = obj; 386 368 } 387 369 388 if (sym->sc == sc_var) { 389 /* Find member variable in object. */ 390 member_var = intmap_get(&aobj->fields, 391 nameref->name->sid); 392 assert(member_var != NULL); 393 394 /* Return address of the variable. */ 395 item = rdata_item_new(ic_address); 396 address = rdata_address_new(ac_var); 397 addr_var = rdata_addr_var_new(); 398 399 item->u.address = address; 400 address->u.var_a = addr_var; 401 addr_var->vref = member_var; 402 403 *res = item; 404 } else { 405 /* Construct named property address. */ 406 item = rdata_item_new(ic_address); 407 address = rdata_address_new(ac_prop); 408 addr_prop = rdata_addr_prop_new(apc_named); 409 aprop_named = rdata_aprop_named_new(); 410 item->u.address = address; 411 address->u.prop_a = addr_prop; 412 addr_prop->u.named = aprop_named; 413 414 deleg_p = rdata_deleg_new(); 415 deleg_p->obj = sobj; 416 deleg_p->sym = sym; 417 addr_prop->u.named->prop_d = deleg_p; 418 419 *res = item; 420 } 370 /* Find member variable in object. */ 371 member_var = intmap_get(&aobj->fields, nameref->name->sid); 372 assert(member_var != NULL); 373 374 /* Return address of the variable. */ 375 item = rdata_item_new(ic_address); 376 address = rdata_address_new(ac_var); 377 addr_var = rdata_addr_var_new(); 378 379 item->u.address = address; 380 address->u.var_a = addr_var; 381 addr_var->vref = member_var; 382 383 *res = item; 384 break; 385 case sc_prop: 386 /* XXX TODO */ 387 printf("Unimplemented: Property name reference.\n"); 388 abort(); 421 389 break; 422 390 } … … 643 611 rdata_value_t *v1, *v2; 644 612 645 rarg1_i = NULL;646 rarg2_i = NULL;647 rarg1_vi = NULL;648 rarg2_vi = NULL;649 650 613 #ifdef DEBUG_RUN_TRACE 651 614 printf("Run binary operation.\n"); … … 653 616 run_expr(run, binop->arg1, &rarg1_i); 654 617 if (run_is_bo(run)) { 655 *res = run_recovery_item(run); 656 goto cleanup; 657 } 658 659 #ifdef DEBUG_RUN_TRACE 660 printf("Check binop argument result.\n"); 661 #endif 662 run_cvt_value_item(run, rarg1_i, &rarg1_vi); 663 if (run_is_bo(run)) { 664 *res = run_recovery_item(run); 665 goto cleanup; 618 *res = NULL; 619 return; 666 620 } 667 621 668 622 run_expr(run, binop->arg2, &rarg2_i); 669 623 if (run_is_bo(run)) { 670 *res = run_recovery_item(run); 671 goto cleanup; 672 } 673 674 #ifdef DEBUG_RUN_TRACE 675 printf("Check binop argument result.\n"); 676 #endif 624 *res = NULL; 625 return; 626 } 627 628 #ifdef DEBUG_RUN_TRACE 629 printf("Check binop argument results.\n"); 630 #endif 631 632 run_cvt_value_item(run, rarg1_i, &rarg1_vi); 677 633 run_cvt_value_item(run, rarg2_i, &rarg2_vi); 678 if (run_is_bo(run)) {679 *res = run_recovery_item(run);680 goto cleanup;681 }682 634 683 635 v1 = rarg1_vi->u.value; … … 716 668 assert(b_false); 717 669 } 718 719 cleanup:720 if (rarg1_i != NULL)721 rdata_item_destroy(rarg1_i);722 if (rarg2_i != NULL)723 rdata_item_destroy(rarg2_i);724 if (rarg1_vi != NULL)725 rdata_item_destroy(rarg1_vi);726 if (rarg2_vi != NULL)727 rdata_item_destroy(rarg2_vi);728 670 } 729 671 … … 1112 1054 rdata_bool_t *bool_v; 1113 1055 1114 stree_embr_t *e1, *e2;1056 rdata_var_t *ref1, *ref2; 1115 1057 1116 1058 (void) run; … … 1125 1067 var->u.bool_v = bool_v; 1126 1068 1127 e1 = v1->var->u.enum_v->value;1128 e2 = v2->var->u.enum_v->value;1069 ref1 = v1->var->u.ref_v->vref; 1070 ref2 = v2->var->u.ref_v->vref; 1129 1071 1130 1072 switch (binop->bc) { 1131 1073 case bo_equal: 1132 bool_v->value = ( e1 == e2);1074 bool_v->value = (ref1 == ref2); 1133 1075 break; 1134 1076 case bo_notequal: 1135 bool_v->value = ( e1 != e2);1077 bool_v->value = (ref1 != ref2); 1136 1078 break; 1137 1079 default: … … 1158 1100 printf("Run unary operation.\n"); 1159 1101 #endif 1160 rarg_i = NULL;1161 rarg_vi = NULL;1162 1163 1102 run_expr(run, unop->arg, &rarg_i); 1164 1103 if (run_is_bo(run)) { 1165 *res = run_recovery_item(run);1166 goto cleanup;1104 *res = NULL; 1105 return; 1167 1106 } 1168 1107 … … 1171 1110 #endif 1172 1111 run_cvt_value_item(run, rarg_i, &rarg_vi); 1173 if (run_is_bo(run)) {1174 *res = run_recovery_item(run);1175 goto cleanup;1176 }1177 1112 1178 1113 val = rarg_vi->u.value; … … 1189 1124 "type %d.\n", val->var->vc); 1190 1125 run_raise_error(run); 1191 *res = run_recovery_item(run); 1192 break; 1193 } 1194 cleanup: 1195 if (rarg_i != NULL) 1196 rdata_item_destroy(rarg_i); 1197 if (rarg_vi != NULL) 1198 rdata_item_destroy(rarg_vi); 1126 *res = NULL; 1127 break; 1128 } 1199 1129 } 1200 1130 … … 1278 1208 *res = item; 1279 1209 } 1280 1281 /** Run equality comparison of two values1282 *1283 * This should be equivalent to equality ('==') binary operation.1284 * XXX Duplicating code of run_binop_xxx().1285 *1286 * @param run Runner object1287 * @param v1 Value of first argument1288 * @param v2 Value of second argument1289 * @param res Place to store result (plain boolean value)1290 */1291 void run_equal(run_t *run, rdata_value_t *v1, rdata_value_t *v2, bool_t *res)1292 {1293 bool_t b1, b2;1294 bigint_t *c1, *c2;1295 bigint_t *i1, *i2;1296 bigint_t diff;1297 const char *s1, *s2;1298 rdata_var_t *ref1, *ref2;1299 stree_embr_t *e1, *e2;1300 1301 (void) run;1302 assert(v1->var->vc == v2->var->vc);1303 1304 switch (v1->var->vc) {1305 case vc_bool:1306 b1 = v1->var->u.bool_v->value;1307 b2 = v2->var->u.bool_v->value;1308 1309 *res = (b1 == b2);1310 break;1311 case vc_char:1312 c1 = &v1->var->u.char_v->value;1313 c2 = &v2->var->u.char_v->value;1314 1315 bigint_sub(c1, c2, &diff);1316 *res = bigint_is_zero(&diff);1317 break;1318 case vc_int:1319 i1 = &v1->var->u.int_v->value;1320 i2 = &v2->var->u.int_v->value;1321 1322 bigint_sub(i1, i2, &diff);1323 *res = bigint_is_zero(&diff);1324 break;1325 case vc_string:1326 s1 = v1->var->u.string_v->value;1327 s2 = v2->var->u.string_v->value;1328 1329 *res = os_str_cmp(s1, s2) == 0;1330 break;1331 case vc_ref:1332 ref1 = v1->var->u.ref_v->vref;1333 ref2 = v2->var->u.ref_v->vref;1334 1335 *res = (ref1 == ref2);1336 break;1337 case vc_enum:1338 e1 = v1->var->u.enum_v->value;1339 e2 = v2->var->u.enum_v->value;1340 1341 *res = (e1 == e2);1342 break;1343 1344 case vc_deleg:1345 case vc_array:1346 case vc_object:1347 case vc_resource:1348 case vc_symbol:1349 assert(b_false);1350 }1351 }1352 1353 1210 1354 1211 /** Evaluate @c new operation. … … 1440 1297 run_expr(run, expr, &rexpr); 1441 1298 if (run_is_bo(run)) { 1442 *res = run_recovery_item(run);1299 *res = NULL; 1443 1300 return; 1444 1301 } 1445 1302 1446 1303 run_cvt_value_item(run, rexpr, &rexpr_vi); 1447 if (run_is_bo(run)) {1448 *res = run_recovery_item(run);1449 return;1450 }1451 1452 1304 assert(rexpr_vi->ic == ic_value); 1453 1305 rexpr_var = rexpr_vi->u.value->var; … … 1523 1375 run_call_args(run, &new_op->ctor_args, &arg_vals); 1524 1376 if (run_is_bo(run)) { 1525 *res = run_recovery_item(run);1377 *res = NULL; 1526 1378 return; 1527 1379 } … … 1535 1387 assert(obj_i->u.address->ac == ac_var); 1536 1388 run_object_ctor(run, obj_i->u.address->u.var_a->vref, &arg_vals); 1537 rdata_item_destroy(obj_i);1538 1539 /* Destroy argument values */1540 run_destroy_arg_vals(&arg_vals);1541 1389 } 1542 1390 … … 1556 1404 printf("Run access operation.\n"); 1557 1405 #endif 1558 rarg = NULL;1559 1560 1406 run_expr(run, access->arg, &rarg); 1561 1407 if (run_is_bo(run)) { 1562 *res = run_recovery_item(run);1563 goto cleanup;1408 *res = NULL; 1409 return; 1564 1410 } 1565 1411 … … 1570 1416 1571 1417 run_access_item(run, access, rarg, res); 1572 cleanup:1573 if (rarg != NULL)1574 rdata_item_destroy(rarg);1575 1418 } 1576 1419 … … 1641 1484 /* Try again. */ 1642 1485 run_access_item(run, access, darg, res); 1643 1644 /* Destroy temporary */1645 rdata_item_destroy(darg);1646 1486 } 1647 1487 … … 1950 1790 #endif 1951 1791 run_cvt_value_item(run, arg, &arg_vi); 1952 if (run_is_bo(run)) {1953 *res = run_recovery_item(run);1954 return;1955 }1956 1957 1792 arg_val = arg_vi->u.value; 1958 1793 assert(arg_val->var->vc == vc_symbol); … … 1965 1800 embr = stree_enum_find_mbr(symbol_v->sym->u.enum_d, 1966 1801 access->member_name); 1967 1968 rdata_item_destroy(arg_vi);1969 1802 1970 1803 /* Member existence should be ensured by static type checking. */ … … 2008 1841 printf("Run call operation.\n"); 2009 1842 #endif 2010 rdeleg = NULL;2011 rdeleg_vi = NULL;2012 2013 1843 run_expr(run, call->fun, &rdeleg); 2014 1844 if (run_is_bo(run)) { 1845 *res = NULL; 1846 return; 1847 } 1848 1849 if (run->thread_ar->bo_mode != bm_none) { 2015 1850 *res = run_recovery_item(run); 2016 goto cleanup;1851 return; 2017 1852 } 2018 1853 2019 1854 run_cvt_value_item(run, rdeleg, &rdeleg_vi); 2020 if (run_is_bo(run)) {2021 *res = run_recovery_item(run);2022 goto cleanup;2023 }2024 2025 1855 assert(rdeleg_vi->ic == ic_value); 2026 1856 … … 2047 1877 run_call_args(run, &call->args, &arg_vals); 2048 1878 if (run_is_bo(run)) { 2049 *res = run_recovery_item(run);2050 goto cleanup;1879 *res = NULL; 1880 return; 2051 1881 } 2052 1882 … … 2059 1889 /* Fill in argument values. */ 2060 1890 run_proc_ar_set_args(run, proc_ar, &arg_vals); 2061 2062 /* Destroy arg_vals, they are no longer needed. */2063 run_destroy_arg_vals(&arg_vals);2064 1891 2065 1892 /* Run the function. */ … … 2073 1900 } 2074 1901 2075 /* Destroy procedure activation record. */2076 run_proc_ar_destroy(run, proc_ar);2077 2078 cleanup:2079 if (rdeleg != NULL)2080 rdata_item_destroy(rdeleg);2081 if (rdeleg_vi != NULL)2082 rdata_item_destroy(rdeleg_vi);2083 2084 1902 #ifdef DEBUG_RUN_TRACE 2085 1903 printf("Returned from function call.\n"); … … 2110 1928 run_expr(run, arg, &rarg_i); 2111 1929 if (run_is_bo(run)) 2112 goto error;1930 return; 2113 1931 2114 1932 run_cvt_value_item(run, rarg_i, &rarg_vi); 2115 rdata_item_destroy(rarg_i);2116 if (run_is_bo(run))2117 goto error;2118 1933 2119 1934 list_append(arg_vals, rarg_vi); 2120 1935 arg_n = list_next(args, arg_n); 2121 1936 } 2122 return;2123 2124 error:2125 /*2126 * An exception or error occured while evaluating one of the2127 * arguments. Destroy already obtained argument values and2128 * dismantle the list.2129 */2130 run_destroy_arg_vals(arg_vals);2131 }2132 2133 /** Destroy list of evaluated arguments.2134 *2135 * Provided a list of evaluated arguments, destroy them, removing them2136 * from the list and fini the list itself.2137 *2138 * @param arg_vals List of evaluated arguments (value items,2139 * rdata_item_t).2140 */2141 static void run_destroy_arg_vals(list_t *arg_vals)2142 {2143 list_node_t *val_n;2144 rdata_item_t *val_i;2145 2146 /*2147 * An exception or error occured while evaluating one of the2148 * arguments. Destroy already obtained argument values and2149 * dismantle the list.2150 */2151 while (!list_is_empty(arg_vals)) {2152 val_n = list_first(arg_vals);2153 val_i = list_node_data(val_n, rdata_item_t *);2154 2155 rdata_item_destroy(val_i);2156 list_remove(arg_vals, val_n);2157 }2158 list_fini(arg_vals);2159 1937 } 2160 1938 … … 2176 1954 var_class_t vc; 2177 1955 list_t arg_vals; 2178 list_node_t *val_n;2179 rdata_item_t *val_i;2180 1956 2181 1957 #ifdef DEBUG_RUN_TRACE … … 2184 1960 run_expr(run, index->base, &rbase); 2185 1961 if (run_is_bo(run)) { 2186 *res = run_recovery_item(run);1962 *res = NULL; 2187 1963 return; 2188 1964 } … … 2193 1969 if (vc == vc_ref) { 2194 1970 run_dereference(run, rbase, index->base->cspan, &base_i); 2195 rdata_item_destroy(rbase);2196 1971 if (run_is_bo(run)) { 2197 *res = run_recovery_item(run);1972 *res = NULL; 2198 1973 return; 2199 1974 } … … 2212 1987 run_expr(run, arg, &rarg_i); 2213 1988 if (run_is_bo(run)) { 2214 *res = run_recovery_item(run);2215 goto cleanup;1989 *res = NULL; 1990 return; 2216 1991 } 2217 1992 2218 1993 run_cvt_value_item(run, rarg_i, &rarg_vi); 2219 rdata_item_destroy(rarg_i);2220 if (run_is_bo(run)) {2221 *res = run_recovery_item(run);2222 goto cleanup;2223 }2224 1994 2225 1995 list_append(&arg_vals, rarg_vi); … … 2242 2012 exit(1); 2243 2013 } 2244 2245 /* Destroy the indexing base temporary */2246 rdata_item_destroy(base_i);2247 cleanup:2248 /*2249 * An exception or error occured while evaluating one of the2250 * arguments. Destroy already obtained argument values and2251 * dismantle the list.2252 */2253 while (!list_is_empty(&arg_vals)) {2254 val_n = list_first(&arg_vals);2255 val_i = list_node_data(val_n, rdata_item_t *);2256 2257 rdata_item_destroy(val_i);2258 list_remove(&arg_vals, val_n);2259 }2260 2261 list_fini(&arg_vals);2262 2014 } 2263 2015 … … 2384 2136 2385 2137 list_node_t *node; 2386 rdata_item_t *arg , *arg_copy;2138 rdata_item_t *arg; 2387 2139 2388 2140 #ifdef DEBUG_RUN_TRACE … … 2434 2186 while (node != NULL) { 2435 2187 arg = list_node_data(node, rdata_item_t *); 2436 2437 /* 2438 * Clone argument so that original can 2439 * be freed. 2440 */ 2441 assert(arg->ic == ic_value); 2442 arg_copy = rdata_item_new(ic_value); 2443 rdata_value_copy(arg->u.value, &arg_copy->u.value); 2444 2445 list_append(&aprop_indexed->args, arg_copy); 2188 list_append(&aprop_indexed->args, arg); 2446 2189 node = list_next(args, node); 2447 2190 } … … 2482 2225 2483 2226 run_cvt_value_item(run, base, &base_vi); 2484 if (run_is_bo(run)) {2485 *res = run_recovery_item(run);2486 return;2487 }2488 2489 2227 assert(base_vi->u.value->var->vc == vc_string); 2490 2228 string = base_vi->u.value->var->u.string_v; … … 2539 2277 index->expr->cspan); 2540 2278 *res = run_recovery_item(run); 2541 goto cleanup;2279 return; 2542 2280 } 2543 2281 … … 2553 2291 2554 2292 *res = ritem; 2555 cleanup:2556 rdata_item_destroy(base_vi);2557 2293 } 2558 2294 … … 2574 2310 printf("Run assign operation.\n"); 2575 2311 #endif 2576 rdest_i = NULL;2577 rsrc_i = NULL;2578 rsrc_vi = NULL;2579 2580 2312 run_expr(run, assign->dest, &rdest_i); 2581 2313 if (run_is_bo(run)) { 2582 *res = run_recovery_item(run);2583 goto cleanup;2314 *res = NULL; 2315 return; 2584 2316 } 2585 2317 2586 2318 run_expr(run, assign->src, &rsrc_i); 2587 2319 if (run_is_bo(run)) { 2588 *res = run_recovery_item(run);2589 goto cleanup;2320 *res = NULL; 2321 return; 2590 2322 } 2591 2323 2592 2324 run_cvt_value_item(run, rsrc_i, &rsrc_vi); 2593 if (run_is_bo(run)) {2594 *res = run_recovery_item(run);2595 goto cleanup;2596 }2597 2598 2325 assert(rsrc_vi->ic == ic_value); 2599 2326 … … 2607 2334 2608 2335 *res = NULL; 2609 cleanup:2610 if (rdest_i != NULL)2611 rdata_item_destroy(rdest_i);2612 if (rsrc_i != NULL)2613 rdata_item_destroy(rsrc_i);2614 if (rsrc_vi != NULL)2615 rdata_item_destroy(rsrc_vi);2616 2336 } 2617 2337 … … 2639 2359 run_expr(run, as_op->arg, &rarg_i); 2640 2360 if (run_is_bo(run)) { 2641 *res = run_recovery_item(run);2361 *res = NULL; 2642 2362 return; 2643 2363 } … … 2649 2369 assert(run_item_get_vc(run, rarg_i) == vc_ref); 2650 2370 run_cvt_value_item(run, rarg_i, &rarg_vi); 2651 rdata_item_destroy(rarg_i);2652 2653 if (run_is_bo(run)) {2654 *res = run_recovery_item(run);2655 return;2656 }2657 2658 2371 assert(rarg_vi->ic == ic_value); 2659 2372 … … 2692 2405 } 2693 2406 2694 /* The dereferenced item is not used anymore. */2695 rdata_item_destroy(rarg_di);2696 2697 2407 *res = rarg_vi; 2698 2408 } … … 2725 2435 run_expr(run, box->arg, &rarg_i); 2726 2436 if (run_is_bo(run)) { 2727 *res = run_recovery_item(run);2437 *res = NULL; 2728 2438 return; 2729 2439 } 2730 2440 2731 2441 run_cvt_value_item(run, rarg_i, &rarg_vi); 2732 rdata_item_destroy(rarg_i);2733 if (run_is_bo(run)) {2734 *res = run_recovery_item(run);2735 return;2736 }2737 2738 2442 assert(rarg_vi->ic == ic_value); 2739 2443 … … 2778 2482 2779 2483 rdata_var_write(mbr_var, rarg_vi->u.value); 2780 rdata_item_destroy(rarg_vi);2781 2484 } 2782 2485 … … 2954 2657 assert(res == NULL); 2955 2658 2956 /* Destroy procedure activation record. */2957 run_proc_ar_destroy(run, proc_ar);2958 2959 2659 #ifdef DEBUG_RUN_TRACE 2960 2660 printf("Returned from constructor..\n"); … … 2975 2675 rdata_item_t *vitem; 2976 2676 rdata_var_t *var; 2977 bool_t res;2978 2677 2979 2678 (void) run; 2980 2679 run_cvt_value_item(run, item, &vitem); 2981 if (run_is_bo(run))2982 return b_true;2983 2680 2984 2681 assert(vitem->ic == ic_value); … … 2986 2683 2987 2684 assert(var->vc == vc_bool); 2988 res = var->u.bool_v->value; 2989 2990 /* Free value item */ 2991 rdata_item_destroy(vitem); 2992 return res; 2993 } 2685 return var->u.bool_v->value; 2686 }
Note:
See TracChangeset
for help on using the changeset viewer.