Ignore:
File:
1 edited

Legend:

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

    r051bc69a rc5cb943d  
    4242#include "builtin/bi_boxed.h"
    4343#include "builtin/bi_error.h"
     44#include "builtin/bi_char.h"
    4445#include "builtin/bi_fun.h"
     46#include "builtin/bi_int.h"
    4547#include "builtin/bi_textfile.h"
    4648#include "builtin/bi_string.h"
     
    5254#include "os/os.h"
    5355#include "parse.h"
     56#include "rdata.h"
    5457#include "run.h"
    5558#include "stree.h"
     
    8992
    9093        bi_error_declare(bi);
     94        bi_char_declare(bi);
    9195        bi_fun_declare(bi);
     96        bi_int_declare(bi);
    9297        bi_textfile_declare(bi);
    9398        bi_string_declare(bi);
     
    105110        bi_boxed_bind(bi);
    106111        bi_error_bind(bi);
     112        bi_char_bind(bi);
    107113        bi_fun_bind(bi);
     114        bi_int_bind(bi);
    108115        bi_textfile_bind(bi);
    109116        bi_string_bind(bi);
     
    250257{
    251258        stree_symbol_t *fun_sym;
    252         builtin_t *bi;
    253259        builtin_proc_t bproc;
    254260
     
    257263#endif
    258264        fun_sym = proc->outer_symbol;
    259         bi = run->program->builtin;
    260265
    261266        bproc = proc->bi_handler;
     
    298303}
    299304
    300 /** Declare a builtin function in @a csi.
     305/** Return string value from builtin procedure.
     306 *
     307 * Makes it easy for a builtin procedure to return value of type @c string.
     308 *
     309 * @param run           Runner object
     310 * @param str           String value. Must be allocated from heap and its
     311 *                      ownership is hereby given up.
     312 */
     313void builtin_return_string(run_t *run, const char *astr)
     314{
     315        rdata_string_t *rstring;
     316        rdata_var_t *rvar;
     317        rdata_value_t *rval;
     318        rdata_item_t *ritem;
     319
     320        run_proc_ar_t *proc_ar;
     321
     322#ifdef DEBUG_RUN_TRACE
     323        printf("Return string '%s' from builtin function.\n", astr);
     324#endif
     325        rstring = rdata_string_new();
     326        rstring->value = astr;
     327
     328        rvar = rdata_var_new(vc_string);
     329        rvar->u.string_v = rstring;
     330        rval = rdata_value_new();
     331        rval->var = rvar;
     332
     333        ritem = rdata_item_new(ic_value);
     334        ritem->u.value = rval;
     335
     336        proc_ar = run_get_current_proc_ar(run);
     337        proc_ar->retval = ritem;
     338}
     339
     340/** Declare a static builtin function in @a csi.
    301341 *
    302342 * Declare a builtin function member of CSI @a csi. Deprecated in favor
     
    314354        stree_csimbr_t *csimbr;
    315355        stree_symbol_t *fun_sym;
     356        stree_symbol_attr_t *sym_attr;
    316357
    317358        ident = stree_ident_new();
     
    333374        fun_sym->u.fun = fun;
    334375        fun_sym->outer_csi = csi;
     376
     377        sym_attr = stree_symbol_attr_new(sac_static);
     378        list_append(&fun_sym->attr, sym_attr);
     379
    335380        fun->symbol = fun_sym;
    336381        fun->proc->outer_symbol = fun_sym;
Note: See TracChangeset for help on using the changeset viewer.