Changeset 39e8406 in mainline for uspace/app/sbi/src/builtin.c


Ignore:
Timestamp:
2010-03-20T21:57:13Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b535aeb
Parents:
6ba20a6b
Message:

Update SBI to rev. 128.

File:
1 edited

Legend:

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

    r6ba20a6b r39e8406  
    4444static stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name);
    4545static void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name);
    46 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name);
     46static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name,
     47    stree_texpr_t *type);
     48
     49static stree_texpr_t *builtin_mktype_string_array(void);
    4750
    4851static void builtin_write_line(run_t *run);
     
    8689
    8790        bi_exec = builtin_declare_fun(csi, "Exec");
    88         builtin_fun_add_vararg(bi_exec, "args");
    89 }
    90 
    91 void builtin_run_proc(run_t *run, stree_symbol_t *proc_sym)
    92 {
     91        builtin_fun_add_vararg(bi_exec, "args",
     92            builtin_mktype_string_array());
     93}
     94
     95void builtin_run_proc(run_t *run, stree_proc_t *proc)
     96{
     97        stree_symbol_t *fun_sym;
     98
    9399#ifdef DEBUG_RUN_TRACE
    94100        printf("Run builtin procedure.\n");
    95101#endif
    96         if (proc_sym == bi_write_line) {
     102        fun_sym = proc->outer_symbol;
     103
     104        if (fun_sym == bi_write_line) {
    97105                builtin_write_line(run);
    98         } else if (proc_sym == bi_exec) {
     106        } else if (fun_sym == bi_exec) {
    99107                builtin_exec(run);
    100108        } else {
     
    109117        stree_fun_t *fun;
    110118        stree_csimbr_t *csimbr;
    111         stree_symbol_t *symbol;
     119        stree_symbol_t *fun_sym;
    112120
    113121        ident = stree_ident_new();
     
    116124        fun = stree_fun_new();
    117125        fun->name = ident;
    118         fun->body = NULL;
     126        fun->proc = stree_proc_new();
     127        fun->proc->body = NULL;
    119128        list_init(&fun->args);
    120129
     
    122131        csimbr->u.fun = fun;
    123132
    124         symbol = stree_symbol_new(sc_fun);
    125         symbol->u.fun = fun;
    126         symbol->outer_csi = csi;
    127         fun->symbol = symbol;
     133        fun_sym = stree_symbol_new(sc_fun);
     134        fun_sym->u.fun = fun;
     135        fun_sym->outer_csi = csi;
     136        fun->symbol = fun_sym;
     137        fun->proc->outer_symbol = fun_sym;
    128138
    129139        list_append(&csi->members, csimbr);
    130140
    131         return symbol;
     141        return fun_sym;
    132142}
    133143
     
    150160
    151161/** Add variadic formal parameter to function. */
    152 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name)
     162static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name,
     163    stree_texpr_t *type)
    153164{
    154165        stree_proc_arg_t *proc_arg;
     
    161172        proc_arg->name = stree_ident_new();
    162173        proc_arg->name->sid = strtab_get_sid(name);
    163         proc_arg->type = NULL; /* XXX */
     174        proc_arg->type = type;
    164175
    165176        fun->varg = proc_arg;
     177}
     178
     179/** Construct a @c string[] type expression. */
     180static stree_texpr_t *builtin_mktype_string_array(void)
     181{
     182        stree_texpr_t *tstring;
     183        stree_texpr_t *tsarray;
     184        stree_tliteral_t *tliteral;
     185        stree_tindex_t *tindex;
     186
     187        /* Construct @c string */
     188        tstring = stree_texpr_new(tc_tliteral);
     189        tliteral = stree_tliteral_new(tlc_string);
     190        tstring->u.tliteral = tliteral;
     191
     192        /* Construct the indexing node */
     193        tsarray = stree_texpr_new(tc_tindex);
     194        tindex = stree_tindex_new();
     195        tsarray->u.tindex = tindex;
     196
     197        tindex->base_type = tstring;
     198        tindex->n_args = 1;
     199        list_init(&tindex->args);
     200
     201        return tsarray;
    166202}
    167203
Note: See TracChangeset for help on using the changeset viewer.