Changeset d0febca in mainline


Ignore:
Timestamp:
2010-03-13T12:04:37Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7715994
Parents:
94d484a
Message:

Update SBI to rev. 100.

Location:
uspace/app/sbi/src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/builtin.c

    r94d484a rd0febca  
    2727 */
    2828
    29 /** @file Builtin functions. */
     29/** @file Builtin procedures. */
    3030
    3131#include <stdio.h>
     
    4242#include "builtin.h"
    4343
    44 static stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, char *name);
    45 static void builtin_fun_add_arg(stree_symbol_t *fun_sym, char *name);
    46 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, char *name);
     44static stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name);
     45static void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name);
     46static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name);
    4747
    4848static void builtin_write_line(run_t *run);
     
    5454/** Declare builtin symbols in the program.
    5555 *
    56  * Declares symbols that will be hooked to builtin interpreter functions.
     56 * Declares symbols that will be hooked to builtin interpreter procedures.
    5757 */
    5858void builtin_declare(stree_program_t *program)
     
    8080        list_append(&program->module->members, modm);
    8181
    82         /* Declare builtin functions. */
     82        /* Declare builtin procedures. */
    8383
    8484        bi_write_line = builtin_declare_fun(csi, "WriteLine");
     
    8989}
    9090
    91 void builtin_run_fun(run_t *run, stree_symbol_t *fun_sym)
     91void builtin_run_proc(run_t *run, stree_symbol_t *proc_sym)
    9292{
    9393#ifdef DEBUG_RUN_TRACE
    94         printf("Run builtin function.\n");
     94        printf("Run builtin procedure.\n");
    9595#endif
    96         if (fun_sym == bi_write_line) {
     96        if (proc_sym == bi_write_line) {
    9797                builtin_write_line(run);
    98         } else if (fun_sym == bi_exec) {
     98        } else if (proc_sym == bi_exec) {
    9999                builtin_exec(run);
    100100        } else {
     
    104104
    105105/** Declare a builtin function in @a csi. */
    106 static stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, char *name)
     106static stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name)
    107107{
    108108        stree_ident_t *ident;
     
    133133
    134134/** Add one formal parameter to function. */
    135 static void builtin_fun_add_arg(stree_symbol_t *fun_sym, char *name)
    136 {
    137         stree_fun_arg_t *fun_arg;
     135static void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name)
     136{
     137        stree_proc_arg_t *proc_arg;
    138138        stree_fun_t *fun;
    139139
     
    141141        assert(fun != NULL);
    142142
    143         fun_arg = stree_fun_arg_new();
    144         fun_arg->name = stree_ident_new();
    145         fun_arg->name->sid = strtab_get_sid(name);
    146         fun_arg->type = NULL; /* XXX */
    147 
    148         list_append(&fun->args, fun_arg);
     143        proc_arg = stree_proc_arg_new();
     144        proc_arg->name = stree_ident_new();
     145        proc_arg->name->sid = strtab_get_sid(name);
     146        proc_arg->type = NULL; /* XXX */
     147
     148        list_append(&fun->args, proc_arg);
    149149}
    150150
    151151/** Add variadic formal parameter to function. */
    152 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, char *name)
    153 {
    154         stree_fun_arg_t *fun_arg;
     152static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name)
     153{
     154        stree_proc_arg_t *proc_arg;
    155155        stree_fun_t *fun;
    156156
     
    158158        assert(fun != NULL);
    159159
    160         fun_arg = stree_fun_arg_new();
    161         fun_arg->name = stree_ident_new();
    162         fun_arg->name->sid = strtab_get_sid(name);
    163         fun_arg->type = NULL; /* XXX */
    164 
    165         fun->varg = fun_arg;
     160        proc_arg = stree_proc_arg_new();
     161        proc_arg->name = stree_ident_new();
     162        proc_arg->name->sid = strtab_get_sid(name);
     163        proc_arg->type = NULL; /* XXX */
     164
     165        fun->varg = proc_arg;
    166166}
    167167
  • uspace/app/sbi/src/builtin.h

    r94d484a rd0febca  
    3333
    3434void builtin_declare(stree_program_t *program);
    35 void builtin_run_fun(run_t *run, stree_symbol_t *fun_sym);
     35void builtin_run_proc(run_t *run, stree_symbol_t *proc_sym);
    3636
    3737#endif
  • uspace/app/sbi/src/os/helenos.c

    r94d484a rd0febca  
    7575}
    7676
     77/** Get character from string at the given index. */
     78int os_str_get_char(const char *str, int index, int *out_char)
     79{
     80        size_t offset;
     81        int i;
     82        wchar_t c;
     83
     84        if (index < 0)
     85                return EINVAL;
     86
     87        offset = 0;
     88        for (i = 0; i <= index; ++i) {
     89                c = str_decode(str, &offset, STR_NO_LIMIT);
     90                if (c == '\0')
     91                        return EINVAL;
     92                if (c == U_SPECIAL)
     93                        return EIO;
     94        }
     95
     96        *out_char = (int) c;
     97        return EOK;
     98}
     99
    77100/** Simple command execution. */
    78101int os_exec(char *const cmd[])
  • uspace/app/sbi/src/os/os.h

    r94d484a rd0febca  
    3333int os_str_cmp(const char *a, const char *b);
    3434char *os_str_dup(const char *str);
     35int os_str_get_char(const char *str, int index, int *out_char);
    3536int os_exec(char *const cmd[]);
    3637
  • uspace/app/sbi/src/os/posix.c

    r94d484a rd0febca  
    7979}
    8080
     81/** Get character from string at the given index. */
     82int os_str_get_char(const char *str, int index, int *out_char)
     83{
     84        size_t len;
     85
     86        len = strlen(str);
     87        if (index < 0 || (size_t) index >= len)
     88                return EINVAL;
     89
     90        *out_char = str[index];
     91        return EOK;
     92}
     93
    8194/** Simple command execution. */
    8295int os_exec(char *const cmd[])
  • uspace/app/sbi/src/parse.c

    r94d484a rd0febca  
    5555static stree_prop_t *parse_prop(parse_t *parse);
    5656
    57 static stree_fun_arg_t *parse_fun_arg(parse_t *parse);
     57static stree_proc_arg_t *parse_proc_arg(parse_t *parse);
    5858static stree_arg_attr_t *parse_arg_attr(parse_t *parse);
    5959
     
    227227{
    228228        stree_fun_t *fun;
    229         stree_fun_arg_t *arg;
     229        stree_proc_arg_t *arg;
    230230
    231231        fun = stree_fun_new();
     
    241241                /* Parse formal parameters. */
    242242                while (b_true) {
    243                         arg = parse_fun_arg(parse);
     243                        arg = parse_proc_arg(parse);
    244244                        if (stree_arg_has_attr(arg, aac_packed)) {
    245245                                fun->varg = arg;
     
    292292{
    293293        stree_prop_t *prop;
     294        stree_ident_t *ident;
     295        stree_proc_arg_t *arg;
    294296
    295297        prop = stree_prop_new();
     298        list_init(&prop->args);
    296299
    297300        lmatch(parse, lc_prop);
    298         prop->name = parse_ident(parse);
     301
     302        if (lcur_lc(parse) == lc_self) {
     303                /* Indexed property set */
     304
     305                /* Use some name that is impossible as identifier. */
     306                ident = stree_ident_new();
     307                ident->sid = strtab_get_sid(INDEXER_IDENT);
     308                prop->name = ident;
     309
     310                lskip(parse);
     311                lmatch(parse, lc_lsbr);
     312
     313                /* Parse formal parameters. */
     314                while (b_true) {
     315                        arg = parse_proc_arg(parse);
     316                        if (stree_arg_has_attr(arg, aac_packed)) {
     317                                prop->varg = arg;
     318                                break;
     319                        } else {
     320                                list_append(&prop->args, arg);
     321                        }
     322
     323                        if (lcur_lc(parse) == lc_rsbr)
     324                                break;
     325
     326                        lmatch(parse, lc_scolon);
     327                }
     328
     329                lmatch(parse, lc_rsbr);
     330        } else {
     331                /* Named property */
     332                prop->name = parse_ident(parse);
     333        }
     334
    299335        lmatch(parse, lc_colon);
    300336        prop->type = parse_texpr(parse);
    301337        lmatch(parse, lc_is);
     338
     339        while (lcur_lc(parse) != lc_end) {
     340                switch (lcur_lc(parse)) {
     341                case lc_get:
     342                        lskip(parse);
     343                        lmatch(parse, lc_is);
     344                        if (prop->getter_body != NULL) {
     345                                printf("Error: Duplicate getter.\n");
     346                                exit(1);
     347                        }
     348                        prop->getter_body = parse_block(parse);
     349                        lmatch(parse, lc_end);
     350                        break;
     351                case lc_set:
     352                        lskip(parse);
     353                        prop->setter_arg_name = parse_ident(parse);
     354                        lmatch(parse, lc_is);
     355                        if (prop->setter_body != NULL) {
     356                                printf("Error: Duplicate setter.\n");
     357                                exit(1);
     358                        }
     359                        prop->setter_body = parse_block(parse);
     360                        lmatch(parse, lc_end);
     361                        break;
     362                default:
     363                        lunexpected_error(parse);
     364                }
     365        }
     366
    302367        lmatch(parse, lc_end);
    303368
     
    306371
    307372/** Parse formal function argument. */
    308 static stree_fun_arg_t *parse_fun_arg(parse_t *parse)
    309 {
    310         stree_fun_arg_t *arg;
     373static stree_proc_arg_t *parse_proc_arg(parse_t *parse)
     374{
     375        stree_proc_arg_t *arg;
    311376        stree_arg_attr_t *attr;
    312377
    313         arg = stree_fun_arg_new();
     378        arg = stree_proc_arg_new();
    314379        arg->name = parse_ident(parse);
    315380        lmatch(parse, lc_colon);
  • uspace/app/sbi/src/rdata.c

    r94d484a rd0febca  
    6464}
    6565
    66 rdata_address_t *rdata_address_new(void)
     66rdata_addr_var_t *rdata_addr_var_new(void)
     67{
     68        rdata_addr_var_t *addr_var;
     69
     70        addr_var = calloc(1, sizeof(rdata_addr_var_t));
     71        if (addr_var == NULL) {
     72                printf("Memory allocation failed.\n");
     73                exit(1);
     74        }
     75
     76        return addr_var;
     77}
     78
     79rdata_aprop_named_t *rdata_aprop_named_new(void)
     80{
     81        rdata_aprop_named_t *aprop_named;
     82
     83        aprop_named = calloc(1, sizeof(rdata_aprop_named_t));
     84        if (aprop_named == NULL) {
     85                printf("Memory allocation failed.\n");
     86                exit(1);
     87        }
     88
     89        return aprop_named;
     90}
     91
     92rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
     93{
     94        rdata_aprop_indexed_t *aprop_indexed;
     95
     96        aprop_indexed = calloc(1, sizeof(rdata_aprop_indexed_t));
     97        if (aprop_indexed == NULL) {
     98                printf("Memory allocation failed.\n");
     99                exit(1);
     100        }
     101
     102        return aprop_indexed;
     103}
     104
     105rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
     106{
     107        rdata_addr_prop_t *addr_prop;
     108
     109        addr_prop = calloc(1, sizeof(rdata_addr_prop_t));
     110        if (addr_prop == NULL) {
     111                printf("Memory allocation failed.\n");
     112                exit(1);
     113        }
     114
     115        addr_prop->apc = apc;
     116        return addr_prop;
     117}
     118
     119rdata_address_t *rdata_address_new(address_class_t ac)
    67120{
    68121        rdata_address_t *address;
     
    74127        }
    75128
     129        address->ac = ac;
    76130        return address;
    77131}
     
    349403}
    350404
    351 /** Convert item to value item.
    352  *
    353  * If @a item is a value, we just return a copy. If @a item is an address,
    354  * we read from the address.
     405/** Read data from a variable.
     406 *
     407 * Return value stored in variable @a var.
    355408 */
    356 void rdata_cvt_value_item(rdata_item_t *item, rdata_item_t **ritem)
    357 {
    358         rdata_value_t *value;
    359 
    360         /*
    361          * This can happen when trying to use output of a function which
    362          * does not return a value.
    363          */
    364         if (item == NULL) {
    365                 printf("Error: Sub-expression has no value.\n");
    366                 exit(1);
    367         }
    368 
    369         /* Address item. Perform read operation. */
    370         if (item->ic == ic_address) {
    371                 rdata_address_read(item->u.address, ritem);
    372                 return;
    373         }
    374 
    375         /* It already is a value, we can share the @c var. */
    376         value = rdata_value_new();
    377         value->var = item->u.value->var;
    378         *ritem = rdata_item_new(ic_value);
    379         (*ritem)->u.value = value;
    380 }
    381 
    382 /** Return reference to a variable.
    383  *
    384  * Constructs a reference (value item) pointing to @a var.
    385  */
    386 void rdata_reference(rdata_var_t *var, rdata_item_t **res)
    387 {
    388         rdata_ref_t *ref;
    389         rdata_var_t *ref_var;
    390         rdata_value_t *ref_value;
    391         rdata_item_t *ref_item;
    392 
    393         /* Create reference to the variable. */
    394         ref = rdata_ref_new();
    395         ref_var = rdata_var_new(vc_ref);
    396         ref->vref = var;
    397         ref_var->u.ref_v = ref;
    398 
    399         /* Construct value of the reference to return. */
    400         ref_item = rdata_item_new(ic_value);
    401         ref_value = rdata_value_new();
    402         ref_item->u.value = ref_value;
    403         ref_value->var = ref_var;
    404 
    405         *res = ref_item;
    406 }
    407 
    408 /** Return address of reference target.
    409  *
    410  * Takes a reference (address or value) and returns the address (item) of
    411  * the target of the reference.
    412  */
    413 void rdata_dereference(rdata_item_t *ref, rdata_item_t **ritem)
    414 {
    415         rdata_item_t *ref_val;
    416         rdata_item_t *item;
    417         rdata_address_t *address;
    418 
    419 #ifdef DEBUG_RUN_TRACE
    420         printf("run_dereference()\n");
    421 #endif
    422         rdata_cvt_value_item(ref, &ref_val);
    423         assert(ref_val->u.value->var->vc == vc_ref);
    424 
    425         item = rdata_item_new(ic_address);
    426         address = rdata_address_new();
    427         item->u.address = address;
    428         address->vref = ref_val->u.value->var->u.ref_v->vref;
    429 
    430         if (address->vref == NULL) {
    431                 printf("Error: Accessing null reference.\n");
    432                 exit(1);
    433         }
    434 
    435 #ifdef DEBUG_RUN_TRACE
    436         printf("vref set to %p\n", address->vref);
    437 #endif
    438         *ritem = item;
    439 }
    440 
    441 /** Read data from an address.
    442  *
    443  * Return value stored in a variable at the specified address.
    444  */
    445 void rdata_address_read(rdata_address_t *address, rdata_item_t **ritem)
     409void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
    446410{
    447411        rdata_value_t *value;
    448412        rdata_var_t *rvar;
    449413
    450         /* Perform a shallow copy of @c var. */
    451         rdata_var_copy(address->vref, &rvar);
     414        /* Perform a shallow copy of @a var. */
     415        rdata_var_copy(var, &rvar);
    452416
    453417        value = rdata_value_new();
     
    455419        *ritem = rdata_item_new(ic_value);
    456420        (*ritem)->u.value = value;
    457 }
    458 
    459 /** Write data to an address.
    460  *
    461  * Store @a value to the variable at @a address.
    462  */
    463 void rdata_address_write(rdata_address_t *address, rdata_value_t *value)
    464 {
    465         rdata_var_write(address->vref, value);
    466421}
    467422
     
    492447}
    493448
     449/** Get item var-class.
     450 *
     451 * Get var-class of @a item, regardless whether it is a value or address.
     452 * (I.e. the var class of the value or variable at the given address).
     453 */
     454var_class_t rdata_item_get_vc(rdata_item_t *item)
     455{
     456        var_class_t vc;
     457
     458        switch (item->ic) {
     459        case ic_value:
     460                vc = item->u.value->var->vc;
     461                break;
     462        case ic_address:
     463                switch (item->u.address->ac) {
     464                case ac_var:
     465                        vc = item->u.address->u.var_a->vref->vc;
     466                        break;
     467                case ac_prop:
     468                        printf("Unimplemented: Get property address "
     469                            "varclass.\n");
     470                        exit(1);
     471                default:
     472                        assert(b_false);
     473                }
     474                break;
     475        default:
     476                assert(b_false);
     477        }
     478
     479        return vc;
     480}
     481
    494482/** Determine if CSI @a a is derived from CSI described by type item @a tb. */
    495483bool_t rdata_is_csi_derived_from_ti(stree_csi_t *a, rdata_titem_t *tb)
     
    530518static void rdata_address_print(rdata_address_t *address)
    531519{
    532         rdata_var_print(address->vref);
     520        switch (address->ac) {
     521        case ac_var:
     522                rdata_var_print(address->u.var_a->vref);
     523                break;
     524        case ac_prop:
     525                printf("Warning: Unimplemented: Print property address.\n");
     526                break;
     527        }
    533528}
    534529
  • uspace/app/sbi/src/rdata.h

    r94d484a rd0febca  
    3333
    3434rdata_item_t *rdata_item_new(item_class_t ic);
    35 rdata_address_t *rdata_address_new(void);
     35rdata_addr_var_t *rdata_addr_var_new(void);
     36rdata_aprop_named_t *rdata_aprop_named_new(void);
     37rdata_aprop_indexed_t *rdata_aprop_indexed_new(void);
     38rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc);
     39rdata_address_t *rdata_address_new(address_class_t ac);
    3640rdata_value_t *rdata_value_new(void);
     41
    3742rdata_var_t *rdata_var_new(var_class_t vc);
    3843rdata_ref_t *rdata_ref_new(void);
     
    5156void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest);
    5257
    53 void rdata_cvt_value_item(rdata_item_t *item, rdata_item_t **ritem);
    54 void rdata_reference(rdata_var_t *var, rdata_item_t **res);
    55 void rdata_dereference(rdata_item_t *ref, rdata_item_t **ritem);
    56 void rdata_address_read(rdata_address_t *address, rdata_item_t **ritem);
    57 void rdata_address_write(rdata_address_t *address, rdata_value_t *value);
     58void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem);
    5859void rdata_var_write(rdata_var_t *var, rdata_value_t *value);
    5960
     61var_class_t rdata_item_get_vc(rdata_item_t *item);
    6062bool_t rdata_is_csi_derived_from_ti(stree_csi_t *a, rdata_titem_t *tb);
    6163
  • uspace/app/sbi/src/rdata_t.h

    r94d484a rd0febca  
    131131} rdata_var_t;
    132132
    133 /** Address item. */
    134 typedef struct rdata_address {
     133/** Address class */
     134typedef enum {
     135        /** Variable address */
     136        ac_var,
     137
     138        /** Property address */
     139        ac_prop
     140} address_class_t;
     141
     142/** Variable address */
     143typedef struct {
    135144        /** Targeted variable */
    136145        rdata_var_t *vref;
     146} rdata_addr_var_t;
     147
     148/** Named property address */
     149typedef struct {
     150        /** Delegate to the property */
     151        rdata_deleg_t *prop_d;
     152} rdata_aprop_named_t;
     153
     154/** Indexed property address */
     155typedef struct {
     156        /** Delegate to the object (or CSI) which is being indexed. */
     157        rdata_deleg_t *object_d;
     158
     159        /** Arguments (indices) */
     160        list_t args; /* of rdata_item_t */
     161} rdata_aprop_indexed_t;
     162
     163typedef enum {
     164        /* Named property address */
     165        apc_named,
     166
     167        /* Indexed property address */
     168        apc_indexed
     169} aprop_class_t;
     170
     171/** Property address.
     172 *
     173 * When accessing part of a property that is non-scalar and mutable,
     174 * a read-modify-write (or get-modify-set) operation is necessary.
     175 * To accomodate this, the address item must hold a temporary copy of the
     176 * property value.
     177 */
     178typedef struct {
     179        aprop_class_t apc;
     180
     181        /** Temporary copy of property value or @c NULL when not used. */
     182        struct rdata_value *tvalue;
     183
     184        /**
     185         * Points to the specific var node within @c tvalue that is addressed
     186         * or @c NULL when @c tvalue is not used.
     187         */
     188        rdata_var_t *tpos;
     189
     190        union {
     191                rdata_aprop_named_t *named;
     192                rdata_aprop_indexed_t *indexed;
     193        } u;
     194} rdata_addr_prop_t;
     195
     196/** Address item */
     197typedef struct rdata_address {
     198        address_class_t ac;
     199
     200        union {
     201                rdata_addr_var_t *var_a;
     202                rdata_addr_prop_t *prop_a;
     203        } u;
    137204} rdata_address_t;
    138205
  • uspace/app/sbi/src/run.c

    r94d484a rd0febca  
    5858static bool_t run_exc_match(run_t *run, stree_except_t *except_c);
    5959
     60static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
     61    rdata_item_t **ritem);
     62static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
     63    rdata_value_t *value);
     64
    6065/** Initialize runner instance. */
    6166void run_init(run_t *run)
     
    7176        stree_ident_t *fake_ident;
    7277        list_t main_args;
    73         run_fun_ar_t *fun_ar;
     78        run_proc_ar_t *proc_ar;
    7479        rdata_item_t *res;
    7580
     
    7984        /* Initialize thread activation record. */
    8085        run->thread_ar = run_thread_ar_new();
    81         list_init(&run->thread_ar->fun_ar);
     86        list_init(&run->thread_ar->proc_ar);
    8287        run->thread_ar->bo_mode = bm_none;
    8388
     
    103108        /* Run function @c main. */
    104109        list_init(&main_args);
    105         run_fun_ar_create(run, NULL, main_fun, &fun_ar);
    106         run_fun_ar_set_args(run, fun_ar, &main_args);
    107         run_fun(run, fun_ar, &res);
     110        run_proc_ar_create(run, NULL, main_fun_sym, main_fun->body, &proc_ar);
     111        run_proc_ar_set_args(run, proc_ar, &main_args);
     112        run_proc(run, proc_ar, &res);
    108113
    109114        /* Check for unhandled exceptions. */
     
    115120}
    116121
    117 /** Run member function */
    118 void run_fun(run_t *run, run_fun_ar_t *fun_ar, rdata_item_t **res)
    119 {
    120         stree_symbol_t *fun_sym;
    121         stree_fun_t *fun;
     122/** Run procedure. */
     123void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res)
     124{
     125        stree_symbol_t *proc_sym;
    122126        list_node_t *node;
    123127
    124         fun_sym = fun_ar->fun_sym;
    125         fun = symbol_to_fun(fun_sym);
    126         assert(fun != NULL);
     128        proc_sym = proc_ar->proc_sym;
    127129
    128130#ifdef DEBUG_RUN_TRACE
    129131        printf("Start executing function '");
    130         symbol_print_fqn(run->program, fun_sym);
     132        symbol_print_fqn(run->program, proc_sym);
    131133        printf("'.\n");
    132134#endif
    133         /* Add function AR to the stack. */
    134         list_append(&run->thread_ar->fun_ar, fun_ar);
    135 
    136         /* Run main function block. */
    137         if (fun->body != NULL) {
    138                 run_block(run, fun->body);
     135        /* Add procedure AR to the stack. */
     136        list_append(&run->thread_ar->proc_ar, proc_ar);
     137
     138        /* Run main procedure block. */
     139        if (proc_ar->proc_block != NULL) {
     140                run_block(run, proc_ar->proc_block);
    139141        } else {
    140                 builtin_run_fun(run, fun_sym);
     142                builtin_run_proc(run, proc_sym);
    141143        }
    142144
     
    146148                printf("Error: Misplaced 'break' statement.\n");
    147149                exit(1);
    148         case bm_fun:
     150        case bm_proc:
    149151                run->thread_ar->bo_mode = bm_none;
    150152                break;
     
    154156
    155157#ifdef DEBUG_RUN_TRACE
    156         printf("Done executing function '");
    157         symbol_print_fqn(run->program, fun_sym);
     158        printf("Done executing procedure '");
     159        symbol_print_fqn(run->program, proc_sym);
    158160        printf("'.\n");
    159161
    160162        run_print_fun_bt(run);
    161163#endif
    162         /* Remove function activation record from the stack. */
    163         node = list_last(&run->thread_ar->fun_ar);
    164         assert(list_node_data(node, run_fun_ar_t *) == fun_ar);
    165         list_remove(&run->thread_ar->fun_ar, node);
    166 
    167         *res = fun_ar->retval;
     164        /* Remove procedure activation record from the stack. */
     165        node = list_last(&run->thread_ar->proc_ar);
     166        assert(list_node_data(node, run_proc_ar_t *) == proc_ar);
     167        list_remove(&run->thread_ar->proc_ar, node);
     168
     169        /* Procedure should not return an address. */
     170        assert(proc_ar->retval == NULL || proc_ar->retval->ic == ic_value);
     171        *res = proc_ar->retval;
    168172}
    169173
     
    171175static void run_block(run_t *run, stree_block_t *block)
    172176{
    173         run_fun_ar_t *fun_ar;
     177        run_proc_ar_t *proc_ar;
    174178        run_block_ar_t *block_ar;
    175179        list_node_t *node;
     
    185189
    186190        /* Add block activation record to the stack. */
    187         fun_ar = run_get_current_fun_ar(run);
    188         list_append(&fun_ar->block_ar, block_ar);
     191        proc_ar = run_get_current_proc_ar(run);
     192        list_append(&proc_ar->block_ar, block_ar);
    189193
    190194        node = list_first(&block->stats);
     
    204208
    205209        /* Remove block activation record from the stack. */
    206         node = list_last(&fun_ar->block_ar);
     210        node = list_last(&proc_ar->block_ar);
    207211        assert(list_node_data(node, run_block_ar_t *) == block_ar);
    208         list_remove(&fun_ar->block_ar, node);
     212        list_remove(&proc_ar->block_ar, node);
    209213}
    210214
     
    357361#endif
    358362        run_expr(run, raise_s->expr, &rexpr);
    359         rdata_cvt_value_item(rexpr, &rexpr_vi);
     363        run_cvt_value_item(run, rexpr, &rexpr_vi);
    360364
    361365        /* Store expression result in thread AR. */
     
    370374{
    371375        rdata_item_t *rexpr;
    372         run_fun_ar_t *fun_ar;
     376        rdata_item_t *rexpr_vi;
     377        run_proc_ar_t *proc_ar;
    373378
    374379#ifdef DEBUG_RUN_TRACE
     
    376381#endif
    377382        run_expr(run, return_s->expr, &rexpr);
     383        run_cvt_value_item(run, rexpr, &rexpr_vi);
    378384
    379385        /* Store expression result in function AR. */
    380         fun_ar = run_get_current_fun_ar(run);
    381         fun_ar->retval = rexpr;
    382 
    383         /* Force control to ascend and leave the function. */
     386        proc_ar = run_get_current_proc_ar(run);
     387        proc_ar->retval = rexpr_vi;
     388
     389        /* Force control to ascend and leave the procedure. */
    384390        if (run->thread_ar->bo_mode == bm_none)
    385                 run->thread_ar->bo_mode = bm_fun;
     391                run->thread_ar->bo_mode = bm_proc;
    386392}
    387393
     
    501507rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name)
    502508{
    503         run_fun_ar_t *fun_ar;
     509        run_proc_ar_t *proc_ar;
    504510        run_block_ar_t *block_ar;
    505511        rdata_var_t *var;
    506512        list_node_t *node;
    507513
    508         fun_ar = run_get_current_fun_ar(run);
    509         node = list_last(&fun_ar->block_ar);
     514        proc_ar = run_get_current_proc_ar(run);
     515        node = list_last(&proc_ar->block_ar);
    510516
    511517        /* Walk through all block activation records. */
     
    516522                        return var;
    517523
    518                 node = list_prev(&fun_ar->block_ar, node);
     524                node = list_prev(&proc_ar->block_ar, node);
    519525        }
    520526
     
    524530
    525531/** Get current function activation record. */
    526 run_fun_ar_t *run_get_current_fun_ar(run_t *run)
     532run_proc_ar_t *run_get_current_proc_ar(run_t *run)
    527533{
    528534        list_node_t *node;
    529535
    530         node = list_last(&run->thread_ar->fun_ar);
    531         return list_node_data(node, run_fun_ar_t *);
     536        node = list_last(&run->thread_ar->proc_ar);
     537        return list_node_data(node, run_proc_ar_t *);
    532538}
    533539
     
    535541run_block_ar_t *run_get_current_block_ar(run_t *run)
    536542{
    537         run_fun_ar_t *fun_ar;
     543        run_proc_ar_t *proc_ar;
    538544        list_node_t *node;
    539545
    540         fun_ar = run_get_current_fun_ar(run);
    541 
    542         node = list_last(&fun_ar->block_ar);
     546        proc_ar = run_get_current_proc_ar(run);
     547
     548        node = list_last(&proc_ar->block_ar);
    543549        return list_node_data(node, run_block_ar_t *);
    544550}
     
    547553stree_csi_t *run_get_current_csi(run_t *run)
    548554{
    549         run_fun_ar_t *fun_ar;
    550 
    551         fun_ar = run_get_current_fun_ar(run);
    552         return fun_ar->fun_sym->outer_csi;
     555        run_proc_ar_t *proc_ar;
     556
     557        proc_ar = run_get_current_proc_ar(run);
     558        return proc_ar->proc_sym->outer_csi;
    553559}
    554560
     
    600606
    601607/** Construct a function AR. */
    602 void run_fun_ar_create(run_t *run, rdata_var_t *obj, stree_fun_t *fun,
    603     run_fun_ar_t **rfun_ar)
    604 {
    605         run_fun_ar_t *fun_ar;
     608void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_symbol_t *proc_sym,
     609    stree_block_t *proc_block, run_proc_ar_t **rproc_ar)
     610{
     611        run_proc_ar_t *proc_ar;
     612        run_block_ar_t *block_ar;
    606613
    607614        (void) run;
    608615
    609616        /* Create function activation record. */
    610         fun_ar = run_fun_ar_new();
    611         fun_ar->obj = obj;
    612         fun_ar->fun_sym = fun_to_symbol(fun);
    613         list_init(&fun_ar->block_ar);
    614 
    615         fun_ar->retval = NULL;
    616 
    617         *rfun_ar = fun_ar;
    618 }
    619 
    620 /** Fill arguments in a function AR. */
    621 void run_fun_ar_set_args(run_t *run, run_fun_ar_t *fun_ar, list_t *args)
     617        proc_ar = run_proc_ar_new();
     618        proc_ar->obj = obj;
     619        proc_ar->proc_sym = proc_sym;
     620        proc_ar->proc_block = proc_block;
     621        list_init(&proc_ar->block_ar);
     622
     623        proc_ar->retval = NULL;
     624
     625        /* Create special block activation record to hold function arguments. */
     626        block_ar = run_block_ar_new();
     627        intmap_init(&block_ar->vars);
     628        list_append(&proc_ar->block_ar, block_ar);
     629
     630        *rproc_ar = proc_ar;
     631}
     632
     633/** Fill arguments in a procedure AR.
     634 *
     635 * When invoking a procedure this is used to store the argument values
     636 * in the activation record.
     637 */
     638void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals)
    622639{
    623640        stree_fun_t *fun;
     641        stree_prop_t *prop;
     642        list_t *args;
     643        stree_proc_arg_t *varg;
     644
    624645        run_block_ar_t *block_ar;
    625         list_node_t *rarg_n, *farg_n;
     646        list_node_t *block_ar_n;
     647        list_node_t *rarg_n, *parg_n;
    626648        list_node_t *cn;
    627649        rdata_item_t *rarg;
    628         stree_fun_arg_t *farg;
     650        stree_proc_arg_t *parg;
    629651        rdata_var_t *var;
    630652        rdata_var_t *ref_var;
     
    633655        int n_vargs, idx;
    634656
    635         /* AR should have been created with run_fun_ar_create(). */
    636         assert(fun_ar->fun_sym != NULL);
    637         assert(list_is_empty(&fun_ar->block_ar));
    638 
    639         fun = symbol_to_fun(fun_ar->fun_sym);
    640         assert(fun != NULL);
    641 
    642         /* Create special block activation record to hold function arguments. */
    643         block_ar = run_block_ar_new();
    644         intmap_init(&block_ar->vars);
    645         list_append(&fun_ar->block_ar, block_ar);
     657        /* AR should have been created with run_proc_ar_create(). */
     658        assert(proc_ar->proc_sym != NULL);
     659
     660        /*
     661         * The procedure being activated should be a member function or
     662         * property getter/setter.
     663         */
     664        switch (proc_ar->proc_sym->sc) {
     665        case sc_fun:
     666                fun = symbol_to_fun(proc_ar->proc_sym);
     667                args = &fun->args;
     668                varg = fun->varg;
     669                break;
     670        case sc_prop:
     671                prop = symbol_to_prop(proc_ar->proc_sym);
     672                args = &prop->args;
     673                varg = prop->varg;
     674                break;
     675        default:
     676                assert(b_false);
     677        }
     678
     679        /* Fetch first block activation record. */
     680        block_ar_n = list_first(&proc_ar->block_ar);
     681        assert(block_ar_n != NULL);
     682        block_ar = list_node_data(block_ar_n, run_block_ar_t *);
    646683
    647684        /* Declare local variables to hold argument values. */
    648         rarg_n = list_first(args);
    649         farg_n = list_first(&fun->args);
    650 
    651         while (farg_n != NULL) {
     685        rarg_n = list_first(arg_vals);
     686        parg_n = list_first(args);
     687
     688        while (parg_n != NULL) {
    652689                if (rarg_n == NULL) {
    653690                        printf("Error: Too few arguments to function '");
    654                         symbol_print_fqn(run->program, fun_ar->fun_sym);
     691                        symbol_print_fqn(run->program, proc_ar->proc_sym);
    655692                        printf("'.\n");
    656693                        exit(1);
     
    658695
    659696                rarg = list_node_data(rarg_n, rdata_item_t *);
    660                 farg = list_node_data(farg_n, stree_fun_arg_t *);
     697                parg = list_node_data(parg_n, stree_proc_arg_t *);
    661698
    662699                assert(rarg->ic == ic_value);
     
    666703
    667704                /* Declare variable using name of formal argument. */
    668                 intmap_set(&block_ar->vars, farg->name->sid, var);
    669 
    670                 rarg_n = list_next(args, rarg_n);
    671                 farg_n = list_next(&fun->args, farg_n);
    672         }
    673 
    674         if (fun->varg != NULL) {
     705                intmap_set(&block_ar->vars, parg->name->sid, var);
     706
     707                rarg_n = list_next(arg_vals, rarg_n);
     708                parg_n = list_next(args, parg_n);
     709        }
     710
     711        if (varg != NULL) {
    675712                /* Function is variadic. Count number of variadic arguments. */
    676713                cn = rarg_n;
     
    678715                while (cn != NULL) {
    679716                        n_vargs += 1;
    680                         cn = list_next(args, cn);
     717                        cn = list_next(arg_vals, cn);
    681718                }
    682719
     
    695732                        rdata_var_write(array->element[idx], rarg->u.value);
    696733
    697                         rarg_n = list_next(args, rarg_n);
     734                        rarg_n = list_next(arg_vals, rarg_n);
    698735                        idx += 1;
    699736                }
     
    709746
    710747                /* Declare variable using name of formal argument. */
    711                 intmap_set(&block_ar->vars, fun->varg->name->sid,
     748                intmap_set(&block_ar->vars, varg->name->sid,
    712749                    ref_var);
    713750        }
     
    716753        if (rarg_n != NULL) {
    717754                printf("Error: Too many arguments to function '");
    718                 symbol_print_fqn(run->program, fun_ar->fun_sym);
     755                symbol_print_fqn(run->program, proc_ar->proc_sym);
    719756                printf("'.\n");
    720757                exit(1);
    721758        }
     759}
     760
     761/** Fill setter argument in a procedure AR.
     762 *
     763 * When invoking a setter this is used to store its argument value in its
     764 * procedure activation record.
     765 */
     766void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
     767    rdata_item_t *arg_val)
     768{
     769        stree_prop_t *prop;
     770        run_block_ar_t *block_ar;
     771        list_node_t *block_ar_n;
     772        rdata_var_t *var;
     773
     774        (void) run;
     775
     776        /* AR should have been created with run_proc_ar_create(). */
     777        assert(proc_ar->proc_sym != NULL);
     778
     779        /* The procedure being activated should be a property setter. */
     780        prop = symbol_to_prop(proc_ar->proc_sym);
     781        assert(prop != NULL);
     782
     783        /* Fetch first block activation record. */
     784        block_ar_n = list_first(&proc_ar->block_ar);
     785        assert(block_ar_n != NULL);
     786        block_ar = list_node_data(block_ar_n, run_block_ar_t *);
     787
     788        assert(arg_val->ic == ic_value);
     789
     790        /* Construct a variable from the argument value. */
     791        run_value_item_to_var(arg_val, &var);
     792
     793        /* Declare variable using name of formal argument. */
     794        intmap_set(&block_ar->vars, prop->setter_arg_name->sid, var);
    722795}
    723796
     
    726799{
    727800        list_node_t *node;
    728         run_fun_ar_t *fun_ar;
     801        run_proc_ar_t *proc_ar;
    729802
    730803        printf("Backtrace:\n");
    731         node = list_last(&run->thread_ar->fun_ar);
     804        node = list_last(&run->thread_ar->proc_ar);
    732805        while (node != NULL) {
    733806                printf(" * ");
    734                 fun_ar = list_node_data(node, run_fun_ar_t *);
    735                 symbol_print_fqn(run->program, fun_ar->fun_sym);
     807                proc_ar = list_node_data(node, run_proc_ar_t *);
     808                symbol_print_fqn(run->program, proc_ar->proc_sym);
    736809                printf("\n");
    737810
    738                 node = list_prev(&run->thread_ar->fun_ar, node);
    739         }
    740 }
     811                node = list_prev(&run->thread_ar->proc_ar, node);
     812        }
     813}
     814
     815/** Convert item to value item.
     816 *
     817 * If @a item is a value, we just return a copy. If @a item is an address,
     818 * we read from the address.
     819 */
     820void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem)
     821{
     822        rdata_value_t *value;
     823
     824        /*
     825         * This can happen when trying to use output of a function which
     826         * does not return a value.
     827         */
     828        if (item == NULL) {
     829                printf("Error: Sub-expression has no value.\n");
     830                exit(1);
     831        }
     832
     833        /* Address item. Perform read operation. */
     834        if (item->ic == ic_address) {
     835                run_address_read(run, item->u.address, ritem);
     836                return;
     837        }
     838
     839        /* It already is a value, we can share the @c var. */
     840        value = rdata_value_new();
     841        value->var = item->u.value->var;
     842        *ritem = rdata_item_new(ic_value);
     843        (*ritem)->u.value = value;
     844}
     845
     846
     847/** Read data from an address.
     848 *
     849 * Return value stored in a variable at the specified address.
     850 */
     851void run_address_read(run_t *run, rdata_address_t *address,
     852    rdata_item_t **ritem)
     853{
     854        (void) run;
     855
     856        switch (address->ac) {
     857        case ac_var:
     858                rdata_var_read(address->u.var_a->vref, ritem);
     859                break;
     860        case ac_prop:
     861                run_aprop_read(run, address->u.prop_a, ritem);
     862                break;
     863        }
     864
     865        assert((*ritem)->ic == ic_value);
     866}
     867
     868/** Write data to an address.
     869 *
     870 * Store @a value to the variable at @a address.
     871 */
     872void run_address_write(run_t *run, rdata_address_t *address,
     873    rdata_value_t *value)
     874{
     875        (void) run;
     876
     877        switch (address->ac) {
     878        case ac_var:
     879                rdata_var_write(address->u.var_a->vref, value);
     880                break;
     881        case ac_prop:
     882                run_aprop_write(run, address->u.prop_a, value);
     883                break;
     884        }
     885}
     886
     887static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
     888    rdata_item_t **ritem)
     889{
     890        rdata_deleg_t *deleg;
     891        rdata_var_t *obj;
     892        stree_symbol_t *prop_sym;
     893        stree_prop_t *prop;
     894
     895        run_proc_ar_t *proc_ar;
     896
     897#ifdef DEBUG_RUN_TRACE
     898        printf("Read from property.\n");
     899#endif
     900        /*
     901         * If @c tvalue is present, we need to use the relevant part from that
     902         * instead of re-reading the whole thing.
     903         */
     904        if (addr_prop->tvalue != NULL) {
     905                printf("Unimplemented: Property field access.\n");
     906                exit(1);
     907        }
     908
     909        if (addr_prop->apc == apc_named)
     910                deleg = addr_prop->u.named->prop_d;
     911        else
     912                deleg = addr_prop->u.indexed->object_d;
     913
     914        obj = deleg->obj;
     915        prop_sym = deleg->sym;
     916        prop = symbol_to_prop(prop_sym);
     917        assert(prop != NULL);
     918
     919        if (prop->getter_body == NULL) {
     920                printf("Error: Property is not readable.\n");
     921                exit(1);
     922        }
     923
     924        /* Create procedure activation record. */
     925        run_proc_ar_create(run, obj, prop_sym, prop->getter_body, &proc_ar);
     926
     927        /* Fill in arguments (indices). */
     928        if (addr_prop->apc == apc_indexed) {
     929                run_proc_ar_set_args(run, proc_ar,
     930                    &addr_prop->u.indexed->args);
     931        }
     932
     933        /* Run getter. */
     934        run_proc(run, proc_ar, ritem);
     935
     936#ifdef DEBUG_RUN_TRACE
     937        printf("Getter returns ");
     938        rdata_item_print(*ritem);
     939        printf(".\n");
     940        printf("Done reading from property.\n");
     941#endif
     942}
     943
     944static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
     945    rdata_value_t *value)
     946{
     947        rdata_deleg_t *deleg;
     948        rdata_var_t *obj;
     949        stree_symbol_t *prop_sym;
     950        stree_prop_t *prop;
     951
     952        run_proc_ar_t *proc_ar;
     953        rdata_item_t *vitem;
     954        rdata_item_t *ritem;
     955
     956#ifdef DEBUG_RUN_TRACE
     957        printf("Write to property.\n");
     958#endif
     959        /* If @c tvalue is present, we need to modify it and write it back. */
     960        if (addr_prop->tvalue != NULL) {
     961                printf("Unimplemented: Read-modify-write property access.\n");
     962                exit(1);
     963        }
     964
     965        if (addr_prop->apc == apc_named)
     966                deleg = addr_prop->u.named->prop_d;
     967        else
     968                deleg = addr_prop->u.indexed->object_d;
     969
     970        obj = deleg->obj;
     971        prop_sym = deleg->sym;
     972        prop = symbol_to_prop(prop_sym);
     973        assert(prop != NULL);
     974
     975        if (prop->setter_body == NULL) {
     976                printf("Error: Property is not writable.\n");
     977                exit(1);
     978        }
     979
     980        vitem = rdata_item_new(ic_value);
     981        vitem->u.value = value;
     982
     983        /* Create procedure activation record. */
     984        run_proc_ar_create(run, obj, prop_sym, prop->setter_body, &proc_ar);
     985
     986        /* Fill in arguments (indices). */
     987        if (addr_prop->apc == apc_indexed) {
     988                run_proc_ar_set_args(run, proc_ar,
     989                    &addr_prop->u.indexed->args);
     990        }
     991
     992        /* Fill in value argument for setter. */
     993        run_proc_ar_set_setter_arg(run, proc_ar, vitem);
     994
     995        /* Run setter. */
     996        run_proc(run, proc_ar, &ritem);
     997
     998        /* Setter should not return a value. */
     999        assert(ritem == NULL);
     1000
     1001#ifdef DEBUG_RUN_TRACE
     1002        printf("Done writing to property.\n");
     1003#endif
     1004}
     1005
     1006/** Return reference to a variable.
     1007 *
     1008 * Constructs a reference (value item) pointing to @a var.
     1009 */
     1010void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res)
     1011{
     1012        rdata_ref_t *ref;
     1013        rdata_var_t *ref_var;
     1014        rdata_value_t *ref_value;
     1015        rdata_item_t *ref_item;
     1016
     1017        (void) run;
     1018
     1019        /* Create reference to the variable. */
     1020        ref = rdata_ref_new();
     1021        ref_var = rdata_var_new(vc_ref);
     1022        ref->vref = var;
     1023        ref_var->u.ref_v = ref;
     1024
     1025        /* Construct value of the reference to return. */
     1026        ref_item = rdata_item_new(ic_value);
     1027        ref_value = rdata_value_new();
     1028        ref_item->u.value = ref_value;
     1029        ref_value->var = ref_var;
     1030
     1031        *res = ref_item;
     1032}
     1033
     1034/** Return address of reference target.
     1035 *
     1036 * Takes a reference (address or value) and returns the address (item) of
     1037 * the target of the reference.
     1038 */
     1039void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem)
     1040{
     1041        rdata_item_t *ref_val;
     1042        rdata_item_t *item;
     1043        rdata_address_t *address;
     1044        rdata_addr_var_t *addr_var;
     1045
     1046#ifdef DEBUG_RUN_TRACE
     1047        printf("run_dereference()\n");
     1048#endif
     1049        run_cvt_value_item(run, ref, &ref_val);
     1050        assert(ref_val->u.value->var->vc == vc_ref);
     1051
     1052        item = rdata_item_new(ic_address);
     1053        address = rdata_address_new(ac_var);
     1054        addr_var = rdata_addr_var_new();
     1055        item->u.address = address;
     1056        address->u.var_a = addr_var;
     1057        addr_var->vref = ref_val->u.value->var->u.ref_v->vref;
     1058
     1059        if (addr_var->vref == NULL) {
     1060                printf("Error: Accessing null reference.\n");
     1061                exit(1);
     1062        }
     1063
     1064#ifdef DEBUG_RUN_TRACE
     1065        printf("vref set to %p\n", addr_var->vref);
     1066#endif
     1067        *ritem = item;
     1068}
     1069
    7411070
    7421071run_thread_ar_t *run_thread_ar_new(void)
     
    7531082}
    7541083
    755 run_fun_ar_t *run_fun_ar_new(void)
    756 {
    757         run_fun_ar_t *fun_ar;
    758 
    759         fun_ar = calloc(1, sizeof(run_fun_ar_t));
    760         if (fun_ar == NULL) {
     1084run_proc_ar_t *run_proc_ar_new(void)
     1085{
     1086        run_proc_ar_t *proc_ar;
     1087
     1088        proc_ar = calloc(1, sizeof(run_proc_ar_t));
     1089        if (proc_ar == NULL) {
    7611090                printf("Memory allocation failed.\n");
    7621091                exit(1);
    7631092        }
    7641093
    765         return fun_ar;
     1094        return proc_ar;
    7661095}
    7671096
  • uspace/app/sbi/src/run.h

    r94d484a rd0febca  
    3434void run_init(run_t *run);
    3535void run_program(run_t *run, stree_program_t *prog);
    36 void run_fun(run_t *run, run_fun_ar_t *fun_ar, rdata_item_t **res);
     36void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res);
    3737
    3838void run_print_fun_bt(run_t *run);
    3939
    4040rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name);
    41 run_fun_ar_t *run_get_current_fun_ar(run_t *run);
     41run_proc_ar_t *run_get_current_proc_ar(run_t *run);
    4242run_block_ar_t *run_get_current_block_ar(run_t *run);
    4343stree_csi_t *run_get_current_csi(run_t *run);
    4444
    4545void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var);
    46 void run_fun_ar_set_args(run_t *run, run_fun_ar_t *fun_ar, list_t *args);
    47 void run_fun_ar_create(run_t *run, rdata_var_t *obj, stree_fun_t *fun,
    48     run_fun_ar_t **rfun_ar);
     46void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar,
     47    list_t *arg_vals);
     48void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
     49    rdata_item_t *arg_val);
     50void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_symbol_t *proc_sym,
     51    stree_block_t *proc_block, run_proc_ar_t **rproc_ar);
     52
     53void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem);
     54void run_address_read(run_t *run, rdata_address_t *address,
     55    rdata_item_t **ritem);
     56void run_address_write(run_t *run, rdata_address_t *address,
     57    rdata_value_t *value);
     58void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res);
     59void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem);
    4960
    5061run_thread_ar_t *run_thread_ar_new(void);
    51 run_fun_ar_t *run_fun_ar_new(void);
     62run_proc_ar_t *run_proc_ar_new(void);
    5263run_block_ar_t *run_block_ar_new(void);
    5364
  • uspace/app/sbi/src/run_expr.c

    r94d484a rd0febca  
    4141#include "run_texpr.h"
    4242#include "symbol.h"
     43#include "stree.h"
    4344#include "strtab.h"
    4445
     
    8788static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res);
    8889static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res);
     90static void run_index_array(run_t *run, stree_index_t *index,
     91    rdata_item_t *base, list_t *args, rdata_item_t **res);
     92static void run_index_object(run_t *run, stree_index_t *index,
     93    rdata_item_t *base, list_t *args, rdata_item_t **res);
     94static void run_index_string(run_t *run, stree_index_t *index,
     95    rdata_item_t *base, list_t *args, rdata_item_t **res);
    8996static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res);
    9097
     
    143150        rdata_item_t *item;
    144151        rdata_address_t *address;
     152        rdata_addr_var_t *addr_var;
    145153        rdata_value_t *value;
    146154        rdata_var_t *var;
    147155        rdata_deleg_t *deleg_v;
    148156
    149         run_fun_ar_t *fun_ar;
     157        run_proc_ar_t *proc_ar;
    150158        stree_symbol_t *csi_sym;
    151159        stree_csi_t *csi;
     
    164172                /* Found a local variable. */
    165173                item = rdata_item_new(ic_address);
    166                 address = rdata_address_new();
     174                address = rdata_address_new(ac_var);
     175                addr_var = rdata_addr_var_new();
    167176
    168177                item->u.address = address;
    169                 address->vref = var;
     178                address->u.var_a = addr_var;
     179                addr_var->vref = var;
    170180
    171181                *res = item;
     
    181191
    182192        /* Determine currently active object or CSI. */
    183         fun_ar = run_get_current_fun_ar(run);
    184         if (fun_ar->obj != NULL) {
    185                 assert(fun_ar->obj->vc == vc_object);
    186                 obj = fun_ar->obj->u.object_v;
     193        proc_ar = run_get_current_proc_ar(run);
     194        if (proc_ar->obj != NULL) {
     195                assert(proc_ar->obj->vc == vc_object);
     196                obj = proc_ar->obj->u.object_v;
    187197                csi_sym = obj->class_sym;
    188198                csi = symbol_to_csi(csi_sym);
    189199                assert(csi != NULL);
    190200        } else {
    191                 csi = fun_ar->fun_sym->outer_csi;
     201                csi = proc_ar->proc_sym->outer_csi;
    192202                obj = NULL;
    193203        }
     
    238248                var->u.deleg_v = deleg_v;
    239249
    240                 deleg_v->obj = fun_ar->obj;
     250                deleg_v->obj = proc_ar->obj;
    241251                deleg_v->sym = sym;
    242252
     
    270280                /* Return address of the variable. */
    271281                item = rdata_item_new(ic_address);
    272                 address = rdata_address_new();
     282                address = rdata_address_new(ac_var);
     283                addr_var = rdata_addr_var_new();
    273284
    274285                item->u.address = address;
    275                 address->vref = member_var;
     286                address->u.var_a = addr_var;
     287                addr_var->vref = member_var;
    276288
    277289                *res = item;
     
    393405    rdata_item_t **res)
    394406{
    395         run_fun_ar_t *fun_ar;
     407        run_proc_ar_t *proc_ar;
    396408
    397409#ifdef DEBUG_RUN_TRACE
     
    399411#endif
    400412        (void) self_ref;
    401         fun_ar = run_get_current_fun_ar(run);
     413        proc_ar = run_get_current_proc_ar(run);
    402414
    403415        /* Return reference to the currently active object. */
    404         rdata_reference(fun_ar->obj, res);
     416        run_reference(run, proc_ar->obj, res);
    405417}
    406418
     
    438450#endif
    439451
    440         rdata_cvt_value_item(rarg1_i, &rarg1_vi);
    441         rdata_cvt_value_item(rarg2_i, &rarg2_vi);
     452        run_cvt_value_item(run, rarg1_i, &rarg1_vi);
     453        run_cvt_value_item(run, rarg2_i, &rarg2_vi);
    442454
    443455        v1 = rarg1_vi->u.value;
     
    687699                /* Evaluate extent argument. */
    688700                run_expr(run, expr, &rexpr);
    689                 rdata_cvt_value_item(rexpr, &rexpr_vi);
     701                run_cvt_value_item(run, rexpr, &rexpr_vi);
    690702                assert(rexpr_vi->ic == ic_value);
    691703                rexpr_var = rexpr_vi->u.value->var;
     
    727739
    728740        /* Create reference to the new array. */
    729         rdata_reference(array_var, res);
     741        run_reference(run, array_var, res);
    730742}
    731743
     
    782794
    783795        /* Create reference to the new object. */
    784         rdata_reference(obj_var, res);
     796        run_reference(run, obj_var, res);
    785797}
    786798
     
    811823        printf("Run access operation on pre-evaluated base.\n");
    812824#endif
    813         switch (arg->ic) {
    814         case ic_value:
    815                 vc = arg->u.value->var->vc;
    816                 break;
    817         case ic_address:
    818                 vc = arg->u.address->vref->vc;
    819                 break;
    820         default:
    821                 /* Silence warning. */
    822                 abort();
    823         }
     825        vc = rdata_item_get_vc(arg);
    824826
    825827        switch (vc) {
     
    847849
    848850        /* Implicitly dereference. */
    849         rdata_dereference(arg, &darg);
     851        run_dereference(run, arg, &darg);
    850852
    851853        /* Try again. */
     
    865867        printf("Run delegate access operation.\n");
    866868#endif
    867         rdata_cvt_value_item(arg, &arg_vi);
     869        run_cvt_value_item(run, arg, &arg_vi);
    868870        arg_val = arg_vi->u.value;
    869871        assert(arg_val->var->vc == vc_deleg);
     
    906908{
    907909        stree_symbol_t *member;
     910        rdata_var_t *object_var;
    908911        rdata_object_t *object;
    909912        rdata_item_t *ritem;
    910913        rdata_address_t *address;
     914        rdata_addr_var_t *addr_var;
     915        rdata_addr_prop_t *addr_prop;
     916        rdata_aprop_named_t *aprop_named;
     917        rdata_deleg_t *deleg_p;
    911918
    912919        rdata_value_t *value;
     
    918925#endif
    919926        assert(arg->ic == ic_address);
    920         assert(arg->u.value->var->vc == vc_object);
    921 
    922         object = arg->u.value->var->u.object_v;
     927        assert(arg->u.address->ac == ac_var);
     928        assert(arg->u.address->u.var_a->vref->vc == vc_object);
     929
     930        object_var = arg->u.address->u.var_a->vref;
     931        object = object_var->u.object_v;
    923932
    924933        member = symbol_search_csi(run->program, object->class_sym->u.csi,
     
    953962                var->u.deleg_v = deleg_v;
    954963
    955                 deleg_v->obj = arg->u.value->var;
     964                deleg_v->obj = arg->u.address->u.var_a->vref;
    956965                deleg_v->sym = member;
    957966                break;
     
    959968                /* Construct variable address item. */
    960969                ritem = rdata_item_new(ic_address);
    961                 address = rdata_address_new();
     970                address = rdata_address_new(ac_var);
     971                addr_var = rdata_addr_var_new();
    962972                ritem->u.address = address;
    963 
    964                 address->vref = intmap_get(&object->fields,
     973                address->u.var_a = addr_var;
     974
     975                addr_var->vref = intmap_get(&object->fields,
    965976                    access->member_name->sid);
    966                 assert(address->vref != NULL);
     977                assert(addr_var->vref != NULL);
    967978                break;
    968979        case sc_prop:
    969                 printf("Unimplemented: Accessing object property.\n");
    970                 exit(1);
     980                /* Construct named property address. */
     981                ritem = rdata_item_new(ic_address);
     982                address = rdata_address_new(ac_prop);
     983                addr_prop = rdata_addr_prop_new(apc_named);
     984                aprop_named = rdata_aprop_named_new();
     985                ritem->u.address = address;
     986                address->u.prop_a = addr_prop;
     987                addr_prop->u.named = aprop_named;
     988
     989                deleg_p = rdata_deleg_new();
     990                deleg_p->obj = object_var;
     991                deleg_p->sym = member;
     992                addr_prop->u.named->prop_d = deleg_p;
     993                break;
    971994        }
    972995
     
    9851008
    9861009        stree_fun_t *fun;
    987         run_fun_ar_t *fun_ar;
     1010        run_proc_ar_t *proc_ar;
    9881011
    9891012#ifdef DEBUG_RUN_TRACE
     
    10171040                arg = list_node_data(node, stree_expr_t *);
    10181041                run_expr(run, arg, &rarg_i);
    1019                 rdata_cvt_value_item(rarg_i, &rarg_vi);
     1042                run_cvt_value_item(run, rarg_i, &rarg_vi);
    10201043
    10211044                list_append(&arg_vals, rarg_vi);
     
    10261049        assert(fun != NULL);
    10271050
    1028         /* Create function activation record. */
    1029         run_fun_ar_create(run, deleg_v->obj, fun, &fun_ar);
     1051        /* Create procedure activation record. */
     1052        run_proc_ar_create(run, deleg_v->obj, deleg_v->sym, fun->body,
     1053            &proc_ar);
    10301054
    10311055        /* Fill in argument values. */
    1032         run_fun_ar_set_args(run, fun_ar, &arg_vals);
     1056        run_proc_ar_set_args(run, proc_ar, &arg_vals);
    10331057
    10341058        /* Run the function. */
    1035         run_fun(run, fun_ar, res);
     1059        run_proc(run, proc_ar, res);
    10361060
    10371061#ifdef DEBUG_RUN_TRACE
     
    10481072        stree_expr_t *arg;
    10491073        rdata_item_t *rarg_i, *rarg_vi;
     1074        var_class_t vc;
     1075        list_t arg_vals;
     1076
     1077#ifdef DEBUG_RUN_TRACE
     1078        printf("Run index operation.\n");
     1079#endif
     1080        run_expr(run, index->base, &rbase);
     1081
     1082        vc = rdata_item_get_vc(rbase);
     1083
     1084        /* Implicitly dereference. */
     1085        if (vc == vc_ref) {
     1086                run_dereference(run, rbase, &base_i);
     1087        } else {
     1088                base_i = rbase;
     1089        }
     1090
     1091        vc = rdata_item_get_vc(base_i);
     1092
     1093        /* Evaluate arguments (indices). */
     1094        node = list_first(&index->args);
     1095        list_init(&arg_vals);
     1096
     1097        while (node != NULL) {
     1098                arg = list_node_data(node, stree_expr_t *);
     1099                run_expr(run, arg, &rarg_i);
     1100                run_cvt_value_item(run, rarg_i, &rarg_vi);
     1101
     1102                list_append(&arg_vals, rarg_vi);
     1103
     1104                node = list_next(&index->args, node);
     1105        }
     1106
     1107        switch (vc) {
     1108        case vc_array:
     1109                run_index_array(run, index, base_i, &arg_vals, res);
     1110                break;
     1111        case vc_object:
     1112                run_index_object(run, index, base_i, &arg_vals, res);
     1113                break;
     1114        case vc_string:
     1115                run_index_string(run, index, base_i, &arg_vals, res);
     1116                break;
     1117        default:
     1118                printf("Error: Indexing object of bad type (%d).\n", vc);
     1119                exit(1);
     1120        }
     1121}
     1122
     1123/** Run index operation on array. */
     1124static void run_index_array(run_t *run, stree_index_t *index,
     1125    rdata_item_t *base, list_t *args, rdata_item_t **res)
     1126{
     1127        list_node_t *node;
    10501128        rdata_array_t *array;
    1051         var_class_t vc;
     1129        rdata_item_t *arg;
    10521130
    10531131        int i;
     
    10571135        rdata_item_t *ritem;
    10581136        rdata_address_t *address;
    1059 
    1060 #ifdef DEBUG_RUN_TRACE
    1061         printf("Run index operation.\n");
    1062 #endif
    1063         run_expr(run, index->base, &rbase);
    1064 
    1065         switch (rbase->ic) {
    1066         case ic_value:
    1067                 vc = rbase->u.value->var->vc;
    1068                 break;
    1069         case ic_address:
    1070                 vc = rbase->u.address->vref->vc;
    1071                 break;
    1072         default:
    1073                 /* Silence warning. */
    1074                 abort();
    1075         }
    1076 
    1077         if (vc != vc_ref) {
    1078                 printf("Error: Base of index operation is not a reference.\n");
    1079                 exit(1);
    1080         }
    1081 
    1082         rdata_dereference(rbase, &base_i);
    1083         assert(base_i->ic == ic_address);
    1084 
    1085         if (base_i->u.value->var->vc != vc_array) {
    1086                 printf("Error: Indexing something which is not an array.\n");
    1087                 exit(1);
    1088         }
    1089 
    1090         array = base_i->u.value->var->u.array_v;
    1091 
    1092         /* Evaluate arguments (indices). */
    1093         node = list_first(&index->args);
     1137        rdata_addr_var_t *addr_var;
     1138
     1139#ifdef DEBUG_RUN_TRACE
     1140        printf("Run array index operation.\n");
     1141#endif
     1142        (void) run;
     1143        (void) index;
     1144
     1145        assert(base->ic == ic_address);
     1146        assert(base->u.address->ac == ac_var);
     1147        assert(base->u.address->u.var_a->vref->vc == vc_array);
     1148        array = base->u.address->u.var_a->vref->u.array_v;
    10941149
    10951150        /*
     
    10991154        elem_index = 0;
    11001155
     1156        node = list_first(args);
    11011157        i = 0;
     1158
    11021159        while (node != NULL) {
    11031160                if (i >= array->rank) {
     
    11071164                }
    11081165
    1109                 arg = list_node_data(node, stree_expr_t *);
    1110                 run_expr(run, arg, &rarg_i);
    1111                 rdata_cvt_value_item(rarg_i, &rarg_vi);
    1112                 assert(rarg_vi->ic == ic_value);
    1113 
    1114                 if (rarg_vi->u.value->var->vc != vc_int) {
     1166                arg = list_node_data(node, rdata_item_t *);
     1167                assert(arg->ic == ic_value);
     1168
     1169                if (arg->u.value->var->vc != vc_int) {
    11151170                        printf("Error: Array index is not an integer.\n");
    11161171                        exit(1);
    11171172                }
    11181173
    1119                 arg_val = rarg_vi->u.value->var->u.int_v->value;
     1174                arg_val = arg->u.value->var->u.int_v->value;
    11201175
    11211176                if (arg_val < 0 || arg_val >= array->extent[i]) {
     
    11271182                elem_index = elem_index * array->extent[i] + arg_val;
    11281183
    1129                 node = list_next(&index->args, node);
     1184                node = list_next(args, node);
    11301185                i += 1;
    11311186        }
     
    11391194        /* Construct variable address item. */
    11401195        ritem = rdata_item_new(ic_address);
    1141         address = rdata_address_new();
     1196        address = rdata_address_new(ac_var);
     1197        addr_var = rdata_addr_var_new();
    11421198        ritem->u.address = address;
    1143 
    1144         address->vref = array->element[elem_index];
     1199        address->u.var_a = addr_var;
     1200
     1201        addr_var->vref = array->element[elem_index];
    11451202
    11461203        *res = ritem;
    11471204}
     1205
     1206/** Index an object (via its indexer). */
     1207static void run_index_object(run_t *run, stree_index_t *index,
     1208    rdata_item_t *base, list_t *args, rdata_item_t **res)
     1209{
     1210        rdata_item_t *ritem;
     1211        rdata_address_t *address;
     1212        rdata_addr_prop_t *addr_prop;
     1213        rdata_aprop_indexed_t *aprop_indexed;
     1214        rdata_var_t *obj_var;
     1215        stree_csi_t *obj_csi;
     1216        rdata_deleg_t *object_d;
     1217        stree_symbol_t *indexer_sym;
     1218        stree_ident_t *indexer_ident;
     1219
     1220        list_node_t *node;
     1221        rdata_item_t *arg;
     1222
     1223#ifdef DEBUG_RUN_TRACE
     1224        printf("Run object index operation.\n");
     1225#endif
     1226        (void) run;
     1227        (void) index;
     1228
     1229        /* Construct property address item. */
     1230        ritem = rdata_item_new(ic_address);
     1231        address = rdata_address_new(ac_prop);
     1232        addr_prop = rdata_addr_prop_new(apc_indexed);
     1233        aprop_indexed = rdata_aprop_indexed_new();
     1234        ritem->u.address = address;
     1235        address->u.prop_a = addr_prop;
     1236        addr_prop->u.indexed = aprop_indexed;
     1237
     1238        if (base->ic != ic_address || base->u.address->ac != ac_var) {
     1239                /* XXX Several other cases can occur. */
     1240                printf("Unimplemented: Indexing object varclass via something "
     1241                    "which is not a simple variable reference.\n");
     1242                exit(1);
     1243        }
     1244
     1245        /* Find indexer symbol. */
     1246        obj_var = base->u.address->u.var_a->vref;
     1247        assert(obj_var->vc == vc_object);
     1248        indexer_ident = stree_ident_new();
     1249        indexer_ident->sid = strtab_get_sid(INDEXER_IDENT);
     1250        obj_csi = symbol_to_csi(obj_var->u.object_v->class_sym);
     1251        assert(obj_csi != NULL);
     1252        indexer_sym = symbol_search_csi(run->program, obj_csi, indexer_ident);
     1253
     1254        /* Construct delegate. */
     1255        object_d = rdata_deleg_new();
     1256        object_d->obj = obj_var;
     1257        object_d->sym = indexer_sym;
     1258        aprop_indexed->object_d = object_d;
     1259
     1260        /* Copy list of argument values. */
     1261        list_init(&aprop_indexed->args);
     1262
     1263        node = list_first(args);
     1264        while (node != NULL) {
     1265                arg = list_node_data(node, rdata_item_t *);
     1266                list_append(&aprop_indexed->args, arg);
     1267                node = list_next(args, node);
     1268        }
     1269
     1270        *res = ritem;
     1271}
     1272
     1273/** Run index operation on string. */
     1274static void run_index_string(run_t *run, stree_index_t *index,
     1275    rdata_item_t *base, list_t *args, rdata_item_t **res)
     1276{
     1277        list_node_t *node;
     1278        rdata_string_t *string;
     1279        rdata_item_t *base_vi;
     1280        rdata_item_t *arg;
     1281
     1282        int i;
     1283        int elem_index;
     1284        int arg_val;
     1285        int rc;
     1286
     1287        rdata_value_t *value;
     1288        rdata_var_t *cvar;
     1289        rdata_item_t *ritem;
     1290        int cval;
     1291
     1292#ifdef DEBUG_RUN_TRACE
     1293        printf("Run string index operation.\n");
     1294#endif
     1295        (void) run;
     1296        (void) index;
     1297
     1298        run_cvt_value_item(run, base, &base_vi);
     1299        assert(base_vi->u.value->var->vc == vc_string);
     1300        string = base->u.value->var->u.string_v;
     1301
     1302        /*
     1303         * Linear index of the desired element. Elements are stored in
     1304         * lexicographic order with the last index changing the fastest.
     1305         */
     1306        node = list_first(args);
     1307        elem_index = 0;
     1308
     1309        i = 0;
     1310        while (node != NULL) {
     1311                if (i >= 1) {
     1312                        printf("Error: Too many indices string.\n");
     1313                        exit(1);
     1314                }
     1315
     1316                arg = list_node_data(node, rdata_item_t *);
     1317                assert(arg->ic == ic_value);
     1318
     1319                if (arg->u.value->var->vc != vc_int) {
     1320                        printf("Error: String index is not an integer.\n");
     1321                        exit(1);
     1322                }
     1323
     1324                arg_val = arg->u.value->var->u.int_v->value;
     1325                elem_index = arg_val;
     1326
     1327                node = list_next(args, node);
     1328                i += 1;
     1329        }
     1330
     1331        if (i < 1) {
     1332                printf("Error: Too few indices for string.\n");
     1333                exit(1);
     1334        }
     1335
     1336        rc = os_str_get_char(string->value, elem_index, &cval);
     1337        if (rc != EOK) {
     1338                printf("Error: String index (value: %d) is out of range.\n",
     1339                    arg_val);
     1340                exit(1);
     1341        }
     1342
     1343        /* Construct character value. */
     1344        ritem = rdata_item_new(ic_value);
     1345        value = rdata_value_new();
     1346        ritem->u.value = value;
     1347
     1348        cvar = rdata_var_new(vc_int);
     1349        cvar->u.int_v = rdata_int_new();
     1350        cvar->u.int_v->value = cval;
     1351        value->var = cvar;
     1352
     1353        *res = ritem;
     1354}
     1355
    11481356
    11491357/** Execute assignment. */
     
    11601368        run_expr(run, assign->src, &rsrc_i);
    11611369
    1162         rdata_cvt_value_item(rsrc_i, &rsrc_vi);
     1370        run_cvt_value_item(run, rsrc_i, &rsrc_vi);
     1371        assert(rsrc_vi->ic == ic_value);
    11631372        src_val = rsrc_vi->u.value;
    11641373
     
    11691378        }
    11701379
    1171         rdata_address_write(rdest_i->u.address, rsrc_vi->u.value);
     1380        run_address_write(run, rdest_i->u.address, rsrc_vi->u.value);
    11721381
    11731382        *res = NULL;
     
    11871396
    11881397        (void) run;
    1189         rdata_cvt_value_item(item, &vitem);
     1398        run_cvt_value_item(run, item, &vitem);
    11901399
    11911400        assert(vitem->ic == ic_value);
  • uspace/app/sbi/src/run_t.h

    r94d484a rd0febca  
    4444
    4545
    46 /** Function activation record
     46/** Procedure activation record
    4747 *
    48  * One is created whenever a function is invoked.
     48 * A procedure can be a member function, a named property or an indexed
     49 * property. A procedure activation record is created whenever a procedure
     50 * is invoked.
    4951 */
    50 typedef struct run_fun_ar {
    51         /** Object on which the member function is being invoked or @c NULL. */
     52typedef struct run_proc_ar {
     53        /** Object on which the procedure is being invoked or @c NULL. */
    5254        struct rdata_var *obj;
    5355
    54         /** Definition of function being invoked */
    55         struct stree_symbol *fun_sym;
     56        /** Definition of function or property being invoked */
     57        struct stree_symbol *proc_sym;
     58
     59        /** Main block of procedure being invoked */
     60        struct stree_block *proc_block;
    5661
    5762        /** Block activation records */
    5863        list_t block_ar; /* of run_block_ar_t */
    5964
    60         /** Function return value or @c NULL if not set. */
     65        /** Procedure return value or @c NULL if not set. */
    6166        struct rdata_item *retval;
    62 } run_fun_ar_t;
     67} run_proc_ar_t;
    6368
    6469/** Bailout mode
     
    7378        bm_stat,
    7479
    75         /** Return from function */
    76         bm_fun,
     80        /** Return from procedure */
     81        bm_proc,
    7782
    7883        /** Exception */
     
    8691typedef struct run_thread_ar {
    8792        /** Function activation records */
    88         list_t fun_ar; /* of run_fun_ar_t */
     93        list_t proc_ar; /* of run_proc_ar_t */
    8994
    9095        /** Bailout mode */
  • uspace/app/sbi/src/stree.c

    r94d484a rd0febca  
    136136}
    137137
    138 stree_fun_arg_t *stree_fun_arg_new(void)
    139 {
    140         stree_fun_arg_t *fun_arg;
    141 
    142         fun_arg = calloc(1, sizeof(stree_fun_arg_t));
    143         if (fun_arg == NULL) {
    144                 printf("Memory allocation failed.\n");
    145                 exit(1);
    146         }
    147 
    148         return fun_arg;
     138stree_proc_arg_t *stree_proc_arg_new(void)
     139{
     140        stree_proc_arg_t *proc_arg;
     141
     142        proc_arg = calloc(1, sizeof(stree_proc_arg_t));
     143        if (proc_arg == NULL) {
     144                printf("Memory allocation failed.\n");
     145                exit(1);
     146        }
     147
     148        return proc_arg;
    149149}
    150150
     
    561561
    562562/** Determine if argument @a arg has attribute of class @a aac. */
    563 bool_t stree_arg_has_attr(stree_fun_arg_t *arg, arg_attr_class_t aac)
     563bool_t stree_arg_has_attr(stree_proc_arg_t *arg, arg_attr_class_t aac)
    564564{
    565565        list_node_t *node;
  • uspace/app/sbi/src/stree.h

    r94d484a rd0febca  
    4040stree_prop_t *stree_prop_new(void);
    4141
    42 stree_fun_arg_t *stree_fun_arg_new(void);
     42stree_proc_arg_t *stree_proc_arg_new(void);
    4343stree_arg_attr_t *stree_arg_attr_new(arg_attr_class_t aac);
    4444
     
    7979stree_program_t *stree_program_new(void);
    8080
    81 bool_t stree_arg_has_attr(stree_fun_arg_t *arg, arg_attr_class_t aac);
     81bool_t stree_arg_has_attr(stree_proc_arg_t *arg, arg_attr_class_t aac);
    8282bool_t stree_is_csi_derived_from_csi(stree_csi_t *a, stree_csi_t *b);
    8383
  • uspace/app/sbi/src/stree_t.h

    r94d484a rd0febca  
    270270
    271271/** Statement block */
    272 typedef struct {
     272typedef struct stree_block {
    273273        /** List of statements in the block */
    274274        list_t stats; /* of stree_stat_t */
     
    327327        stree_block_t *finally_block;
    328328} stree_wef_t;
    329 
    330329
    331330/** Statement class */
     
    378377        /* Attributes */
    379378        list_t attr; /* of stree_arg_attr_t */
    380 } stree_fun_arg_t;
     379} stree_proc_arg_t;
    381380
    382381/** Member function declaration */
     
    389388
    390389        /** Formal parameters */
    391         list_t args; /* of stree_fun_arg_t */
     390        list_t args; /* of stree_proc_arg_t */
    392391
    393392        /** Variadic argument or @c NULL if none. */
    394         stree_fun_arg_t *varg;
     393        stree_proc_arg_t *varg;
    395394
    396395        /** Return type */
     
    413412        struct stree_symbol *symbol;
    414413        stree_texpr_t *type;
     414
     415        stree_block_t *getter_body;
     416        stree_ident_t *setter_arg_name;
     417        stree_block_t *setter_body;
     418
     419        /** Formal parameters (for indexed properties) */
     420        list_t args; /* of stree_proc_arg_t */
     421
     422        /** Variadic argument or @c NULL if none. */
     423        stree_proc_arg_t *varg;
    415424} stree_prop_t;
     425
     426/**
     427 * Fake identifier used with indexed properties. (Mostly for error messages.)
     428 */
     429#define INDEXER_IDENT "$indexer"
    416430
    417431typedef enum {
  • uspace/app/sbi/src/strtab.c

    r94d484a rd0febca  
    4949}
    5050
    51 sid_t strtab_get_sid(char *str)
     51sid_t strtab_get_sid(const char *str)
    5252{
    5353        list_node_t *node;
  • uspace/app/sbi/src/strtab.h

    r94d484a rd0febca  
    3333
    3434void strtab_init(void);
    35 sid_t strtab_get_sid(char *str);
     35sid_t strtab_get_sid(const char *str);
    3636char *strtab_get_str(sid_t sid);
    3737
Note: See TracChangeset for help on using the changeset viewer.