Changes in / [ecb6ac32:73060801] in mainline


Ignore:
Location:
uspace
Files:
6 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/Makefile

    recb6ac32 r73060801  
    3434
    3535SOURCES = \
    36         src/builtin/bi_error.c \
    3736        src/builtin/bi_fun.c \
    3837        src/builtin/bi_textfile.c \
    3938        src/os/helenos.c \
    4039        src/ancr.c \
    41         src/bigint.c \
    4240        src/builtin.c \
    4341        src/imode.c \
  • uspace/app/sbi/src/builtin.c

    recb6ac32 r73060801  
    4141#include <assert.h>
    4242#include "ancr.h"
    43 #include "builtin/bi_error.h"
    4443#include "builtin/bi_fun.h"
    4544#include "builtin/bi_textfile.h"
     
    8786         */
    8887
    89         bi_error_declare(bi);
    9088        bi_fun_declare(bi);
    9189        bi_textfile_declare(bi);
     
    9492        ancr_module_process(program, program->module);
    9593
    96         bi_error_bind(bi);
    9794        bi_fun_bind(bi);
    9895        bi_textfile_bind(bi);
  • uspace/app/sbi/src/builtin/bi_fun.c

    recb6ac32 r73060801  
    3232#include <stdlib.h>
    3333#include <assert.h>
    34 #include "../bigint.h"
    3534#include "../builtin.h"
    3635#include "../list.h"
     
    108107        switch (var->vc) {
    109108        case vc_int:
    110                 bigint_print(&var->u.int_v->value);
    111                 putchar('\n');
     109                printf("%d\n", var->u.int_v->value);
    112110                break;
    113111        case vc_string:
  • uspace/app/sbi/src/builtin/bi_textfile.c

    recb6ac32 r73060801  
    3232#include <stdlib.h>
    3333#include <assert.h>
    34 #include "../bigint.h"
    3534#include "../builtin.h"
    3635#include "../debug.h"
     
    345344        /* Construct return value. */
    346345        eof_int = rdata_int_new();
    347         bigint_init(&eof_int->value, eof_flag);
     346        eof_int->value = eof_flag;
    348347
    349348        eof_var = rdata_var_new(vc_int);
  • uspace/app/sbi/src/builtin_t.h

    recb6ac32 r73060801  
    4242        /** Grandfather object */
    4343        struct stree_symbol *gf_class;
    44 
    45         /** Error class for nil reference access. */
    46         struct stree_csi *error_nilreference;
    47 
    48         /** Error class for out-of-bounds array access. */
    49         struct stree_csi *error_outofbounds;
    5044} builtin_t;
    5145
  • uspace/app/sbi/src/debug.h

    recb6ac32 r73060801  
    4545//#define DEBUG_RUN_TRACE
    4646
    47 /** Uncomment this to get verbose debugging messages for bigint computation. */
    48 //#define DEBUG_BIGINT_TRACE
    49 
    5047#endif
  • uspace/app/sbi/src/imode.c

    recb6ac32 r73060801  
    4040#include <stdio.h>
    4141#include <stdlib.h>
    42 #include "os/os.h"
    4342#include "ancr.h"
    4443#include "assert.h"
     
    123122        list_append(&run.thread_ar->proc_ar, proc_ar);
    124123
    125         printf("SBI interactive mode. ");
    126         os_input_disp_help();
    127 
    128124        quit_im = b_false;
    129125        while (quit_im != b_true) {
     
    156152                run_stat(&run, stat, &rexpr);
    157153
    158                 /* Check for unhandled exceptions. */
    159                 run_exc_check_unhandled(&run);
    160 
    161154                if (rexpr != NULL) {
    162155                        /* Convert expression result to value item. */
  • uspace/app/sbi/src/lex.c

    recb6ac32 r73060801  
    3434#include <stdio.h>
    3535#include <stdlib.h>
    36 #include "bigint.h"
    3736#include "mytypes.h"
    3837#include "input.h"
     
    136135        { lc_assign,    "=" },
    137136        { lc_plus,      "+" },
    138         { lc_minus,     "-" },
    139         { lc_mult,      "*" },
    140137        { lc_increase,  "+=" },
    141138
     
    208205                break;
    209206        case lc_lit_int:
    210                 printf("(");
    211                 bigint_print(&lem->u.lit_int.value);
    212                 printf(")");
     207                printf("(%d)", lem->u.lit_int.value);
    213208                break;
    214209        case lc_lit_string:
     
    272267 *
    273268 * @param lex           Lexer object.
    274  * @return              Pointer to current lem. Owned by @a lex and only valid
    275  *                      until next call to lex_next().
    276269 */
    277270lem_t *lex_get_current(lex_t *lex)
     
    383376                lex->current.lclass = lc_plus; ++bp; break;
    384377
    385         case '-':
    386                 lex->current.lclass = lc_minus; ++bp; break;
    387 
    388         case '*':
    389                 lex->current.lclass = lc_mult; ++bp; break;
    390 
    391378        case '<':
    392379                if (bp[1] == '=') {
     
    471458{
    472459        char *bp;
    473         bigint_t value;
    474         bigint_t dgval;
    475         bigint_t base;
    476         bigint_t tprod;
     460        int value;
    477461
    478462        bp = lex->ibp;
    479 
    480         bigint_init(&value, 0);
    481         bigint_init(&base, 10);
     463        value = 0;
    482464
    483465        while (is_digit(*bp)) {
    484                 bigint_mul(&value, &base, &tprod);
    485                 bigint_init(&dgval, digit_value(*bp));
    486 
    487                 bigint_destroy(&value);
    488                 bigint_add(&tprod, &dgval, &value);
    489                 bigint_destroy(&tprod);
    490                 bigint_destroy(&dgval);
    491 
     466                value = value * 10 + digit_value(*bp);
    492467                ++bp;
    493468        }
    494469
    495         bigint_destroy(&base);
    496 
    497470        lex->ibp = bp;
    498471
    499472        lex->current.lclass = lc_lit_int;
    500         bigint_shallow_copy(&value, &lex->current.u.lit_int.value);
     473        lex->current.u.lit_int.value = value;
    501474}
    502475
  • uspace/app/sbi/src/lex_t.h

    recb6ac32 r73060801  
    2929#ifndef LEX_T_H_
    3030#define LEX_T_H_
    31 
    32 #include "bigint_t.h"
    3331
    3432/** Lexical element class */
     
    9795        lc_assign,
    9896        lc_plus,
    99         lc_minus,
    100         lc_mult,
    10197        lc_increase,
    10298
     
    116112typedef struct {
    117113        /* Integer value */
    118         bigint_t value;
     114        int value;
    119115} lem_lit_int_t;
    120116
  • uspace/app/sbi/src/main.c

    recb6ac32 r73060801  
    9494        parse_module(&parse);
    9595
    96         /* Check for parse errors. */
    9796        if (parse.error)
    9897                return 1;
     
    106105        stype_module(&stype, program->module);
    107106
    108         /* Check for typing errors. */
    109107        if (stype.error)
    110108                return 1;
     
    113111        run_init(&run);
    114112        run_program(&run, program);
    115 
    116         /* Check for run-time errors. */
    117         if (run.thread_ar->error)
    118                 return 1;
    119113
    120114        return 0;
  • uspace/app/sbi/src/mytypes.h

    recb6ac32 r73060801  
    4747#define EOK 0
    4848
    49 #include "bigint_t.h"
    5049#include "builtin_t.h"
    5150#include "input_t.h"
  • uspace/app/sbi/src/os/helenos.c

    recb6ac32 r73060801  
    101101}
    102102
    103 /** Display survival help message. */
    104 void os_input_disp_help(void)
    105 {
    106         printf("Press Ctrl-Q to quit.\n");
    107 }
    108 
    109103/** Read one line of input from the user. */
    110104int os_input_line(char **ptr)
  • uspace/app/sbi/src/os/os.h

    recb6ac32 r73060801  
    3434char *os_str_dup(const char *str);
    3535int os_str_get_char(const char *str, int index, int *out_char);
    36 void os_input_disp_help(void);
    3736int os_input_line(char **ptr);
    3837int os_exec(char *const cmd[]);
  • uspace/app/sbi/src/os/posix.c

    recb6ac32 r73060801  
    9595static char os_input_buffer[OS_INPUT_BUFFER_SIZE];
    9696
    97 /** Display survival help message. */
    98 void os_input_disp_help(void)
    99 {
    100         printf("Send ^C (SIGINT) to quit.\n");
    101 }
    102 
    10397/** Read one line of input from the user. */
    10498int os_input_line(char **ptr)
  • uspace/app/sbi/src/p_expr.c

    recb6ac32 r73060801  
    3131#include <assert.h>
    3232#include <stdlib.h>
    33 #include "bigint.h"
    3433#include "debug.h"
    3534#include "lex.h"
     
    4544static stree_expr_t *parse_comparative(parse_t *parse);
    4645static stree_expr_t *parse_additive(parse_t *parse);
    47 static stree_expr_t *parse_multip(parse_t *parse);
    4846static stree_expr_t *parse_prefix(parse_t *parse);
    4947static stree_expr_t *parse_prefix_new(parse_t *parse);
     
    5351static stree_expr_t *parse_pf_index(parse_t *parse, stree_expr_t *a);
    5452static stree_expr_t *parse_pf_as(parse_t *parse, stree_expr_t *a);
    55 static stree_expr_t *parse_paren(parse_t *parse);
    5653static stree_expr_t *parse_primitive(parse_t *parse);
    5754static stree_expr_t *parse_nameref(parse_t *parse);
     
    169166        stree_expr_t *a, *b, *tmp;
    170167        stree_binop_t *binop;
    171         binop_class_t bc;
    172 
    173         a = parse_multip(parse);
    174         while (lcur_lc(parse) == lc_plus || lcur_lc(parse) == lc_minus) {
     168
     169        a = parse_prefix(parse);
     170        while (lcur_lc(parse) == lc_plus) {
    175171                if (parse_is_error(parse))
    176172                        break;
    177173
    178                 switch (lcur_lc(parse)) {
    179                 case lc_plus: bc = bo_plus; break;
    180                 case lc_minus: bc = bo_minus; break;
    181                 default: assert(b_false);
    182                 }
    183 
    184174                lskip(parse);
    185                 b = parse_multip(parse);
    186 
    187                 binop = stree_binop_new(bc);
     175                b = parse_prefix(parse);
     176
     177                binop = stree_binop_new(bo_plus);
    188178                binop->arg1 = a;
    189179                binop->arg2 = b;
     
    197187}
    198188
    199 /** Parse multiplicative expression.
    200  *
    201  * @param parse         Parser object.
    202  */
    203 static stree_expr_t *parse_multip(parse_t *parse)
    204 {
    205         stree_expr_t *a, *b, *tmp;
    206         stree_binop_t *binop;
    207         binop_class_t bc;
    208 
    209         a = parse_prefix(parse);
    210         while (lcur_lc(parse) == lc_mult) {
    211                 if (parse_is_error(parse))
    212                         break;
    213 
    214                 switch (lcur_lc(parse)) {
    215                 case lc_mult: bc = bo_mult; break;
    216                 default: assert(b_false);
    217                 }
    218 
    219                 lskip(parse);
    220                 b = parse_prefix(parse);
    221 
    222                 binop = stree_binop_new(bc);
    223                 binop->arg1 = a;
    224                 binop->arg2 = b;
    225 
    226                 tmp = stree_expr_new(ec_binop);
    227                 tmp->u.binop = binop;
    228                 a = tmp;
    229         }
    230 
    231         return a;
    232 }
    233 
    234189/** Parse prefix expression.
    235190 *
     
    239194{
    240195        stree_expr_t *a;
    241         stree_expr_t *tmp;
    242         stree_unop_t *unop;
    243         unop_class_t uc;
    244196
    245197        switch (lcur_lc(parse)) {
    246198        case lc_plus:
    247         case lc_minus:
    248                 if (parse_is_error(parse))
    249                         return parse_recovery_expr(parse);
    250 
    251                 switch (lcur_lc(parse)) {
    252                 case lc_plus: uc = uo_plus; break;
    253                 case lc_minus: uc = uo_minus; break;
    254                 default: assert(b_false);
    255                 }
    256 
    257                 lskip(parse);
    258                 a = parse_postfix(parse);
    259 
    260                 unop = stree_unop_new(uc);
    261                 unop->arg = a;
    262 
    263                 tmp = stree_expr_new(ec_unop);
    264                 tmp->u.unop = unop;
    265                 a = tmp;
     199                printf("Unimplemented: Unary plus.\n");
     200                a = parse_recovery_expr(parse);
     201                parse_note_error(parse);
    266202                break;
    267203        case lc_new:
     
    312248        stree_expr_t *tmp;
    313249
    314         a = parse_paren(parse);
     250        a = parse_primitive(parse);
    315251
    316252        while (lcur_lc(parse) == lc_period || lcur_lc(parse) == lc_lparen ||
     
    462398}
    463399
    464 /** Parse possibly partenthesized expression.
    465  *
    466  * @param parse         Parser object.
    467  */
    468 static stree_expr_t *parse_paren(parse_t *parse)
    469 {
    470         stree_expr_t *expr;
    471 
    472         if (lcur_lc(parse) == lc_lparen) {
    473                 lskip(parse);
    474                 expr = parse_expr(parse);
    475                 lmatch(parse, lc_rparen);
    476         } else {
    477                 expr = parse_primitive(parse);
    478         }
    479 
    480         return expr;
    481 }
    482 
    483 
    484400/** Parse primitive expression.
    485401 *
     
    543459
    544460        literal = stree_literal_new(ltc_int);
    545         bigint_clone(&lcur(parse)->u.lit_int.value,
    546             &literal->u.lit_int.value);
     461        literal->u.lit_int.value = lcur(parse)->u.lit_int.value;
    547462
    548463        lskip(parse);
  • uspace/app/sbi/src/parse.c

    recb6ac32 r73060801  
    7979static stree_except_t *parse_except(parse_t *parse);
    8080
    81 /** Initialize parser object.
    82  *
    83  * Set up parser @a parse to use lexer @a lex for input and to store
    84  * output (i.e. new declarations) to program @a prog. @a prog is not
    85  * necessarily empty, the declarations being parsed are simply added
    86  * to it.
    87  *
    88  * @param parse         Parser object.
    89  * @param prog          Destination program stree.
    90  * @param lex           Input lexer.
    91  */
    9281void parse_init(parse_t *parse, stree_program_t *prog, struct lex *lex)
    9382{
     
    10291}
    10392
    104 /** Parse module.
    105  *
    106  * Parse a program module.
    107  *
    108  * The input is read using the lexer associated with @a parse. The resulting
    109  * declarations are added to existing declarations in the program associated
    110  * with @a parse.
    111  *
    112  * If any parse error occurs, parse->error will @c b_true when this function
    113  * returns. parse->error_bailout will be @c b_true if the error has not
    114  * been recovered yet. Similar holds for other parsing functions in this
    115  * module.
    116  *
    117  * @param parse         Parser object.
    118  */
     93/** Parse module. */
    11994void parse_module(parse_t *parse)
    12095{
     
    142117}
    143118
    144 /** Parse class, struct or interface declaration.
    145  *
    146  * @param parse         Parser object.
    147  * @param dclass        What to parse: @c lc_class, @c lc_struct or @c lc_csi.
    148  * @param outer_csi     CSI containing this declaration or @c NULL if global.
    149  * @return              New syntax tree node.
    150  */
     119/** Parse class, struct or interface declaration. */
    151120static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass,
    152121    stree_csi_t *outer_csi)
     
    200169}
    201170
    202 /** Parse class, struct or interface member.
    203  *
    204  * @param parse         Parser object.
    205  * @param outer_csi     CSI containing this declaration or @c NULL if global.
    206  * @return              New syntax tree node.
    207  */
     171/** Parse class, struct or interface member. */
    208172static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi)
    209173{
     
    247211
    248212
    249 /** Parse member function.
    250  *
    251  * @param parse         Parser object.
    252  * @param outer_csi     CSI containing this declaration or @c NULL if global.
    253  * @return              New syntax tree node.
    254  */
     213/** Parse member function. */
    255214static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi)
    256215{
     
    338297}
    339298
    340 /** Parse member variable.
    341  *
    342  * @param parse         Parser object.
    343  * @param outer_csi     CSI containing this declaration or @c NULL if global.
    344  * @return              New syntax tree node.
    345  */
     299/** Parse member variable. */
    346300static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi)
    347301{
     
    364318}
    365319
    366 /** Parse member property.
    367  *
    368  * @param parse         Parser object.
    369  * @param outer_csi     CSI containing this declaration or @c NULL if global.
    370  * @return              New syntax tree node.
    371  */
     320/** Parse member property. */
    372321static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi)
    373322{
     
    475424}
    476425
    477 /** Parse symbol attribute.
    478  *
    479  * @param parse         Parser object.
    480  * @param outer_csi     CSI containing this declaration or @c NULL if global.
    481  * @return              New syntax tree node.
    482  */
     426/** Parse symbol attribute. */
    483427static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse)
    484428{
     
    498442}
    499443
    500 /** Parse formal function argument.
    501  *
    502  * @param parse         Parser object.
    503  * @return              New syntax tree node.
    504  */
     444/** Parse formal function argument. */
    505445static stree_proc_arg_t *parse_proc_arg(parse_t *parse)
    506446{
     
    528468}
    529469
    530 /** Parse argument attribute.
    531  *
    532  * @param parse         Parser object.
    533  * @return              New syntax tree node.
    534  */
     470/** Parse argument attribute. */
    535471static stree_arg_attr_t *parse_arg_attr(parse_t *parse)
    536472{
     
    550486}
    551487
    552 /** Parse statement block.
    553  *
    554  * @param parse         Parser object.
    555  * @return              New syntax tree node.
    556  */
     488/** Parse statement block. */
    557489static stree_block_t *parse_block(parse_t *parse)
    558490{
     
    577509}
    578510
    579 /** Parse statement.
    580  *
    581  * @param parse         Parser object.
    582  * @return              New syntax tree node.
    583  */
     511/** Parse statement. */
    584512stree_stat_t *parse_stat(parse_t *parse)
    585513{
     
    648576}
    649577
    650 /** Parse variable declaration statement.
    651  *
    652  * @param parse         Parser object.
    653  * @return              New syntax tree node.
    654  */
     578/** Parse variable declaration statement. */
    655579static stree_vdecl_t *parse_vdecl(parse_t *parse)
    656580{
     
    679603}
    680604
    681 /** Parse @c if statement.
    682  *
    683  * @param parse         Parser object.
    684  * @return              New syntax tree node.
    685  */
     605/** Parse @c if statement, */
    686606static stree_if_t *parse_if(parse_t *parse)
    687607{
     
    709629}
    710630
    711 /** Parse @c while statement.
    712  *
    713  * @param parse         Parser object.
    714  */
     631/** Parse @c while statement. */
    715632static stree_while_t *parse_while(parse_t *parse)
    716633{
     
    731648}
    732649
    733 /** Parse @c for statement.
    734  *
    735  * @param parse         Parser object.
    736  * @return              New syntax tree node.
    737  */
     650/** Parse @c for statement. */
    738651static stree_for_t *parse_for(parse_t *parse)
    739652{
     
    758671}
    759672
    760 /** Parse @c raise statement.
    761  *
    762  * @param parse         Parser object.
    763  */
     673/** Parse @c raise statement. */
    764674static stree_raise_t *parse_raise(parse_t *parse)
    765675{
     
    777687}
    778688
    779 /** Parse @c return statement.
    780  *
    781  * @param parse         Parser object.
    782  * @return              New syntax tree node.
    783  */
     689/** Parse @c return statement. */
    784690static stree_return_t *parse_return(parse_t *parse)
    785691{
     
    798704}
    799705
    800 /* Parse @c with-except-finally statement.
    801  *
    802  * @param parse         Parser object.
    803  * @return              New syntax tree node.
    804  */
     706/* Parse @c with-except-finally statement. */
    805707static stree_wef_t *parse_wef(parse_t *parse)
    806708{
     
    844746}
    845747
    846 /* Parse expression statement.
    847  *
    848  * @param parse         Parser object.
    849  * @return              New syntax tree node.
    850  */
     748/* Parse expression statement. */
    851749static stree_exps_t *parse_exps(parse_t *parse)
    852750{
     
    866764}
    867765
    868 /* Parse @c except clause.
    869  *
    870  * @param parse         Parser object.
    871  * @return              New syntax tree node.
    872  */
     766/* Parse @c except clause. */
    873767static stree_except_t *parse_except(parse_t *parse)
    874768{
     
    891785}
    892786
    893 /** Parse identifier.
    894  *
    895  * @param parse         Parser object.
    896  * @return              New syntax tree node.
    897  */
     787/** Parse identifier. */
    898788stree_ident_t *parse_ident(parse_t *parse)
    899789{
     
    911801}
    912802
    913 /** Signal a parse error, start bailing out from parser.
    914  *
    915  * @param parse         Parser object.
    916  */
     803/** Signal a parse error, start bailing out from parser. */
    917804void parse_raise_error(parse_t *parse)
    918805{
     
    921808}
    922809
    923 /** Note a parse error that has been immediately recovered.
    924  *
    925  * @param parse         Parser object.
    926  */
     810/** Note a parse error that has been immediately recovered. */
    927811void parse_note_error(parse_t *parse)
    928812{
     
    930814}
    931815
    932 /** Check if we are currently bailing out of parser due to a parse error.
    933  *
    934  * @param parse         Parser object.
    935  */
     816/** Check if we are currently bailing out of parser due to a parse error. */
    936817bool_t parse_is_error(parse_t *parse)
    937818{
     
    942823 *
    943824 * Still remember that there was an error, but stop bailing out.
    944  *
    945  * @param parse         Parser object.
    946825 */
    947826void parse_recover_error(parse_t *parse)
     
    953832}
    954833
    955 /** Return current lem.
    956  *
    957  * @param parse         Parser object.
    958  * @return              Pointer to current lem. Only valid until the lexing
    959  *                      position is advanced.
    960  */
     834/** Return current lem. */
    961835lem_t *lcur(parse_t *parse)
    962836{
     
    967841}
    968842
    969 /** Return current lem lclass.
    970  *
    971  * @param parse         Parser object.
    972  * @return              Lclass of the current lem.
    973  */
     843/** Retturn current lem lclass. */
    974844lclass_t lcur_lc(parse_t *parse)
    975845{
     
    991861}
    992862
    993 /** Skip to next lem.
    994  *
    995  * @param parse         Parser object.
    996  */
     863/** Skip to next lem. */
    997864void lskip(parse_t *parse)
    998865{
     
    1003870}
    1004871
    1005 /** Verify that lclass of current lem is @a lc.
    1006  *
    1007  * If a lem of different lclass is found, a parse error is raised and
    1008  * a message is printed.
    1009  *
    1010  * @param parse         Parser object.
    1011  * @param lc            Expected lclass.
    1012  */
     872/** Verify that lclass of current lem is @a lc. */
    1013873void lcheck(parse_t *parse, lclass_t lc)
    1014874{
     
    1027887}
    1028888
    1029 /** Verify that lclass of current lem is @a lc and go to next lem.
    1030  *
    1031  * If a lem of different lclass is found, a parse error is raised and
    1032  * a message is printed.
    1033  *
    1034  * @param parse         Parser object.
    1035  * @param lc            Expected lclass.
    1036  */
     889/** Verify that lclass of current lem is @a lc and go to next lem. */
    1037890void lmatch(parse_t *parse, lclass_t lc)
    1038891{
     
    1057910}
    1058911
    1059 /** Raise and display generic parsing error.
    1060  *
    1061  * @param parse         Parser object.
    1062  */
     912/** Display generic parsing error. */
    1063913void lunexpected_error(parse_t *parse)
    1064914{
     
    1070920}
    1071921
    1072 /** Determine whether @a lclass is in follow(block).
    1073  *
    1074  * Tests whether @a lclass belongs to the follow(block) set, i.e. if it is
    1075  * lclass of a lem that can follow a block in the program.
    1076  *
    1077  * @param lclass        Lclass.
    1078  */
     922/** Basically tells us whether @a lclass is in next(block). */
    1079923bool_t terminates_block(lclass_t lclass)
    1080924{
  • uspace/app/sbi/src/rdata.c

    recb6ac32 r73060801  
    2727 */
    2828
    29 /** @file Run-time data representation.
    30  *
    31  * At run time SBI represents all data as a graph of interconnected @c var
    32  * nodes (variable nodes). Any piece of memory addressable by the program
    33  * (i.e. all variables) are stored in var nodes. However, var nodes are also
    34  * used internally to implement value items. (I.e. values in value items
    35  * have exactly the same structure as program variables).
    36  *
    37  * Unlike byte- or word-oriented memory on a real machine, var nodes provide
    38  * structured and typed storage. (This typing is dynamic, however and has
    39  * nothing to do with the static type system).
    40  *
    41  * There are several types of var nodes, one for each primitive type,
    42  * reference, delegate, array, and object. A reference var node contains
    43  * a pointer to another var node. Delegate var node points to some stree
    44  * declaration. Array and object var nodes refer to a collection of child
    45  * nodes (fields, elements).
    46  */
     29/** @file Run-time data representation. */
    4730
    4831#include <stdlib.h>
    4932#include <assert.h>
    50 #include "bigint.h"
    5133#include "mytypes.h"
    5234#include "stree.h"
     
    6850static void rdata_var_print(rdata_var_t *var);
    6951
    70 /** Allocate new data item.
    71  *
    72  * @param ic    Item class.
    73  * @return      New item.
    74  */
     52
    7553rdata_item_t *rdata_item_new(item_class_t ic)
    7654{
     
    8765}
    8866
    89 /** Allocate new address.
    90  *
    91  * @return      New address.
    92  */
    9367rdata_addr_var_t *rdata_addr_var_new(void)
    9468{
     
    10478}
    10579
    106 /** Allocate new named property address.
    107  *
    108  * @return      New named property address.
    109  */
    11080rdata_aprop_named_t *rdata_aprop_named_new(void)
    11181{
     
    12191}
    12292
    123 /** Allocate new indexed property address.
    124  *
    125  * @return      New indexed property address.
    126  */
    12793rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
    12894{
     
    138104}
    139105
    140 /** Allocate new property address.
    141  *
    142  * @param apc   Property address class.
    143  * @return      New property address.
    144  */
    145106rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
    146107{
     
    157118}
    158119
    159 /** Allocate new address.
    160  *
    161  * @param ac    Address class.
    162  * @return      New address.
    163  */
    164120rdata_address_t *rdata_address_new(address_class_t ac)
    165121{
     
    176132}
    177133
    178 /** Allocate new value.
    179  *
    180  * @return      New value.
    181  */
    182134rdata_value_t *rdata_value_new(void)
    183135{
     
    193145}
    194146
    195 /** Allocate new var node.
    196  *
    197  * @param vc    Var node class (varclass).
    198  * @return      New var node.
    199  */
    200147rdata_var_t *rdata_var_new(var_class_t vc)
    201148{
     
    212159}
    213160
    214 /** Allocate new reference.
    215  *
    216  * @return      New reference.
    217  */
    218161rdata_ref_t *rdata_ref_new(void)
    219162{
     
    229172}
    230173
    231 /** Allocate new delegate.
    232  *
    233  * @return      New delegate.
    234  */
    235174rdata_deleg_t *rdata_deleg_new(void)
    236175{
     
    246185}
    247186
    248 /** Allocate new array.
    249  *
    250  * @return      New array.
    251  */
    252187rdata_array_t *rdata_array_new(int rank)
    253188{
     
    270205}
    271206
    272 /** Allocate new object.
    273  *
    274  * @return      New object.
    275  */
    276207rdata_object_t *rdata_object_new(void)
    277208{
     
    287218}
    288219
    289 /** Allocate new integer.
    290  *
    291  * @return      New integer.
    292  */
    293220rdata_int_t *rdata_int_new(void)
    294221{
     
    304231}
    305232
    306 /** Allocate new string.
    307  *
    308  * @return      New string.
    309  */
    310233rdata_string_t *rdata_string_new(void)
    311234{
     
    321244}
    322245
    323 /** Allocate new resource.
    324  *
    325  * @return      New resource.
    326  */
    327246rdata_resource_t *rdata_resource_new(void)
    328247{
     
    338257}
    339258
    340 /** Allocate array elements.
    341  *
    342  * Allocates var nodes for elements of @a array.
    343  *
    344  * @param array         Array.
    345  */
    346259void rdata_array_alloc_element(rdata_array_t *array)
    347260{
     
    369282 * Dimension is the total number of elements in an array, in other words,
    370283 * the product of all extents.
    371  *
    372  * @param array         Array.
    373284 */
    374285static int rdata_array_get_dim(rdata_array_t *array)
     
    383294}
    384295
    385 /** Make copy of a variable.
    386  *
    387  * Creates a new var node that is an exact copy of an existing var node.
    388  * This can be thought of as a shallow copy.
    389  *
    390  * @param src           Source var node.
    391  * @param dest          Place to store pointer to new var node.
    392  */
     296/** Make copy of a variable. */
    393297void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest)
    394298{
     
    424328}
    425329
    426 /** Copy integer.
    427  *
    428  * @param src           Source integer.
    429  * @param dest          Place to store pointer to new integer.
    430  */
    431330static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
    432331{
    433332        *dest = rdata_int_new();
    434         bigint_clone(&src->value, &(*dest)->value);
    435 }
    436 
    437 /** Copy string.
    438  *
    439  * @param src           Source string.
    440  * @param dest          Place to store pointer to new string.
    441  */
     333        (*dest)->value = src->value;
     334}
     335
    442336static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest)
    443337{
     
    446340}
    447341
    448 /** Copy reference.
    449  *
    450  * @param src           Source reference.
    451  * @param dest          Place to store pointer to new reference.
    452  */
    453342static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest)
    454343{
     
    457346}
    458347
    459 /** Copy delegate.
    460  *
    461  * @param src           Source delegate.
    462  * @param dest          Place to store pointer to new delegate.
    463  */
    464348static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest)
    465349{
     
    469353}
    470354
    471 /** Copy array.
    472  *
    473  * @param src           Source array.
    474  * @param dest          Place to store pointer to new array.
    475  */
    476355static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
    477356{
     
    481360}
    482361
    483 /** Copy object.
    484  *
    485  * @param src           Source object.
    486  * @param dest          Place to store pointer to new object.
    487  */
    488362static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest)
    489363{
     
    493367}
    494368
    495 /** Copy resource.
    496  *
    497  * @param src           Source resource.
    498  * @param dest          Place to store pointer to new resource.
    499  */
    500369static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest)
    501370{
     
    506375/** Read data from a variable.
    507376 *
    508  * This copies data from the variable to a value item. Ideally any read access
    509  * to a program variable should go through this function. (Keep in mind
    510  * that although values are composed of var nodes internally, but are not
    511  * variables per se. Therefore this function is not used to read from values)
    512  *
    513  * @param var           Variable to read from (var node where it is stored).
    514  * @param ritem         Place to store pointer to new value item read from
    515  *                      the variable.
     377 * Return value stored in variable @a var.
    516378 */
    517379void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
     
    531393/** Write data to a variable.
    532394 *
    533  * This copies data to the variable from a value. Ideally any write access
    534  * to a program variable should go through this function. (Keep in mind
    535  * that even though values are composed of var nodes internally, but are not
    536  * variables per se. Therefore this function is not used to write to values)
    537  *
    538  * @param var           Variable to write to (var node where it is stored).
    539  * @param value         The value to write.
     395 * Store @a value to variable @a var.
    540396 */
    541397void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
     
    562418}
    563419
    564 /** Print data item in human-readable form.
    565  *
    566  * @param item          Item to print.
    567  */
    568420void rdata_item_print(rdata_item_t *item)
    569421{
     
    585437}
    586438
    587 /** Print address in human-readable form.
    588  *
    589  * Actually this displays contents of the var node that is being addressed.
    590  *
    591  * XXX Maybe we should really rather print the address and not the data
    592  * it is pointing to?
    593  *
    594  * @param item          Address to print.
    595  */
    596439static void rdata_address_print(rdata_address_t *address)
    597440{
     
    606449}
    607450
    608 /** Print value in human-readable form.
    609  *
    610  * @param value         Value to print.
    611  */
    612451void rdata_value_print(rdata_value_t *value)
    613452{
     
    615454}
    616455
    617 /** Print contents of var node in human-readable form.
    618  *
    619  * @param item          Var node to print.
    620  */
    621456static void rdata_var_print(rdata_var_t *var)
    622457{
    623458        switch (var->vc) {
    624459        case vc_int:
    625                 printf("int(");
    626                 bigint_print(&var->u.int_v->value);
    627                 printf(")");
     460                printf("int(%d)", var->u.int_v->value);
    628461                break;
    629462        case vc_string:
  • uspace/app/sbi/src/rdata_t.h

    recb6ac32 r73060801  
    3535#include "intmap_t.h"
    3636
    37 /** Integer variable.
    38  *
    39  * Sysel int type should be able to store arbitrarily (or at least
    40  * very) large numbers.
    41  */
    42 typedef struct {
    43         bigint_t value;
     37/** Integer variable */
     38typedef struct {
     39        /*
     40         * Note: Sysel int type should be able to store arbitrarily large
     41         * numbers. But for now we can live with limited width.
     42         */
     43        int value;
    4444} rdata_int_t;
    4545
  • uspace/app/sbi/src/run.c

    recb6ac32 r73060801  
    3232#include <stdlib.h>
    3333#include <assert.h>
    34 #include "bigint.h"
    3534#include "builtin.h"
    3635#include "debug.h"
     
    5857
    5958static bool_t run_exc_match(run_t *run, stree_except_t *except_c);
    60 static stree_csi_t *run_exc_payload_get_csi(run_t *run);
    61 
    6259static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *aprop);
    6360
     
    116113        run_proc(run, proc_ar, &res);
    117114
    118         run_exc_check_unhandled(run);
     115        /* Check for unhandled exceptions. */
     116        if (run->thread_ar->bo_mode != bm_none) {
     117                assert(run->thread_ar->bo_mode == bm_exc);
     118                printf("Error: Unhandled exception.\n");
     119                exit(1);
     120        }
    119121}
    120122
     
    300302
    301303        var->u.int_v = int_v;
    302         bigint_init(&int_v->value, 0);
     304        int_v->value = 0;
    303305
    304306        block_ar = run_get_current_block_ar(run);
     
    327329#endif
    328330        run_expr(run, if_s->cond, &rcond);
    329         if (run_is_bo(run))
    330                 return;
    331331
    332332        if (run_item_boolean_value(run, rcond) == b_true) {
     
    357357#endif
    358358        run_expr(run, while_s->cond, &rcond);
    359         if (run_is_bo(run))
    360                 return;
    361359
    362360        while (run_item_boolean_value(run, rcond) == b_true) {
    363361                run_block(run, while_s->body);
    364362                run_expr(run, while_s->cond, &rcond);
    365                 if (run_is_bo(run))
    366                         return;
    367363
    368364                if (run->thread_ar->bo_mode != bm_none)
     
    385381#endif
    386382        run_expr(run, raise_s->expr, &rexpr);
    387         if (run_is_bo(run))
    388                 return;
    389 
    390383        run_cvt_value_item(run, rexpr, &rexpr_vi);
    391384
     
    408401#endif
    409402        run_expr(run, return_s->expr, &rexpr);
    410         if (run_is_bo(run))
    411                 return;
    412 
    413403        run_cvt_value_item(run, rexpr, &rexpr_vi);
    414404
     
    487477 *
    488478 * Checks if the currently active exception in the runner object @c run
    489  * matches except clause @c except_c.
     479 * matches except clause @c except_c. Generates an error if the exception
     480 * payload has invalid type (i.e. not an object).
    490481 *
    491482 * @param run           Runner object.
     
    495486static bool_t run_exc_match(run_t *run, stree_except_t *except_c)
    496487{
    497         stree_csi_t *exc_csi;
     488        rdata_value_t *payload;
     489        rdata_var_t *payload_v;
     490        rdata_object_t *payload_o;
    498491        tdata_item_t *etype;
    499492
    500         /* Get CSI of active exception. */
    501         exc_csi = run_exc_payload_get_csi(run);
     493        payload = run->thread_ar->exc_payload;
     494        assert(payload != NULL);
     495
     496        if (payload->var->vc != vc_ref) {
     497                printf("Error: Exception payload must be an object "
     498                    "(found type %d).\n", payload->var->vc);
     499                exit(1);
     500        }
     501
     502        payload_v = payload->var->u.ref_v->vref;
     503        if (payload_v->vc != vc_object) {
     504                printf("Error: Exception payload must be an object "
     505                    "(found type %d).\n", payload_v->vc);
     506                exit(1);
     507        }
     508
     509        payload_o = payload_v->u.object_v;
     510
     511#ifdef DEBUG_RUN_TRACE
     512        printf("Active exception: '");
     513        symbol_print_fqn(payload_o->class_sym);
     514        printf("'.\n");
     515#endif
     516        assert(payload_o->class_sym != NULL);
     517        assert(payload_o->class_sym->sc == sc_csi);
    502518
    503519        /* Evaluate type expression in except clause. */
     
    505521            &etype);
    506522
    507         /* Determine if active exc. is derived from type in exc. clause. */
    508         return tdata_is_csi_derived_from_ti(exc_csi, etype);
    509 }
    510 
    511 /** Return CSI of the active exception.
    512  *
    513  * @param run           Runner object.
    514  * @return              CSI of the active exception.
    515  */
    516 static stree_csi_t *run_exc_payload_get_csi(run_t *run)
    517 {
    518         rdata_value_t *payload;
    519         rdata_var_t *payload_v;
    520         rdata_object_t *payload_o;
    521 
    522         payload = run->thread_ar->exc_payload;
    523         assert(payload != NULL);
    524 
    525         if (payload->var->vc != vc_ref) {
    526                 /* XXX Prevent this via static type checking. */
    527                 printf("Error: Exception payload must be an object "
    528                     "(found type %d).\n", payload->var->vc);
    529                 exit(1);
    530         }
    531 
    532         payload_v = payload->var->u.ref_v->vref;
    533         if (payload_v->vc != vc_object) {
    534                 /* XXX Prevent this via static type checking. */
    535                 printf("Error: Exception payload must be an object "
    536                     "(found type %d).\n", payload_v->vc);
    537                 exit(1);
    538         }
    539 
    540         payload_o = payload_v->u.object_v;
    541 
    542 #ifdef DEBUG_RUN_TRACE
    543         printf("Active exception: '");
    544         symbol_print_fqn(payload_o->class_sym);
    545         printf("'.\n");
    546 #endif
    547         assert(payload_o->class_sym != NULL);
    548         assert(payload_o->class_sym->sc == sc_csi);
    549 
    550         return payload_o->class_sym->u.csi;
    551 }
    552 
    553 
    554 /** Check for unhandled exception.
    555  *
    556  * Checks whether there is an active exception. If so, it prints an
    557  * error message and raises a run-time error.
    558  *
    559  * @param run           Runner object.
    560  */
    561 void run_exc_check_unhandled(run_t *run)
    562 {
    563         stree_csi_t *exc_csi;
    564 
    565         if (run->thread_ar->bo_mode != bm_none) {
    566                 assert(run->thread_ar->bo_mode == bm_exc);
    567 
    568                 exc_csi = run_exc_payload_get_csi(run);
    569 
    570                 printf("Error: Unhandled exception '");
    571                 symbol_print_fqn(csi_to_symbol(exc_csi));
    572                 printf("'.\n");
    573 
    574                 run_raise_error(run);
    575         }
     523        return tdata_is_csi_derived_from_ti(payload_o->class_sym->u.csi,
     524            etype);
    576525}
    577526
     
    671620
    672621                (*var)->u.int_v = int_v;
    673                 bigint_clone(&item->u.value->var->u.int_v->value,
    674                     &int_v->value);
     622                int_v->value = item->u.value->var->u.int_v->value;
    675623                break;
    676624        case vc_string:
     
    12231171
    12241172        if (addr_var->vref == NULL) {
    1225 #ifdef DEBUG_RUN_TRACE
    12261173                printf("Error: Accessing null reference.\n");
    1227 #endif
    1228                 /* Raise Error.NilReference */
    1229                 run_raise_exc(run, run->program->builtin->error_nilreference);
     1174                run_raise_error(run);
    12301175                *ritem = run_recovery_item(run);
    12311176                return;
     
    12361181#endif
    12371182        *ritem = item;
    1238 }
    1239 
    1240 /** Raise an exception of the given class.
    1241  *
    1242  * Used when the interpreter generates an exception due to a run-time
    1243  * error (not for the @c raise statement).
    1244  *
    1245  * @param run           Runner object.
    1246  * @param csi           Exception class.
    1247  */
    1248 void run_raise_exc(run_t *run, stree_csi_t *csi)
    1249 {
    1250         rdata_item_t *exc_vi;
    1251 
    1252         /* Create exception object. */
    1253         run_new_csi_inst(run, csi, &exc_vi);
    1254         assert(exc_vi->ic == ic_value);
    1255 
    1256         /* Store exception object in thread AR. */
    1257         run->thread_ar->exc_payload = exc_vi->u.value;
    1258 
    1259         /* Start exception bailout. */
    1260         run->thread_ar->bo_mode = bm_exc;
    1261 }
    1262 
    1263 /** Determine if we are bailing out. */
    1264 bool_t run_is_bo(run_t *run)
    1265 {
    1266         return run->thread_ar->bo_mode != bm_none;
    12671183}
    12681184
  • uspace/app/sbi/src/run.h

    recb6ac32 r73060801  
    3939void run_print_fun_bt(run_t *run);
    4040
    41 void run_exc_check_unhandled(run_t *run);
    4241void run_raise_error(run_t *run);
    4342rdata_item_t *run_recovery_item(run_t *run);
     
    6564void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem);
    6665
    67 void run_raise_exc(run_t *run, stree_csi_t *csi);
    68 bool_t run_is_bo(run_t *run);
    69 
    7066run_thread_ar_t *run_thread_ar_new(void);
    7167run_proc_ar_t *run_proc_ar_new(void);
  • uspace/app/sbi/src/run_expr.c

    recb6ac32 r73060801  
    3232#include <stdlib.h>
    3333#include <assert.h>
    34 #include "bigint.h"
    3534#include "debug.h"
    3635#include "intmap.h"
     
    7271
    7372static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res);
    74 static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val,
    75     rdata_item_t **res);
    76 
    7773static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res);
    7874static void run_new_array(run_t *run, stree_new_t *new_op,
     
    353349        value->var = var;
    354350        var->u.int_v = int_v;
    355         bigint_clone(&lit_int->value, &int_v->value);
     351        int_v->value = lit_int->value;
    356352
    357353        *res = item;
     
    440436#endif
    441437        run_expr(run, binop->arg1, &rarg1_i);
    442         if (run_is_bo(run)) {
    443                 *res = NULL;
    444                 return;
    445         }
    446 
    447438        run_expr(run, binop->arg2, &rarg2_i);
    448         if (run_is_bo(run)) {
    449                 *res = NULL;
    450                 return;
    451         }
    452439
    453440        switch (binop->bc) {
    454441        case bo_plus:
    455         case bo_minus:
    456         case bo_mult:
    457442        case bo_equal:
    458443        case bo_notequal:
     
    511496        rdata_int_t *int_v;
    512497
    513         bigint_t *i1, *i2;
    514         bigint_t diff;
    515         bool_t done;
    516         bool_t zf, nf;
     498        int i1, i2;
    517499
    518500        (void) run;
     
    527509        var->u.int_v = int_v;
    528510
    529         i1 = &v1->var->u.int_v->value;
    530         i2 = &v2->var->u.int_v->value;
    531 
    532         done = b_true;
     511        i1 = v1->var->u.int_v->value;
     512        i2 = v2->var->u.int_v->value;
    533513
    534514        switch (binop->bc) {
    535515        case bo_plus:
    536                 bigint_add(i1, i2, &int_v->value);
    537                 break;
    538         case bo_minus:
    539                 bigint_sub(i1, i2, &int_v->value);
    540                 break;
    541         case bo_mult:
    542                 bigint_mul(i1, i2, &int_v->value);
    543                 break;
    544         default:
    545                 done = b_false;
    546                 break;
    547         }
    548 
    549         if (done) {
    550                 *res = item;
    551                 return;
    552         }
    553 
    554         /* Relational operation. */
    555 
    556         bigint_sub(i1, i2, &diff);
    557         zf = bigint_is_zero(&diff);
    558         nf = bigint_is_negative(&diff);
     516                int_v->value = i1 + i2;
     517                break;
    559518
    560519        /* XXX We should have a real boolean type. */
    561         switch (binop->bc) {
    562520        case bo_equal:
    563                 bigint_init(&int_v->value, zf ? 1 : 0);
     521                int_v->value = (i1 == i2) ? 1 : 0;
    564522                break;
    565523        case bo_notequal:
    566                 bigint_init(&int_v->value, !zf ? 1 : 0);
     524                int_v->value = (i1 != i2) ? 1 : 0;
    567525                break;
    568526        case bo_lt:
    569                 bigint_init(&int_v->value, (!zf && nf) ? 1 : 0);
     527                int_v->value = (i1 < i2) ? 1 : 0;
    570528                break;
    571529        case bo_gt:
    572                 bigint_init(&int_v->value, (!zf && !nf) ? 1 : 0);
     530                int_v->value = (i1 > i2) ? 1 : 0;
    573531                break;
    574532        case bo_lt_equal:
    575                 bigint_init(&int_v->value, (zf || nf) ? 1 : 0);
     533                int_v->value = (i1 <= i2) ? 1 : 0;
    576534                break;
    577535        case bo_gt_equal:
    578                 bigint_init(&int_v->value, !nf ? 1 : 0);
     536                int_v->value = (i1 >= i2) ? 1 : 0;
    579537                break;
    580538        default:
     
    652610        /* XXX We should have a real boolean type. */
    653611        case bo_equal:
    654                 bigint_init(&int_v->value, (ref1 == ref2) ? 1 : 0);
     612                int_v->value = (ref1 == ref2) ? 1 : 0;
    655613                break;
    656614        case bo_notequal:
    657                 bigint_init(&int_v->value, (ref1 != ref2) ? 1 : 0);
     615                int_v->value = (ref1 != ref2) ? 1 : 0;
    658616                break;
    659617        default:
     
    670628static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res)
    671629{
    672         rdata_item_t *rarg_i;
    673         rdata_item_t *rarg_vi;
    674         rdata_value_t *val;
     630        rdata_item_t *rarg;
    675631
    676632#ifdef DEBUG_RUN_TRACE
    677633        printf("Run unary operation.\n");
    678634#endif
    679         run_expr(run, unop->arg, &rarg_i);
    680         if (run_is_bo(run)) {
    681                 *res = NULL;
    682                 return;
    683         }
    684 
    685 #ifdef DEBUG_RUN_TRACE
    686         printf("Check unop argument result.\n");
    687 #endif
    688         run_cvt_value_item(run, rarg_i, &rarg_vi);
    689 
    690         val = rarg_vi->u.value;
    691 
    692         switch (val->var->vc) {
    693         case vc_int:
    694                 run_unop_int(run, unop, val, res);
    695                 break;
    696         default:
    697                 printf("Unimplemented: Unrary operation argument of "
    698                     "type %d.\n", val->var->vc);
    699                 run_raise_error(run);
    700                 *res = NULL;
    701                 break;
    702         }
    703 }
    704 
    705 /** Evaluate unary operation on int argument. */
    706 static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val,
    707     rdata_item_t **res)
    708 {
    709         rdata_item_t *item;
    710         rdata_value_t *value;
    711         rdata_var_t *var;
    712         rdata_int_t *int_v;
    713 
    714         (void) run;
    715 
    716         item = rdata_item_new(ic_value);
    717         value = rdata_value_new();
    718         var = rdata_var_new(vc_int);
    719         int_v = rdata_int_new();
    720 
    721         item->u.value = value;
    722         value->var = var;
    723         var->u.int_v = int_v;
    724 
    725         switch (unop->uc) {
    726         case uo_plus:
    727                 bigint_clone(&val->var->u.int_v->value, &int_v->value);
    728                 break;
    729         case uo_minus:
    730                 bigint_reverse_sign(&val->var->u.int_v->value,
    731                     &int_v->value);
    732                 break;
    733         }
    734 
    735         *res = item;
    736 }
    737 
     635        run_expr(run, unop->arg, &rarg);
     636        *res = NULL;
     637}
    738638
    739639/** Evaluate @c new operation. */
     
    780680        int length;
    781681        int i;
    782         int rc;
    783         int iextent;
    784682
    785683#ifdef DEBUG_RUN_TRACE
     
    810708                /* Evaluate extent argument. */
    811709                run_expr(run, expr, &rexpr);
    812                 if (run_is_bo(run)) {
    813                         *res = NULL;
    814                         return;
    815                 }
    816 
    817710                run_cvt_value_item(run, rexpr, &rexpr_vi);
    818711                assert(rexpr_vi->ic == ic_value);
     
    825718
    826719#ifdef DEBUG_RUN_TRACE
    827                 printf("Array extent: ");
    828                 bigint_print(&rexpr_var->u.int_v->value);
    829                 printf(".\n");
    830 #endif
    831                 rc = bigint_get_value_int(&rexpr_var->u.int_v->value,
    832                     &iextent);
    833                 if (rc != EOK) {
    834                         printf("Memory allocation failed (big int used).\n");
    835                         exit(1);
    836                 }
    837 
    838                 array->extent[i] = iextent;
     720                printf("Array extent: %d.\n", rexpr_var->u.int_v->value);
     721#endif
     722                array->extent[i] = rexpr_var->u.int_v->value;
    839723                length = length * array->extent[i];
    840724
     
    854738                elem_var = rdata_var_new(vc_int);
    855739                elem_var->u.int_v = rdata_int_new();
    856                 bigint_init(&elem_var->u.int_v->value, 0);
     740                elem_var->u.int_v->value = 0;
    857741
    858742                array->element[i] = elem_var;
     
    871755    tdata_item_t *titem, rdata_item_t **res)
    872756{
     757        rdata_object_t *obj;
     758        rdata_var_t *obj_var;
     759
     760        stree_symbol_t *csi_sym;
    873761        stree_csi_t *csi;
     762        stree_csimbr_t *csimbr;
     763
     764        rdata_var_t *mbr_var;
     765
     766        list_node_t *node;
    874767
    875768#ifdef DEBUG_RUN_TRACE
    876769        printf("Create new object.\n");
    877770#endif
     771        (void) run;
    878772        (void) new_op;
    879773
     
    881775        assert(titem->tic == tic_tobject);
    882776        csi = titem->u.tobject->csi;
    883 
    884         /* Create CSI instance. */
    885         run_new_csi_inst(run, csi, res);
     777        csi_sym = csi_to_symbol(csi);
     778
     779        /* Create the object. */
     780        obj = rdata_object_new();
     781        obj->class_sym = csi_sym;
     782        intmap_init(&obj->fields);
     783
     784        obj_var = rdata_var_new(vc_object);
     785        obj_var->u.object_v = obj;
     786
     787        /* Create object fields. */
     788        node = list_first(&csi->members);
     789        while (node != NULL) {
     790                csimbr = list_node_data(node, stree_csimbr_t *);
     791                if (csimbr->cc == csimbr_var) {
     792                        /* XXX Depends on member variable type. */
     793                        mbr_var = rdata_var_new(vc_int);
     794                        mbr_var->u.int_v = rdata_int_new();
     795                        mbr_var->u.int_v->value = 0;
     796
     797                        intmap_set(&obj->fields, csimbr->u.var->name->sid,
     798                            mbr_var);
     799                }
     800
     801                node = list_next(&csi->members, node);
     802        }
     803
     804        /* Create reference to the new object. */
     805        run_reference(run, obj_var, res);
    886806}
    887807
     
    895815#endif
    896816        run_expr(run, access->arg, &rarg);
    897         if (run_is_bo(run)) {
    898                 *res = NULL;
    899                 return;
    900         }
    901 
    902817        if (rarg == NULL) {
    903818                printf("Error: Sub-expression has no value.\n");
     
    11131028#endif
    11141029        run_expr(run, call->fun, &rfun);
    1115         if (run_is_bo(run)) {
    1116                 *res = NULL;
    1117                 return;
    1118         }
    11191030
    11201031        if (run->thread_ar->bo_mode != bm_none) {
     
    11471058                arg = list_node_data(node, stree_expr_t *);
    11481059                run_expr(run, arg, &rarg_i);
    1149                 if (run_is_bo(run)) {
    1150                         *res = NULL;
    1151                         return;
    1152                 }
    1153 
    11541060                run_cvt_value_item(run, rarg_i, &rarg_vi);
    11551061
     
    11901096#endif
    11911097        run_expr(run, index->base, &rbase);
    1192         if (run_is_bo(run)) {
    1193                 *res = NULL;
    1194                 return;
    1195         }
    11961098
    11971099        vc = run_item_get_vc(run, rbase);
     
    12131115                arg = list_node_data(node, stree_expr_t *);
    12141116                run_expr(run, arg, &rarg_i);
    1215                 if (run_is_bo(run)) {
    1216                         *res = NULL;
    1217                         return;
    1218                 }
    1219 
    12201117                run_cvt_value_item(run, rarg_i, &rarg_vi);
    12211118
     
    12521149        int elem_index;
    12531150        int arg_val;
    1254         int rc;
    12551151
    12561152        rdata_item_t *ritem;
     
    12931189                }
    12941190
    1295                 rc = bigint_get_value_int(
    1296                     &arg->u.value->var->u.int_v->value,
    1297                     &arg_val);
    1298 
    1299                 if (rc != EOK || arg_val < 0 || arg_val >= array->extent[i]) {
    1300 #ifdef DEBUG_RUN_TRACE
     1191                arg_val = arg->u.value->var->u.int_v->value;
     1192
     1193                if (arg_val < 0 || arg_val >= array->extent[i]) {
    13011194                        printf("Error: Array index (value: %d) is out of range.\n",
    13021195                            arg_val);
    1303 #endif
    1304                         /* Raise Error.OutOfBounds */
    1305                         run_raise_exc(run,
    1306                             run->program->builtin->error_outofbounds);
     1196                        run_raise_error(run);
    13071197                        *res = run_recovery_item(run);
    13081198                        return;
     
    14171307        int elem_index;
    14181308        int arg_val;
    1419         int rc1, rc2;
     1309        int rc;
    14201310
    14211311        rdata_value_t *value;
     
    14321322        run_cvt_value_item(run, base, &base_vi);
    14331323        assert(base_vi->u.value->var->vc == vc_string);
    1434         string = base_vi->u.value->var->u.string_v;
     1324        string = base->u.value->var->u.string_v;
    14351325
    14361326        /*
     
    14561346                }
    14571347
    1458                 rc1 = bigint_get_value_int(
    1459                     &arg->u.value->var->u.int_v->value,
    1460                     &arg_val);
    1461 
     1348                arg_val = arg->u.value->var->u.int_v->value;
    14621349                elem_index = arg_val;
    14631350
     
    14711358        }
    14721359
    1473         if (rc1 == EOK)
    1474                 rc2 = os_str_get_char(string->value, elem_index, &cval);
    1475 
    1476         if (rc1 != EOK || rc2 != EOK) {
     1360        rc = os_str_get_char(string->value, elem_index, &cval);
     1361        if (rc != EOK) {
    14771362                printf("Error: String index (value: %d) is out of range.\n",
    14781363                    arg_val);
     
    14871372        cvar = rdata_var_new(vc_int);
    14881373        cvar->u.int_v = rdata_int_new();
    1489         bigint_init(&cvar->u.int_v->value, cval);
     1374        cvar->u.int_v->value = cval;
    14901375        value->var = cvar;
    14911376
     
    15041389#endif
    15051390        run_expr(run, assign->dest, &rdest_i);
    1506         if (run_is_bo(run)) {
    1507                 *res = NULL;
    1508                 return;
    1509         }
    1510 
    15111391        run_expr(run, assign->src, &rsrc_i);
    1512         if (run_is_bo(run)) {
    1513                 *res = NULL;
    1514                 return;
    1515         }
    15161392
    15171393        run_cvt_value_item(run, rsrc_i, &rsrc_vi);
     
    15471423#endif
    15481424        run_expr(run, as_op->arg, &rarg_i);
    1549         if (run_is_bo(run)) {
    1550                 *res = NULL;
    1551                 return;
    1552         }
    15531425
    15541426        /*
     
    15951467
    15961468        *res = rarg_vi;
    1597 }
    1598 
    1599 /** Create new CSI instance. */
    1600 void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res)
    1601 {
    1602         rdata_object_t *obj;
    1603         rdata_var_t *obj_var;
    1604 
    1605         stree_symbol_t *csi_sym;
    1606         stree_csimbr_t *csimbr;
    1607 
    1608         rdata_var_t *mbr_var;
    1609 
    1610         list_node_t *node;
    1611 
    1612         csi_sym = csi_to_symbol(csi);
    1613 
    1614 #ifdef DEBUG_RUN_TRACE
    1615         printf("Create new instance of CSI '");
    1616         symbol_print_fqn(csi_sym);
    1617         printf("'.\n");
    1618 #endif
    1619 
    1620         /* Create the object. */
    1621         obj = rdata_object_new();
    1622         obj->class_sym = csi_sym;
    1623         intmap_init(&obj->fields);
    1624 
    1625         obj_var = rdata_var_new(vc_object);
    1626         obj_var->u.object_v = obj;
    1627 
    1628         /* Create object fields. */
    1629         node = list_first(&csi->members);
    1630         while (node != NULL) {
    1631                 csimbr = list_node_data(node, stree_csimbr_t *);
    1632                 if (csimbr->cc == csimbr_var) {
    1633                         /* XXX Depends on member variable type. */
    1634                         mbr_var = rdata_var_new(vc_int);
    1635                         mbr_var->u.int_v = rdata_int_new();
    1636                         bigint_init(&mbr_var->u.int_v->value, 0);
    1637 
    1638                         intmap_set(&obj->fields, csimbr->u.var->name->sid,
    1639                             mbr_var);
    1640                 }
    1641 
    1642                 node = list_next(&csi->members, node);
    1643         }
    1644 
    1645         /* Create reference to the new object. */
    1646         run_reference(run, obj_var, res);
    16471469}
    16481470
     
    16701492        }
    16711493
    1672         return !bigint_is_zero(&var->u.int_v->value);
    1673 }
     1494        return (var->u.int_v->value != 0);
     1495}
  • uspace/app/sbi/src/run_expr.h

    recb6ac32 r73060801  
    3434void run_expr(run_t *run, stree_expr_t *expr, rdata_item_t **res);
    3535
    36 void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res);
    3736bool_t run_item_boolean_value(run_t *run, rdata_item_t *item);
    3837
  • uspace/app/sbi/src/stree.c

    recb6ac32 r73060801  
    376376}
    377377
    378 stree_unop_t *stree_unop_new(unop_class_t uc)
    379 {
    380         stree_unop_t *unop;
    381 
    382         unop = calloc(1, sizeof(stree_unop_t));
    383         if (unop == NULL) {
    384                 printf("Memory allocation failed.\n");
    385                 exit(1);
    386         }
    387 
    388         unop->uc = uc;
    389         return unop;
    390 }
    391 
    392378stree_new_t *stree_new_new(void)
    393379{
  • uspace/app/sbi/src/stree.h

    recb6ac32 r73060801  
    6262stree_assign_t *stree_assign_new(assign_class_t ac);
    6363stree_binop_t *stree_binop_new(binop_class_t bc);
    64 stree_unop_t *stree_unop_new(unop_class_t uc);
    6564stree_new_t *stree_new_new(void);
    6665stree_access_t *stree_access_new(void);
  • uspace/app/sbi/src/stree_t.h

    recb6ac32 r73060801  
    3030#define STREE_T_H_
    3131
    32 #include "bigint_t.h"
    3332#include "list_t.h"
    3433#include "builtin_t.h"
     
    5554
    5655typedef struct {
    57         bigint_t value;
     56        int value;
    5857} stree_lit_int_t;
    5958
     
    9089        bo_lt_equal,
    9190        bo_gt_equal,
    92         bo_plus,
    93         bo_minus,
    94         bo_mult
     91        bo_plus
    9592} binop_class_t;
    9693
    9794/** Unary operation class */
    9895typedef enum {
    99         uo_plus,
    100         uo_minus,
     96        uo_plus
    10197} unop_class_t;
    10298
     
    113109typedef struct {
    114110        /** Operation class */
    115         unop_class_t uc;
     111        unop_class_t oc;
    116112
    117113        /** Argument */
  • uspace/app/sbi/src/stype.c

    recb6ac32 r73060801  
    162162                    &titem);
    163163
    164                 if (titem->tic != tic_tarray && titem->tic != tic_ignore) {
     164                if (titem->tic != tic_tarray) {
    165165                        printf("Error: Packed argument is not an array.\n");
    166166                        stype_note_error(stype);
     
    487487        }
    488488
    489         if (dest->tic == tic_ignore || src->tic == tic_ignore)
     489        if (dest == NULL || src == NULL)
    490490                return expr;
    491491
     
    680680{
    681681        tdata_item_t *titem;
     682        tdata_primitive_t *tprimitive;
    682683
    683684        (void) stype;
    684685
    685         titem = tdata_item_new(tic_ignore);
     686        titem = tdata_item_new(tic_tprimitive);
     687        tprimitive = tdata_primitive_new(tpc_int);
     688
     689        titem->u.tprimitive = tprimitive;
     690
    686691        return titem;
    687692}
  • uspace/app/sbi/src/stype_expr.c

    recb6ac32 r73060801  
    6060static void stype_unop(stype_t *stype, stree_unop_t *unop,
    6161    tdata_item_t **rtitem);
    62 static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop,
    63     tdata_item_t *ta, tdata_item_t **rtitem);
    6462static void stype_new(stype_t *stype, stree_new_t *new,
    6563    tdata_item_t **rtitem);
     
    278276{
    279277        bool_t equal;
    280         tdata_item_t *titem1, *titem2;
     278        tdata_item_t *titem;
    281279
    282280#ifdef DEBUG_TYPE_TRACE
     
    286284        stype_expr(stype, binop->arg2);
    287285
    288         titem1 = binop->arg1->titem;
    289         titem2 = binop->arg2->titem;
    290 
    291         if (titem1 == NULL || titem2 == NULL) {
    292                 printf("Error: Binary operand has no value.\n");
    293                 stype_note_error(stype);
    294                 *rtitem = stype_recovery_titem(stype);
    295                 return;
    296         }
    297 
    298         if (titem1->tic == tic_ignore || titem2->tic == tic_ignore) {
    299                 *rtitem = stype_recovery_titem(stype);
    300                 return;
    301         }
    302 
    303         equal = tdata_item_equal(titem1, titem2);
     286        /* XXX This should be checked properly. */
     287        assert(binop->arg1->titem != NULL);
     288        assert(binop->arg2->titem != NULL);
     289
     290        if (binop->arg1->titem == NULL) {
     291                printf("Error First binary operand has no value.\n");
     292                stype_note_error(stype);
     293                if (binop->arg2->titem != NULL)
     294                        *rtitem = binop->arg2->titem;
     295                else
     296                        *rtitem = stype_recovery_titem(stype);
     297                return;
     298        }
     299
     300        if (binop->arg2->titem == NULL) {
     301                printf("Error: Second binary operand has no value.\n");
     302                stype_note_error(stype);
     303                *rtitem = binop->arg1->titem;
     304                return;
     305        }
     306
     307        equal = tdata_item_equal(binop->arg1->titem, binop->arg2->titem);
    304308        if (equal != b_true) {
    305309                printf("Error: Binary operation arguments "
    306310                    "have different types ('");
    307                 tdata_item_print(titem1);
     311                tdata_item_print(binop->arg1->titem);
    308312                printf("' and '");
    309                 tdata_item_print(titem2);
     313                tdata_item_print(binop->arg2->titem);
    310314                printf("').\n");
    311315                stype_note_error(stype);
    312                 *rtitem = stype_recovery_titem(stype);
    313                 return;
    314         }
    315 
    316         switch (titem1->tic) {
     316                *rtitem = binop->arg1->titem;
     317                return;
     318        }
     319
     320        titem = binop->arg1->titem;
     321
     322        switch (titem->tic) {
    317323        case tic_tprimitive:
    318                 stype_binop_tprimitive(stype, binop, titem1, titem2, rtitem);
     324                stype_binop_tprimitive(stype, binop, binop->arg1->titem,
     325                    binop->arg2->titem, rtitem);
    319326                break;
    320327        case tic_tobject:
    321                 stype_binop_tobject(stype, binop, titem1, titem2, rtitem);
     328                stype_binop_tobject(stype, binop, binop->arg1->titem,
     329                    binop->arg2->titem, rtitem);
    322330                break;
    323331        default:
    324332                printf("Error: Binary operation on value which is not of a "
    325333                    "supported type (found '");
    326                 tdata_item_print(titem1);
     334                tdata_item_print(titem);
    327335                printf("').\n");
    328336                stype_note_error(stype);
    329                 *rtitem = stype_recovery_titem(stype);
     337                *rtitem = titem;
    330338                break;
    331339        }
     
    409417    tdata_item_t **rtitem)
    410418{
    411         tdata_item_t *titem;
    412 
    413419#ifdef DEBUG_TYPE_TRACE
    414420        printf("Evaluate type of unary operation.\n");
     
    416422        stype_expr(stype, unop->arg);
    417423
    418         titem = unop->arg->titem;
    419 
    420         if (titem->tic == tic_ignore) {
    421                 *rtitem = stype_recovery_titem(stype);
    422                 return;
    423         }
    424 
    425         switch (titem->tic) {
    426         case tic_tprimitive:
    427                 stype_unop_tprimitive(stype, unop, titem, rtitem);
    428                 break;
    429         default:
    430                 printf("Error: Unary operation on value which is not of a "
    431                     "supported type (found '");
    432                 tdata_item_print(titem);
    433                 printf("').\n");
    434                 stype_note_error(stype);
    435                 *rtitem = stype_recovery_titem(stype);
    436                 break;
    437         }
    438 }
    439 
    440 /** Type a binary operation arguments of primitive type. */
    441 static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop,
    442     tdata_item_t *ta, tdata_item_t **rtitem)
    443 {
    444         tprimitive_class_t rtpc;
    445         tdata_item_t *res_ti;
    446 
    447         (void) stype;
    448         (void) unop;
    449 
    450         assert(ta->tic == tic_tprimitive);
    451 
    452         switch (ta->u.tprimitive->tpc) {
    453         case tpc_int:
    454                 rtpc = tpc_int;
    455                 break;
    456         default:
    457                 printf("Error: Unary operator applied on unsupported "
    458                     "primitive type %d.\n", ta->u.tprimitive->tpc);
    459                 stype_note_error(stype);
    460                 *rtitem = stype_recovery_titem(stype);
    461                 return;
    462         }
    463 
    464         res_ti = tdata_item_new(tic_tprimitive);
    465         res_ti->u.tprimitive = tdata_primitive_new(rtpc);
    466 
    467         *rtitem = res_ti;
     424        *rtitem = NULL;
    468425}
    469426
     
    517474                printf("Error: Using '.' operator on a function.\n");
    518475                stype_note_error(stype);
    519                 *rtitem = stype_recovery_titem(stype);
    520                 break;
    521         case tic_ignore:
    522476                *rtitem = stype_recovery_titem(stype);
    523477                break;
     
    659613        stype_expr(stype, call->fun);
    660614
    661         /* Check type item class */
    662 
    663615        fun_ti = call->fun->titem;
    664         switch (fun_ti->tic) {
    665         case tic_tfun:
    666                 /* The expected case */
    667                 break;
    668         case tic_ignore:
    669                 *rtitem = stype_recovery_titem(stype);
    670                 return;
    671         default:
    672                 printf("Error: Calling something which is not a function ");
    673                 printf("(found '");
    674                 tdata_item_print(fun_ti);
    675                 printf("').\n");
    676                 stype_note_error(stype);
    677                 *rtitem = stype_recovery_titem(stype);
    678                 return;
    679         }
    680 
     616        assert(fun_ti->tic == tic_tfun);
    681617        fun = fun_ti->u.tfun->fun;
    682618        fun_sym = fun_to_symbol(fun);
     
    798734                printf("Error: Indexing a function.\n");
    799735                stype_note_error(stype);
    800                 *rtitem = stype_recovery_titem(stype);
    801                 break;
    802         case tic_ignore:
    803736                *rtitem = stype_recovery_titem(stype);
    804737                break;
  • uspace/app/sbi/src/tdata.c

    recb6ac32 r73060801  
    148148                tdata_tfun_print(titem->u.tfun);
    149149                break;
    150         case tic_ignore:
    151                 printf("ignore");
    152                 break;
    153150        }
    154151}
  • uspace/app/sbi/src/tdata_t.h

    recb6ac32 r73060801  
    8484
    8585typedef enum {
    86         /** Primitive type item */
    8786        tic_tprimitive,
    88         /** Object type item */
    8987        tic_tobject,
    90         /** Array type item */
    9188        tic_tarray,
    92         /** Generic type item */
    9389        tic_tgeneric,
    94         /** Function type item */
    95         tic_tfun,
    96         /** Special error-recovery type item */
    97         tic_ignore
     90        tic_tfun
    9891} titem_class_t;
    9992
  • uspace/dist/src/sysel/demos/varargs.sy

    recb6ac32 r73060801  
    3333        -- with the attribute 'packed'.
    3434        --
    35         fun Print(args : string[], packed) is
     35        -- Note that we need to pass 'n' just because the array type
     36        -- does not implement the Length property yet.
     37        --
     38        fun Print(n : int; args : string[], packed) is
    3639                var i : int;
    37                 var error : int;
    3840
    39                 error = 0;
    4041                i = 0;
    41                 while error == 0 do
    42                         -- This is definitely the wrong way to determine
    43                         -- array bounds, but until a better one is
    44                         -- implemented...
    45                         do
    46                                 Builtin.WriteLine(args[i]);
    47                         except e : Error.OutOfBounds do
    48                                 error = 1;
    49                         end
    50 
     42                while i < n do
     43                        Builtin.WriteLine(args[i]);
    5144                        i = i + 1;
    5245                end
     
    5447
    5548        fun Main() is
    56                 Print("One", "Two", "Three", "Four", "Five");
     49                Print(5, "One", "Two", "Three", "Four", "Five");
    5750        end
    5851end
Note: See TracChangeset for help on using the changeset viewer.