Changes in / [1ef0fc3:2721a75] in mainline


Ignore:
Location:
uspace
Files:
6 deleted
28 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/Makefile

    r1ef0fc3 r2721a75  
    5050        src/p_type.c \
    5151        src/parse.c \
    52         src/program.c \
    5352        src/rdata.c \
    5453        src/run.c \
  • uspace/app/sbi/src/builtin/bi_fun.c

    r1ef0fc3 r2721a75  
    9999{
    100100        rdata_var_t *var;
    101         int char_val;
    102         int rc;
    103101
    104102#ifdef DEBUG_RUN_TRACE
     
    109107
    110108        switch (var->vc) {
    111         case vc_char:
    112                 rc = bigint_get_value_int(&var->u.char_v->value, &char_val);
    113                 if (rc == EOK)
    114                         printf("%lc\n", char_val);
    115                 else
    116                         printf("???\n");
    117                 break;
    118109        case vc_int:
    119110                bigint_print(&var->u.int_v->value);
  • uspace/app/sbi/src/imode.c

    r1ef0fc3 r2721a75  
    4747#include "list.h"
    4848#include "mytypes.h"
    49 #include "program.h"
    5049#include "rdata.h"
    5150#include "stree.h"
     
    9190        builtin_declare(program);
    9291
    93         /* Process the library. */
    94         if (program_lib_process(program) != EOK)
    95                 exit(1);
    96 
    9792        /* Resolve ancestry. */
    9893        ancr_module_process(program, program->module);
     
    135130                parse.error = b_false;
    136131                stype.error = b_false;
    137                 run.thread_ar->exc_payload = NULL;
    138                 run.thread_ar->bo_mode = bm_none;
    139132
    140133                input_new_interactive(&input);
  • uspace/app/sbi/src/input.c

    r1ef0fc3 r2721a75  
    4545#define INPUT_BUFFER_SIZE 256
    4646
    47 static int input_init_file(input_t *input, const char *fname);
     47static int input_init_file(input_t *input, char *fname);
    4848static void input_init_interactive(input_t *input);
    4949static void input_init_string(input_t *input, const char *str);
     
    5757 *                      ENOENT when opening file fails.
    5858 */
    59 int input_new_file(input_t **input, const char *fname)
     59int input_new_file(input_t **input, char *fname)
    6060{
    6161        *input = malloc(sizeof(input_t));
     
    104104 * @return              EOK on success, ENOENT when opening file fails.
    105105*/
    106 static int input_init_file(input_t *input, const char *fname)
     106static int input_init_file(input_t *input, char *fname)
    107107{
    108108        FILE *f;
  • uspace/app/sbi/src/input.h

    r1ef0fc3 r2721a75  
    3232#include "mytypes.h"
    3333
    34 int input_new_file(input_t **input, const char *fname);
     34int input_new_file(input_t **input, char *fname);
    3535int input_new_interactive(input_t **input);
    3636int input_new_string(input_t **input, const char *str);
  • uspace/app/sbi/src/lex.c

    r1ef0fc3 r2721a75  
    5353static bool_t is_digit(char c);
    5454static void lex_word(lex_t *lex);
    55 static void lex_char(lex_t *lex);
    5655static void lex_number(lex_t *lex);
    5756static void lex_string(lex_t *lex);
     
    7574static struct lc_name keywords[] = {
    7675        { lc_as,        "as" },
    77         { lc_bool,      "bool" },
    78         { lc_char,      "char" },
    7976        { lc_builtin,   "builtin" },
    8077        { lc_class,     "class" },
     
    8481        { lc_end,       "end" },
    8582        { lc_except,    "except" },
    86         { lc_false,     "false" },
    8783        { lc_finally,   "finally" },
    8884        { lc_for,       "for" },
     
    112108        { lc_then,      "then" },
    113109        { lc_this,      "this" },
    114         { lc_true,      "true" },
    115110        { lc_var,       "var" },
    116111        { lc_with,      "with" },
     
    343338        }
    344339
    345         if (bp[0] == '\'') {
    346                 lex_char(lex);
    347                 return b_true;
    348         }
    349 
    350340        if (is_digit(bp[0])) {
    351341                lex_number(lex);
     
    470460        lex->current.lclass = lc_ident;
    471461        lex->current.u.ident.sid = strtab_get_sid(ident_buf);
    472 }
    473 
    474 /** Lex a character literal.
    475  *
    476  * Reads in a character literal and stores it in the current lem in @a lex.
    477  *
    478  * @param lex           Lexer object.
    479  */
    480 static void lex_char(lex_t *lex)
    481 {
    482         char *bp;
    483         int idx;
    484         size_t len;
    485         int char_val;
    486 
    487         bp = lex->ibp + 1;
    488         idx = 0;
    489 
    490         while (bp[idx] != '\'') {
    491                 if (idx >= SLBUF_SIZE) {
    492                         printf("Error: Character literal too long.\n");
    493                         exit(1);
    494                 }
    495 
    496                 if (bp[idx] == '\0') {
    497                         printf("Error: Unterminated character literal.\n");
    498                         exit(1);
    499                 }
    500 
    501                 strlit_buf[idx] = bp[idx];
    502                 ++idx;
    503         }
    504 
    505         lex->ibp = bp + idx + 1;
    506 
    507         strlit_buf[idx] = '\0';
    508         len = os_str_length(strlit_buf);
    509         if (len != 1) {
    510                 printf("Character literal should contain one character, "
    511                     "but contains %u characters instead.\n", (unsigned) len);
    512                 exit(1);
    513         }
    514 
    515         os_str_get_char(strlit_buf, 0, &char_val);
    516         lex->current.lclass = lc_lit_char;
    517         bigint_init(&lex->current.u.lit_char.value, char_val);
    518462}
    519463
  • uspace/app/sbi/src/lex_t.h

    r1ef0fc3 r2721a75  
    3838
    3939        lc_ident,
    40         lc_lit_char,
    4140        lc_lit_int,
    4241        lc_lit_string,
     
    4443        /* Keywords */
    4544        lc_as,
    46         lc_bool,
    4745        lc_builtin,
    48         lc_char,
    4946        lc_class,
    5047        lc_constructor,
     
    5350        lc_end,
    5451        lc_except,
    55         lc_false,
    5652        lc_finally,
    5753        lc_for,
     
    8177        lc_then,
    8278        lc_this,
    83         lc_true,
    8479        lc_var,
    8580        lc_with,
     
    120115
    121116typedef struct {
    122         /* Character value */
    123         bigint_t value;
    124 } lem_lit_char_t;
    125 
    126 typedef struct {
    127117        /* Integer value */
    128118        bigint_t value;
     
    141131        union {
    142132                lem_ident_t ident;
    143                 lem_lit_char_t lit_char;
    144133                lem_lit_int_t lit_int;
    145134                lem_lit_string_t lit_string;
  • uspace/app/sbi/src/main.c

    r1ef0fc3 r2721a75  
    3737#include <stdlib.h>
    3838#include "ancr.h"
    39 #include "os/os.h"
    4039#include "builtin.h"
    4140#include "imode.h"
    4241#include "mytypes.h"
    43 #include "program.h"
    4442#include "strtab.h"
    4543#include "stree.h"
     
    5048#include "run.h"
    5149
    52 static void syntax_print(void);
     50void syntax_print(void);
    5351
    5452/** Main entry point.
     
    5856int main(int argc, char *argv[])
    5957{
     58        input_t *input;
     59        lex_t lex;
     60        parse_t parse;
    6061        stree_program_t *program;
    6162        stype_t stype;
     
    6364        int rc;
    6465
    65         /* Store executable file path under which we have been invoked. */
    66         os_store_ef_path(*argv);
    67 
    68         argv += 1;
    69         argc -= 1;
    70 
    71         if (argc == 0) {
     66        if (argc == 1) {
    7267                /* Enter interactive mode */
    7368                strtab_init();
     
    7671        }
    7772
    78         if (os_str_cmp(*argv, "-h") == 0) {
     73        if (argc != 2) {
    7974                syntax_print();
    80                 return 0;
     75                exit(1);
     76        }
     77
     78        rc = input_new_file(&input, argv[1]);
     79        if (rc != EOK) {
     80                printf("Failed opening source file '%s'.\n", argv[1]);
     81                exit(1);
    8182        }
    8283
     
    8889        builtin_declare(program);
    8990
    90         /* Process source files in the library. */
    91         if (program_lib_process(program) != EOK)
     91        /* Parse input file. */
     92        lex_init(&lex, input);
     93        parse_init(&parse, program, &lex);
     94        parse_module(&parse);
     95
     96        /* Check for parse errors. */
     97        if (parse.error)
    9298                return 1;
    9399
    94         /* Process all source files specified in command-line arguments. */
    95         while (argc > 0) {
    96                 rc = program_file_process(program, *argv);
    97                 if (rc != EOK)
    98                         return 1;
    99 
    100                 argv += 1;
    101                 argc -= 1;
    102         }
    103 
    104100        /* Resolve ancestry. */
    105         ancr_module_process(program, program->module);
     101        ancr_module_process(program, parse.cur_mod);
    106102
    107103        /* Type program. */
     
    126122
    127123/** Print command-line syntax help. */
    128 static void syntax_print(void)
     124void syntax_print(void)
    129125{
     126        printf("Missing or invalid arguments.\n");
    130127        printf("Syntax: sbi <source_file.sy>\n");
    131128}
  • uspace/app/sbi/src/os/helenos.c

    r1ef0fc3 r2721a75  
    3838#include "os.h"
    3939
    40 /** Path to executable file via which we have been invoked. */
    41 static char *ef_path;
    42 
    4340/*
    4441 * Using HelenOS-specific string API.
     
    7370{
    7471        return str_cmp(a, b);
    75 }
    76 
    77 /** Return number of characters in string. */
    78 size_t os_str_length(const char *str)
    79 {
    80         return str_length(str);
    8172}
    8273
     
    165156        return EOK;
    166157}
    167 
    168 /** Store the executable file path via which we were executed. */
    169 void os_store_ef_path(char *path)
    170 {
    171         ef_path = path;
    172 }
    173 
    174 /** Return path to the Sysel library
    175  *
    176  * @return New string. Caller should deallocate it using @c free().
    177  */
    178 char *os_get_lib_path(void)
    179 {
    180         return os_str_dup("/src/sysel/lib");
    181 }
  • uspace/app/sbi/src/os/os.h

    r1ef0fc3 r2721a75  
    3333int os_str_cmp(const char *a, const char *b);
    3434char *os_str_dup(const char *str);
    35 size_t os_str_length(const char *str);
    3635int os_str_get_char(const char *str, int index, int *out_char);
    3736void os_input_disp_help(void);
     
    3938int os_exec(char *const cmd[]);
    4039
    41 void os_store_ef_path(char *path);
    42 char *os_get_lib_path(void);
    4340
    4441#endif
  • uspace/app/sbi/src/os/posix.c

    r1ef0fc3 r2721a75  
    2929/** @file POSIX-specific code. */
    3030
    31 #include <libgen.h>
    3231#include <stdio.h>
    3332#include <stdlib.h>
     
    4039
    4140#include "os.h"
    42 
    43 /** Path to executable file via which we have been invoked. */
    44 static char *ef_path;
    4541
    4642/*
     
    7571{
    7672        return strcmp(a, b);
    77 }
    78 
    79 /** Return number of characters in string. */
    80 size_t os_str_length(const char *str)
    81 {
    82         return strlen(str);
    8373}
    8474
     
    156146        return EOK;
    157147}
    158 
    159 /** Store the executable file path via which we were executed. */
    160 void os_store_ef_path(char *path)
    161 {
    162         ef_path = path;
    163 }
    164 
    165 /** Return path to the Sysel library
    166  *
    167  * @return New string. Caller should deallocate it using @c free().
    168  */
    169 char *os_get_lib_path(void)
    170 {
    171         return os_str_acat(dirname(ef_path), "/lib");
    172 }
  • uspace/app/sbi/src/p_expr.c

    r1ef0fc3 r2721a75  
    5656static stree_expr_t *parse_primitive(parse_t *parse);
    5757static stree_expr_t *parse_nameref(parse_t *parse);
    58 static stree_expr_t *parse_lit_bool(parse_t *parse);
    59 static stree_expr_t *parse_lit_char(parse_t *parse);
    6058static stree_expr_t *parse_lit_int(parse_t *parse);
    6159static stree_expr_t *parse_lit_ref(parse_t *parse);
     
    496494                expr = parse_nameref(parse);
    497495                break;
    498         case lc_false:
    499         case lc_true:
    500                 expr = parse_lit_bool(parse);
    501                 break;
    502         case lc_lit_char:
    503                 expr = parse_lit_char(parse);
    504                 break;
    505496        case lc_lit_int:
    506497                expr = parse_lit_int(parse);
     
    540531}
    541532
    542 /** Parse boolean literal.
    543  *
    544  * @param parse         Parser object.
    545  */
    546 static stree_expr_t *parse_lit_bool(parse_t *parse)
    547 {
    548         stree_literal_t *literal;
    549         stree_expr_t *expr;
    550         bool_t value;
    551 
    552         switch (lcur_lc(parse)) {
    553         case lc_false: value = b_false; break;
    554         case lc_true: value = b_true; break;
    555         default: assert(b_false);
    556         }
    557 
    558         lskip(parse);
    559 
    560         literal = stree_literal_new(ltc_bool);
    561         literal->u.lit_bool.value = value;
    562 
    563         expr = stree_expr_new(ec_literal);
    564         expr->u.literal = literal;
    565 
    566         return expr;
    567 }
    568 
    569 /** Parse character literal.
    570  *
    571  * @param parse         Parser object.
    572  */
    573 static stree_expr_t *parse_lit_char(parse_t *parse)
    574 {
    575         stree_literal_t *literal;
    576         stree_expr_t *expr;
    577 
    578         lcheck(parse, lc_lit_char);
    579 
    580         literal = stree_literal_new(ltc_char);
    581         bigint_clone(&lcur(parse)->u.lit_char.value,
    582             &literal->u.lit_char.value);
    583 
    584         lskip(parse);
    585 
    586         expr = stree_expr_new(ec_literal);
    587         expr->u.literal = literal;
    588 
    589         return expr;
    590 }
    591 
    592533/** Parse integer literal.
    593534 *
  • uspace/app/sbi/src/p_type.c

    r1ef0fc3 r2721a75  
    7878static stree_texpr_t *parse_tapply(parse_t *parse)
    7979{
    80         stree_texpr_t *gtype;
    81         stree_texpr_t *aexpr;
    82         stree_texpr_t *targ;
     80        stree_texpr_t *a, *b, *tmp;
    8381        stree_tapply_t *tapply;
    8482
    85         gtype = parse_tpostfix(parse);
    86         if (lcur_lc(parse) != lc_slash)
    87                 return gtype;
    88 
    89         tapply = stree_tapply_new();
    90         tapply->gtype = gtype;
    91         list_init(&tapply->targs);
    92 
     83        a = parse_tpostfix(parse);
    9384        while (lcur_lc(parse) == lc_slash) {
    9485
     
    9788
    9889                lskip(parse);
    99                 targ = parse_tpostfix(parse);
    100 
    101                 list_append(&tapply->targs, targ);
    102         }
    103 
    104         aexpr = stree_texpr_new(tc_tapply);
    105         aexpr->u.tapply = tapply;
    106         return aexpr;
     90                b = parse_tpostfix(parse);
     91
     92                tapply = stree_tapply_new();
     93                tapply->gtype = a;
     94                tapply->targ = b;
     95
     96                tmp = stree_texpr_new(tc_tapply);
     97                tmp->u.tapply = tapply;
     98                a = tmp;
     99        }
     100
     101        return a;
    107102}
    108103
     
    229224                texpr->u.tnameref = parse_tnameref(parse);
    230225                break;
    231         case lc_bool:
    232         case lc_char:
    233226        case lc_int:
    234227        case lc_string:
     
    256249
    257250        switch (lcur_lc(parse)) {
    258         case lc_bool:
    259                 tlc = tlc_bool;
    260                 break;
    261         case lc_char:
    262                 tlc = tlc_char;
    263                 break;
    264251        case lc_int:
    265252                tlc = tlc_int;
  • uspace/app/sbi/src/parse.c

    r1ef0fc3 r2721a75  
    156156        stree_csimbr_t *csimbr;
    157157        stree_symbol_t *symbol;
    158         stree_ident_t *targ_name;
    159158
    160159        switch (dclass) {
     
    169168        csi = stree_csi_new(cc);
    170169        csi->name = parse_ident(parse);
    171 
    172         list_init(&csi->targ_names);
    173 
    174         while (lcur_lc(parse) == lc_slash) {
    175                 lskip(parse);
    176                 targ_name = parse_ident(parse);
    177                 list_append(&csi->targ_names, targ_name);
    178         }
    179170
    180171        symbol = stree_symbol_new(sc_csi);
  • uspace/app/sbi/src/rdata.c

    r1ef0fc3 r2721a75  
    5151#include "mytypes.h"
    5252#include "stree.h"
    53 #include "symbol.h"
    5453
    5554#include "rdata.h"
    5655
    57 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest);
    58 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest);
    5956static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest);
    6057static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest);
     
    290287}
    291288
    292 /** Allocate new boolean.
    293  *
    294  * @return      New boolean.
    295  */
    296 rdata_bool_t *rdata_bool_new(void)
    297 {
    298         rdata_bool_t *bool_v;
    299 
    300         bool_v = calloc(1, sizeof(rdata_bool_t));
    301         if (bool_v == NULL) {
    302                 printf("Memory allocation failed.\n");
    303                 exit(1);
    304         }
    305 
    306         return bool_v;
    307 }
    308 
    309 /** Allocate new character.
    310  *
    311  * @return      New character.
    312  */
    313 rdata_char_t *rdata_char_new(void)
    314 {
    315         rdata_char_t *char_v;
    316 
    317         char_v = calloc(1, sizeof(rdata_char_t));
    318         if (char_v == NULL) {
    319                 printf("Memory allocation failed.\n");
    320                 exit(1);
    321         }
    322 
    323         return char_v;
    324 }
    325 
    326289/** Allocate new integer.
    327290 *
     
    435398
    436399        switch (src->vc) {
    437         case vc_bool:
    438                 rdata_bool_copy(src->u.bool_v, &nvar->u.bool_v);
    439                 break;
    440         case vc_char:
    441                 rdata_char_copy(src->u.char_v, &nvar->u.char_v);
    442                 break;
    443400        case vc_int:
    444401                rdata_int_copy(src->u.int_v, &nvar->u.int_v);
     
    465422
    466423        *dest = nvar;
    467 }
    468 
    469 /** Copy boolean.
    470  *
    471  * @param src           Source boolean.
    472  * @param dest          Place to store pointer to new boolean.
    473  */
    474 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest)
    475 {
    476         *dest = rdata_bool_new();
    477         (*dest)->value = src->value;
    478 }
    479 
    480 /** Copy character.
    481  *
    482  * @param src           Source character.
    483  * @param dest          Place to store pointer to new character.
    484  */
    485 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest)
    486 {
    487         *dest = rdata_char_new();
    488         bigint_clone(&src->value, &(*dest)->value);
    489424}
    490425
     
    615550        var->vc = nvar->vc;
    616551        switch (nvar->vc) {
    617         case vc_bool: var->u.bool_v = nvar->u.bool_v; break;
    618         case vc_char: var->u.char_v = nvar->u.char_v; break;
    619552        case vc_int: var->u.int_v = nvar->u.int_v; break;
    620553        case vc_string: var->u.string_v = nvar->u.string_v; break;
     
    688621static void rdata_var_print(rdata_var_t *var)
    689622{
    690         int val;
    691 
    692623        switch (var->vc) {
    693         case vc_bool:
    694                 printf("bool(%s)", var->u.bool_v->value ? "true" : "false");
    695                 break;
    696         case vc_char:
    697                 printf("char(");
    698                 if (bigint_get_value_int(&var->u.char_v->value, &val) == EOK)
    699                         printf("'%c'", val);
    700                 else
    701                         printf("???:x%x\n", (unsigned) val);
    702                 printf(")");
    703                 break;
    704624        case vc_int:
    705625                printf("int(");
     
    711631                break;
    712632        case vc_ref:
    713                 printf("ref(");
    714                 rdata_var_print(var->u.ref_v->vref);
    715                 printf(")");
     633                printf("ref");
    716634                break;
    717635        case vc_deleg:
    718                 printf("deleg(");
    719                 if (var->u.deleg_v->obj != NULL) {
    720                         rdata_var_print(var->u.deleg_v->obj);
    721                         printf(",");
    722                 }
    723                 symbol_print_fqn(var->u.deleg_v->sym);
    724                 printf(")");
    725                 break;
    726         case vc_array:
    727                 printf("array");
     636                printf("deleg");
    728637                break;
    729638        case vc_object:
    730639                printf("object");
    731640                break;
    732         case vc_resource:
    733                 printf("resource(%p)", var->u.resource_v->data);
    734                 break;
    735         }
    736 }
     641        default:
     642                printf("print(%d)\n", var->vc);
     643                assert(b_false);
     644        }
     645}
  • uspace/app/sbi/src/rdata.h

    r1ef0fc3 r2721a75  
    4545rdata_array_t *rdata_array_new(int rank);
    4646rdata_object_t *rdata_object_new(void);
    47 rdata_bool_t *rdata_bool_new(void);
    48 rdata_char_t *rdata_char_new(void);
    4947rdata_int_t *rdata_int_new(void);
    5048rdata_string_t *rdata_string_new(void);
  • uspace/app/sbi/src/rdata_t.h

    r1ef0fc3 r2721a75  
    3535#include "intmap_t.h"
    3636
    37 /** Boolean variable. */
    38 typedef struct {
    39         bool_t value;
    40 } rdata_bool_t;
    41 
    42 /** Character variable.
    43  *
    44  * Sysel character type should be able to store arbitrarily (or at least
    45  * very) large character sets.
    46  */
    47 typedef struct {
    48         bigint_t value;
    49 } rdata_char_t;
    50 
    5137/** Integer variable.
    5238 *
     
    5743        bigint_t value;
    5844} rdata_int_t;
     45
    5946
    6047/** String variable */
     
    117104
    118105typedef enum var_class {
    119         /** Boolean */
    120         vc_bool,
    121 
    122         /** Character **/
    123         vc_char,
    124 
    125106        /** Integer */
    126107        vc_int,
     
    155136
    156137        union {
    157                 rdata_bool_t *bool_v;
    158                 rdata_char_t *char_v;
    159138                rdata_int_t *int_v;
    160139                rdata_string_t *string_v;
  • uspace/app/sbi/src/run.c

    r1ef0fc3 r2721a75  
    657657void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var)
    658658{
    659         rdata_char_t *char_v;
    660659        rdata_int_t *int_v;
    661660        rdata_string_t *string_v;
     
    667666
    668667        switch (in_var->vc) {
    669         case vc_char:
    670                 *var = rdata_var_new(vc_char);
    671                 char_v = rdata_char_new();
    672 
    673                 (*var)->u.char_v = char_v;
    674                 bigint_clone(&item->u.value->var->u.char_v->value,
    675                     &char_v->value);
    676                 break;
    677668        case vc_int:
    678669                *var = rdata_var_new(vc_int);
  • uspace/app/sbi/src/run_expr.c

    r1ef0fc3 r2721a75  
    5353static void run_literal(run_t *run, stree_literal_t *literal,
    5454    rdata_item_t **res);
    55 static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool,
    56     rdata_item_t **res);
    57 static void run_lit_char(run_t *run, stree_lit_char_t *lit_char,
    58     rdata_item_t **res);
    5955static void run_lit_int(run_t *run, stree_lit_int_t *lit_int,
    6056    rdata_item_t **res);
     
    6864
    6965static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res);
    70 static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
    71     rdata_value_t *v2, rdata_item_t **res);
    72 static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
    73     rdata_value_t *v2, rdata_item_t **res);
    7466static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
    7567    rdata_value_t *v2, rdata_item_t **res);
     
    323315        printf("Run literal.\n");
    324316#endif
     317
    325318        switch (literal->ltc) {
    326         case ltc_bool:
    327                 run_lit_bool(run, &literal->u.lit_bool, res);
    328                 break;
    329         case ltc_char:
    330                 run_lit_char(run, &literal->u.lit_char, res);
    331                 break;
    332319        case ltc_int:
    333320                run_lit_int(run, &literal->u.lit_int, res);
     
    339326                run_lit_string(run, &literal->u.lit_string, res);
    340327                break;
    341         }
    342 }
    343 
    344 /** Evaluate Boolean literal. */
    345 static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool,
    346     rdata_item_t **res)
    347 {
    348         rdata_item_t *item;
    349         rdata_value_t *value;
    350         rdata_var_t *var;
    351         rdata_bool_t *bool_v;
    352 
    353 #ifdef DEBUG_RUN_TRACE
    354         printf("Run Boolean literal.\n");
    355 #endif
    356         (void) run;
    357 
    358         item = rdata_item_new(ic_value);
    359         value = rdata_value_new();
    360         var = rdata_var_new(vc_bool);
    361         bool_v = rdata_bool_new();
    362 
    363         item->u.value = value;
    364         value->var = var;
    365         var->u.bool_v = bool_v;
    366         bool_v->value = lit_bool->value;
    367 
    368         *res = item;
    369 }
    370 
    371 /** Evaluate character literal. */
    372 static void run_lit_char(run_t *run, stree_lit_char_t *lit_char,
    373     rdata_item_t **res)
    374 {
    375         rdata_item_t *item;
    376         rdata_value_t *value;
    377         rdata_var_t *var;
    378         rdata_char_t *char_v;
    379 
    380 #ifdef DEBUG_RUN_TRACE
    381         printf("Run character literal.\n");
    382 #endif
    383         (void) run;
    384 
    385         item = rdata_item_new(ic_value);
    386         value = rdata_value_new();
    387         var = rdata_var_new(vc_char);
    388         char_v = rdata_char_new();
    389 
    390         item->u.value = value;
    391         value->var = var;
    392         var->u.char_v = char_v;
    393         bigint_clone(&lit_char->value, &char_v->value);
    394 
    395         *res = item;
     328        default:
     329                assert(b_false);
     330        }
    396331}
    397332
     
    551486
    552487        switch (v1->var->vc) {
    553         case vc_bool:
    554                 run_binop_bool(run, binop, v1, v2, res);
    555                 break;
    556         case vc_char:
    557                 run_binop_char(run, binop, v1, v2, res);
    558                 break;
    559488        case vc_int:
    560489                run_binop_int(run, binop, v1, v2, res);
     
    566495                run_binop_ref(run, binop, v1, v2, res);
    567496                break;
    568         case vc_deleg:
    569         case vc_array:
    570         case vc_object:
    571         case vc_resource:
    572                 assert(b_false);
    573         }
    574 }
    575 
    576 /** Evaluate binary operation on bool arguments. */
    577 static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
    578     rdata_value_t *v2, rdata_item_t **res)
    579 {
    580         rdata_item_t *item;
    581         rdata_value_t *value;
    582         rdata_var_t *var;
    583         rdata_bool_t *bool_v;
    584 
    585         bool_t b1, b2;
    586 
    587         (void) run;
    588 
    589         item = rdata_item_new(ic_value);
    590         value = rdata_value_new();
    591         var = rdata_var_new(vc_bool);
    592         bool_v = rdata_bool_new();
    593 
    594         item->u.value = value;
    595         value->var = var;
    596         var->u.bool_v = bool_v;
    597 
    598         b1 = v1->var->u.bool_v->value;
    599         b2 = v2->var->u.bool_v->value;
    600 
    601         switch (binop->bc) {
    602         case bo_plus:
    603         case bo_minus:
    604         case bo_mult:
    605                 assert(b_false);
    606 
    607         case bo_equal:
    608                 bool_v->value = (b1 == b2);
    609                 break;
    610         case bo_notequal:
    611                 bool_v->value = (b1 != b2);
    612                 break;
    613         case bo_lt:
    614                 bool_v->value = (b1 == b_false) && (b2 == b_true);
    615                 break;
    616         case bo_gt:
    617                 bool_v->value = (b1 == b_true) && (b2 == b_false);
    618                 break;
    619         case bo_lt_equal:
    620                 bool_v->value = (b1 == b_false) || (b2 == b_true);
    621                 break;
    622         case bo_gt_equal:
    623                 bool_v->value = (b1 == b_true) || (b2 == b_false);
    624                 break;
    625         }
    626 
    627         *res = item;
    628 }
    629 
    630 /** Evaluate binary operation on char arguments. */
    631 static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
    632     rdata_value_t *v2, rdata_item_t **res)
    633 {
    634         rdata_item_t *item;
    635         rdata_value_t *value;
    636         rdata_var_t *var;
    637         rdata_bool_t *bool_v;
    638 
    639         bigint_t *c1, *c2;
    640         bigint_t diff;
    641         bool_t zf, nf;
    642 
    643         (void) run;
    644 
    645         item = rdata_item_new(ic_value);
    646         value = rdata_value_new();
    647 
    648         item->u.value = value;
    649 
    650         c1 = &v1->var->u.char_v->value;
    651         c2 = &v2->var->u.char_v->value;
    652 
    653         var = rdata_var_new(vc_bool);
    654         bool_v = rdata_bool_new();
    655         var->u.bool_v = bool_v;
    656         value->var = var;
    657 
    658         bigint_sub(c1, c2, &diff);
    659         zf = bigint_is_zero(&diff);
    660         nf = bigint_is_negative(&diff);
    661 
    662         switch (binop->bc) {
    663         case bo_plus:
    664         case bo_minus:
    665         case bo_mult:
    666                 assert(b_false);
    667 
    668         case bo_equal:
    669                 bool_v->value = zf;
    670                 break;
    671         case bo_notequal:
    672                 bool_v->value = !zf;
    673                 break;
    674         case bo_lt:
    675                 bool_v->value = (!zf && nf);
    676                 break;
    677         case bo_gt:
    678                 bool_v->value = (!zf && !nf);
    679                 break;
    680         case bo_lt_equal:
    681                 bool_v->value = (zf || nf);
    682                 break;
    683         case bo_gt_equal:
    684                 bool_v->value = !nf;
    685                 break;
    686497        default:
    687                 assert(b_false);
    688         }
    689 
    690         *res = item;
     498                printf("Unimplemented: Binary operation arguments of "
     499                    "type %d.\n", v1->var->vc);
     500                exit(1);
     501        }
    691502}
    692503
     
    699510        rdata_var_t *var;
    700511        rdata_int_t *int_v;
    701         rdata_bool_t *bool_v;
    702512
    703513        bigint_t *i1, *i2;
     
    710520        item = rdata_item_new(ic_value);
    711521        value = rdata_value_new();
     522        var = rdata_var_new(vc_int);
     523        int_v = rdata_int_new();
    712524
    713525        item->u.value = value;
     526        value->var = var;
     527        var->u.int_v = int_v;
    714528
    715529        i1 = &v1->var->u.int_v->value;
     
    720534        switch (binop->bc) {
    721535        case bo_plus:
    722                 int_v = rdata_int_new();
    723536                bigint_add(i1, i2, &int_v->value);
    724537                break;
    725538        case bo_minus:
    726                 int_v = rdata_int_new();
    727539                bigint_sub(i1, i2, &int_v->value);
    728540                break;
    729541        case bo_mult:
    730                 int_v = rdata_int_new();
    731542                bigint_mul(i1, i2, &int_v->value);
    732543                break;
     
    737548
    738549        if (done) {
    739                 var = rdata_var_new(vc_int);
    740                 var->u.int_v = int_v;
    741                 value->var = var;
    742550                *res = item;
    743551                return;
    744552        }
    745 
    746         var = rdata_var_new(vc_bool);
    747         bool_v = rdata_bool_new();
    748         var->u.bool_v = bool_v;
    749         value->var = var;
    750553
    751554        /* Relational operation. */
     
    755558        nf = bigint_is_negative(&diff);
    756559
     560        /* XXX We should have a real boolean type. */
    757561        switch (binop->bc) {
    758562        case bo_equal:
    759                 bool_v->value = zf;
     563                bigint_init(&int_v->value, zf ? 1 : 0);
    760564                break;
    761565        case bo_notequal:
    762                 bool_v->value = !zf;
     566                bigint_init(&int_v->value, !zf ? 1 : 0);
    763567                break;
    764568        case bo_lt:
    765                 bool_v->value = (!zf && nf);
     569                bigint_init(&int_v->value, (!zf && nf) ? 1 : 0);
    766570                break;
    767571        case bo_gt:
    768                 bool_v->value = (!zf && !nf);
     572                bigint_init(&int_v->value, (!zf && !nf) ? 1 : 0);
    769573                break;
    770574        case bo_lt_equal:
    771                 bool_v->value = (zf || nf);
     575                bigint_init(&int_v->value, (zf || nf) ? 1 : 0);
    772576                break;
    773577        case bo_gt_equal:
    774                 bool_v->value = !nf;
     578                bigint_init(&int_v->value, !nf ? 1 : 0);
    775579                break;
    776580        default:
     
    827631        rdata_value_t *value;
    828632        rdata_var_t *var;
    829         rdata_bool_t *bool_v;
     633        rdata_int_t *int_v;
    830634
    831635        rdata_var_t *ref1, *ref2;
     
    835639        item = rdata_item_new(ic_value);
    836640        value = rdata_value_new();
    837         var = rdata_var_new(vc_bool);
    838         bool_v = rdata_bool_new();
     641        var = rdata_var_new(vc_int);
     642        int_v = rdata_int_new();
    839643
    840644        item->u.value = value;
    841645        value->var = var;
    842         var->u.bool_v = bool_v;
     646        var->u.int_v = int_v;
    843647
    844648        ref1 = v1->var->u.ref_v->vref;
     
    846650
    847651        switch (binop->bc) {
     652        /* XXX We should have a real boolean type. */
    848653        case bo_equal:
    849                 bool_v->value = (ref1 == ref2);
     654                bigint_init(&int_v->value, (ref1 == ref2) ? 1 : 0);
    850655                break;
    851656        case bo_notequal:
    852                 bool_v->value = (ref1 != ref2);
     657                bigint_init(&int_v->value, (ref1 != ref2) ? 1 : 0);
    853658                break;
    854659        default:
     
    1175980            access->member_name);
    1176981
    1177         /* Member existence should be ensured by static type checking. */
    1178         assert(member != NULL);
     982        if (member == NULL) {
     983                printf("Error: CSI '");
     984                symbol_print_fqn(deleg_v->sym);
     985                printf("' has no member named '%s'.\n",
     986                    strtab_get_str(access->member_name->sid));
     987                exit(1);
     988        }
    1179989
    1180990#ifdef DEBUG_RUN_TRACE
     
    16651475
    16661476        if (rc1 != EOK || rc2 != EOK) {
    1667 #ifdef DEBUG_RUN_TRACE
    16681477                printf("Error: String index (value: %d) is out of range.\n",
    16691478                    arg_val);
    1670 #endif
    1671                 /* Raise Error.OutOfBounds */
    1672                 run_raise_exc(run, run->program->builtin->error_outofbounds);
    1673                 *res = run_recovery_item(run);
    1674                 return;
     1479                exit(1);
    16751480        }
    16761481
     
    16801485        ritem->u.value = value;
    16811486
    1682         cvar = rdata_var_new(vc_char);
    1683         cvar->u.char_v = rdata_char_new();
    1684         bigint_init(&cvar->u.char_v->value, cval);
     1487        cvar = rdata_var_new(vc_int);
     1488        cvar->u.int_v = rdata_int_new();
     1489        bigint_init(&cvar->u.int_v->value, cval);
    16851490        value->var = cvar;
    16861491
     
    18461651 * Tries to interpret @a item as a boolean value. If it is not a boolean
    18471652 * value, this generates an error.
     1653 *
     1654 * XXX Currently int supplants the role of a true boolean type.
    18481655 */
    18491656bool_t run_item_boolean_value(run_t *run, rdata_item_t *item)
     
    18581665        var = vitem->u.value->var;
    18591666
    1860         assert(var->vc == vc_bool);
    1861         return var->u.bool_v->value;
    1862 }
     1667        if (var->vc != vc_int) {
     1668                printf("Error: Boolean (int) expression expected.\n");
     1669                exit(1);
     1670        }
     1671
     1672        return !bigint_is_zero(&var->u.int_v->value);
     1673}
  • uspace/app/sbi/src/run_texpr.c

    r1ef0fc3 r2721a75  
    3333#include "list.h"
    3434#include "mytypes.h"
    35 #include "strtab.h"
    3635#include "symbol.h"
    3736#include "tdata.h"
     
    4746static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
    4847    stree_tnameref_t *tnameref, tdata_item_t **res);
    49 static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,
    50     stree_tapply_t *tapply, tdata_item_t **res);
    5148
    5249void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr,
     
    6764                break;
    6865        case tc_tapply:
    69                 run_tapply(prog, ctx, texpr->u.tapply, res);
    70                 break;
     66                printf("Unimplemented: Evaluate type expression type %d.\n",
     67                    texpr->tc);
     68                exit(1);
    7169        }
    7270}
     
    8785        run_texpr(prog, ctx, taccess->arg, &targ_i);
    8886
    89         if (targ_i->tic == tic_ignore) {
    90                 *res = tdata_item_new(tic_ignore);
    91                 return;
    92         }
    93 
    9487        if (targ_i->tic != tic_tobject) {
    9588                printf("Error: Using '.' with type which is not an object.\n");
    96                 *res = tdata_item_new(tic_ignore);
    97                 return;
     89                exit(1);
    9890        }
    9991
     
    10294
    10395        sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name);
    104         if (sym == NULL) {
    105                 printf("Error: CSI '");
    106                 symbol_print_fqn(csi_to_symbol(base_csi));
    107                 printf("' has no member named '%s'.\n",
    108                     strtab_get_str(taccess->member_name->sid));
    109                 *res = tdata_item_new(tic_ignore);
    110                 return;
    111         }
     96
     97        /* Existence should have been verified in type checking phase. */
     98        assert(sym != NULL);
    11299
    113100        if (sym->sc != sc_csi) {
     
    115102                symbol_print_fqn(sym);
    116103                printf("' is not a CSI.\n");
    117                 *res = tdata_item_new(tic_ignore);
    118                 return;
     104                exit(1);
    119105        }
    120106
     
    144130        /* Evaluate base type. */
    145131        run_texpr(prog, ctx, tindex->base_type, &base_ti);
    146 
    147         if (base_ti->tic == tic_ignore) {
    148                 *res = tdata_item_new(tic_ignore);
    149                 return;
    150         }
    151132
    152133        /* Construct type item. */
     
    186167
    187168        switch (tliteral->tlc) {
    188         case tlc_bool: tpc = tpc_bool; break;
    189         case tlc_char: tpc = tpc_char; break;
    190169        case tlc_int: tpc = tpc_int; break;
    191170        case tlc_string: tpc = tpc_string; break;
     
    212191#endif
    213192        sym = symbol_lookup_in_csi(prog, ctx, tnameref->name);
    214         if (sym == NULL) {
    215                 printf("Error: Symbol '%s' not found.\n",
    216                     strtab_get_str(tnameref->name->sid));
    217                 *res = tdata_item_new(tic_ignore);
    218                 return;
    219         }
     193
     194        /* Existence should have been verified in type-checking phase. */
     195        assert(sym);
    220196
    221197        if (sym->sc != sc_csi) {
     
    223199                symbol_print_fqn(sym);
    224200                printf("' is not a CSI.\n");
    225                 *res = tdata_item_new(tic_ignore);
    226                 return;
     201                exit(1);
    227202        }
    228203
     
    237212        *res = titem;
    238213}
    239 
    240 static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,
    241     stree_tapply_t *tapply, tdata_item_t **res)
    242 {
    243         tdata_item_t *base_ti;
    244         tdata_item_t *arg_ti;
    245         tdata_item_t *titem;
    246         tdata_object_t *tobject;
    247 
    248         list_node_t *arg_n;
    249         stree_texpr_t *arg;
    250 
    251 #ifdef DEBUG_RUN_TRACE
    252         printf("Evaluating type apply operation.\n");
    253 #endif
    254         /* Construct type item. */
    255         titem = tdata_item_new(tic_tobject);
    256         tobject = tdata_object_new();
    257         titem->u.tobject = tobject;
    258 
    259         /* Evaluate base (generic) type. */
    260         run_texpr(prog, ctx, tapply->gtype, &base_ti);
    261 
    262         if (base_ti->tic != tic_tobject) {
    263                 printf("Error: Base type of generic application is not "
    264                     "a CSI.\n");
    265                 *res = tdata_item_new(tic_ignore);
    266                 return;
    267         }
    268 
    269         tobject->static_ref = b_false;
    270         tobject->csi = base_ti->u.tobject->csi;
    271         list_init(&tobject->targs);
    272 
    273         /* Evaluate type arguments. */
    274         arg_n = list_first(&tapply->targs);
    275         while (arg_n != NULL) {
    276                 arg = list_node_data(arg_n, stree_texpr_t *);
    277                 run_texpr(prog, ctx, arg, &arg_ti);
    278 
    279                 if (arg_ti->tic == tic_ignore) {
    280                         *res = tdata_item_new(tic_ignore);
    281                         return;
    282                 }
    283 
    284                 list_append(&tobject->targs, arg_ti);
    285 
    286                 arg_n = list_next(&tapply->targs, arg_n);
    287         }
    288 
    289         *res = titem;
    290 }
  • uspace/app/sbi/src/stree_t.h

    r1ef0fc3 r2721a75  
    5454} stree_self_ref_t;
    5555
    56 /** Boolean literal */
    57 typedef struct {
    58         bool_t value;
    59 } stree_lit_bool_t;
    60 
    61 /** Character literal */
    62 typedef struct {
    63         bigint_t value;
    64 } stree_lit_char_t;
    65 
    66 /** Integer literal */
    6756typedef struct {
    6857        bigint_t value;
     
    7362} stree_lit_ref_t;
    7463
    75 /** String literal */
    7664typedef struct {
    7765        char *value;
     
    7967
    8068typedef enum {
    81         ltc_bool,
    82         ltc_char,
    8369        ltc_int,
    8470        ltc_ref,
     
    9076        literal_class_t ltc;
    9177        union {
    92                 stree_lit_bool_t lit_bool;
    93                 stree_lit_char_t lit_char;
    9478                stree_lit_int_t lit_int;
    9579                stree_lit_ref_t lit_ref;
     
    230214/** Type literal class */
    231215typedef enum {
    232         tlc_bool,
    233         tlc_char,
    234216        tlc_int,
    235217        tlc_resource,
     
    257239/** Type application operation */
    258240typedef struct {
    259         /* Base type */
    260         struct stree_texpr *gtype;
    261 
    262         /** (Formal) type arguments */
    263         list_t targs; /* of stree_texpr_t */
     241        /** Arguments */
     242        struct stree_texpr *gtype, *targ;
    264243} stree_tapply_t;
    265244
     
    517496        stree_ident_t *name;
    518497
    519         /** List of type argument names */
    520         list_t targ_names; /* of stree_ident_t */
    521 
    522498        /** Symbol for this CSI */
    523499        struct stree_symbol *symbol;
  • uspace/app/sbi/src/stype.c

    r1ef0fc3 r2721a75  
    6464static void stype_wef(stype_t *stype, stree_wef_t *wef_s);
    6565
     66static tdata_item_t *stype_boolean_titem(stype_t *stype);
     67
    6668/** Type module */
    6769void stype_module(stype_t *stype, stree_module_t *module)
     
    187189static void stype_var(stype_t *stype, stree_var_t *var)
    188190{
    189         tdata_item_t *titem;
    190 
    191191        (void) stype;
    192192        (void) var;
    193 
    194         run_texpr(stype->program, stype->current_csi, var->type,
    195             &titem);
    196         if (titem->tic == tic_ignore) {
    197                 /* An error occured. */
    198                 stype_note_error(stype);
    199                 return;
    200         }
    201193}
    202194
     
    291283        stype_block_vr_t *block_vr;
    292284        stree_vdecl_t *old_vdecl;
    293         tdata_item_t *titem;
    294285
    295286#ifdef DEBUG_TYPE_TRACE
     
    306297        }
    307298
    308         run_texpr(stype->program, stype->current_csi, vdecl_s->type,
    309             &titem);
    310         if (titem->tic == tic_ignore) {
    311                 /* An error occured. */
    312                 stype_note_error(stype);
    313                 return;
    314         }
    315 
    316299        intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s);
     300
    317301}
    318302
     
    540524                        goto failure;
    541525                break;
    542         case tic_tfun:
     526        default:
    543527                printf("Error: Unimplemented: Converting '");
    544528                tdata_item_print(src);
     
    547531                printf("'.\n");
    548532                stype_note_error(stype);
    549                 break;
    550         case tic_ignore:
    551                 assert(b_false);
    552533        }
    553534
     
    566547
    567548/** Return a boolean type item */
    568 tdata_item_t *stype_boolean_titem(stype_t *stype)
     549static tdata_item_t *stype_boolean_titem(stype_t *stype)
    569550{
    570551        tdata_item_t *titem;
     
    573554        (void) stype;
    574555
     556        /* XXX Use a true boolean type */
    575557        titem = tdata_item_new(tic_tprimitive);
    576         tprimitive = tdata_primitive_new(tpc_bool);
     558        tprimitive = tdata_primitive_new(tpc_int);
    577559        titem->u.tprimitive = tprimitive;
    578560
  • uspace/app/sbi/src/stype.h

    r1ef0fc3 r2721a75  
    4141    tdata_item_t *dest);
    4242
    43 tdata_item_t *stype_boolean_titem(stype_t *stype);
    44 
    4543stree_vdecl_t *stype_local_vars_lookup(stype_t *stype, sid_t name);
    4644stree_proc_arg_t *stype_proc_args_lookup(stype_t *stype, sid_t name);
  • uspace/app/sbi/src/stype_expr.c

    r1ef0fc3 r2721a75  
    5353static void stype_binop(stype_t *stype, stree_binop_t *binop,
    5454    tdata_item_t **rtitem);
    55 
    5655static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop,
    5756    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
    58 static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,
    59     tdata_item_t **rtitem);
    60 static void stype_binop_char(stype_t *stype, stree_binop_t *binop,
    61     tdata_item_t **rtitem);
    62 static void stype_binop_int(stype_t *stype, stree_binop_t *binop,
    63     tdata_item_t **rtitem);
    64 static void stype_binop_nil(stype_t *stype, stree_binop_t *binop,
    65     tdata_item_t **rtitem);
    66 static void stype_binop_string(stype_t *stype, stree_binop_t *binop,
    67     tdata_item_t **rtitem);
    68 static void stype_binop_resource(stype_t *stype, stree_binop_t *binop,
    69     tdata_item_t **rtitem);
    70 
    7157static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
    7258    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
     
    8773static void stype_access_tarray(stype_t *stype, stree_access_t *access,
    8874    tdata_item_t *arg_ti, tdata_item_t **rtitem);
     75static void stype_access_tgeneric(stype_t *stype, stree_access_t *access,
     76    tdata_item_t *arg_ti, tdata_item_t **rtitem);
    8977
    9078static void stype_call(stype_t *stype, stree_call_t *call,
     
    9886    tdata_item_t *base_ti, tdata_item_t **rtitem);
    9987static void stype_index_tarray(stype_t *stype, stree_index_t *index,
     88    tdata_item_t *base_ti, tdata_item_t **rtitem);
     89static void stype_index_tgeneric(stype_t *stype, stree_index_t *index,
    10090    tdata_item_t *base_ti, tdata_item_t **rtitem);
    10191
     
    258248
    259249        switch (literal->ltc) {
    260         case ltc_bool: tpc = tpc_bool; break;
    261         case ltc_char: tpc = tpc_char; break;
    262250        case ltc_int: tpc = tpc_int; break;
    263251        case ltc_ref: tpc = tpc_nil; break;
     
    345333}
    346334
    347 /** Type a binary operation with arguments of primitive type. */
     335/** Type a binary operation arguments of primitive type. */
    348336static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop,
    349337    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
    350338{
     339        tprimitive_class_t rtpc;
     340        tdata_item_t *res_ti;
     341
     342        (void) stype;
     343
    351344        assert(ta->tic == tic_tprimitive);
    352345        assert(tb->tic == tic_tprimitive);
    353346
    354347        switch (ta->u.tprimitive->tpc) {
    355         case tpc_bool:
    356                 stype_binop_bool(stype, binop, rtitem);
    357                 break;
    358         case tpc_char:
    359                 stype_binop_char(stype, binop, rtitem);
    360                 break;
    361348        case tpc_int:
    362                 stype_binop_int(stype, binop, rtitem);
     349                rtpc = tpc_int;
    363350                break;
    364351        case tpc_nil:
    365                 stype_binop_nil(stype, binop, rtitem);
     352                printf("Unimplemented; Binary operation on nil.\n");
     353                stype_note_error(stype);
     354                rtpc = tpc_nil;
    366355                break;
    367356        case tpc_string:
    368                 stype_binop_string(stype, binop, rtitem);
     357                if (binop->bc != bo_plus) {
     358                        printf("Unimplemented: Binary operation(%d) "
     359                            "on strings.\n", binop->bc);
     360                        stype_note_error(stype);
     361                }
     362                rtpc = tpc_string;
    369363                break;
    370364        case tpc_resource:
    371                 stype_binop_resource(stype, binop, rtitem);
    372                 break;
    373         }
    374 }
    375 
    376 /** Type a binary operation with bool arguments. */
    377 static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,
    378     tdata_item_t **rtitem)
    379 {
    380         tprimitive_class_t rtpc;
    381         tdata_item_t *res_ti;
    382 
    383         switch (binop->bc) {
    384         case bo_equal:
    385         case bo_notequal:
    386         case bo_lt:
    387         case bo_gt:
    388         case bo_lt_equal:
    389         case bo_gt_equal:
    390                 /* Comparison -> boolean type */
    391                 rtpc = tpc_bool;
    392                 break;
    393         case bo_plus:
    394         case bo_minus:
    395         case bo_mult:
    396                 /* Arithmetic -> error */
    397                 printf("Error: Binary operation (%d) on booleans.\n",
    398                     binop->bc);
    399                 stype_note_error(stype);
    400                 *rtitem = stype_recovery_titem(stype);
    401                 return;
     365                printf("Error: Cannot apply operator to resource type.\n");
     366                stype_note_error(stype);
     367                rtpc = tpc_resource;
    402368        }
    403369
     
    408374}
    409375
    410 /** Type a binary operation with char arguments. */
    411 static void stype_binop_char(stype_t *stype, stree_binop_t *binop,
    412     tdata_item_t **rtitem)
    413 {
    414         tprimitive_class_t rtpc;
    415         tdata_item_t *res_ti;
    416 
    417         (void) stype;
    418 
    419         switch (binop->bc) {
    420         case bo_equal:
    421         case bo_notequal:
    422         case bo_lt:
    423         case bo_gt:
    424         case bo_lt_equal:
    425         case bo_gt_equal:
    426                 /* Comparison -> boolean type */
    427                 rtpc = tpc_bool;
    428                 break;
    429         case bo_plus:
    430         case bo_minus:
    431         case bo_mult:
    432                 /* Arithmetic -> error */
    433                 printf("Error: Binary operation (%d) on characters.\n",
    434                     binop->bc);
    435                 stype_note_error(stype);
    436                 rtpc = tpc_char;
    437                 break;
    438         }
    439 
    440         res_ti = tdata_item_new(tic_tprimitive);
    441         res_ti->u.tprimitive = tdata_primitive_new(rtpc);
    442 
    443         *rtitem = res_ti;
    444 }
    445 
    446 /** Type a binary operation with int arguments. */
    447 static void stype_binop_int(stype_t *stype, stree_binop_t *binop,
    448     tdata_item_t **rtitem)
    449 {
    450         tprimitive_class_t rtpc;
    451         tdata_item_t *res_ti;
    452 
    453         (void) stype;
    454 
    455         switch (binop->bc) {
    456         case bo_equal:
    457         case bo_notequal:
    458         case bo_lt:
    459         case bo_gt:
    460         case bo_lt_equal:
    461         case bo_gt_equal:
    462                 /* Comparison -> boolean type */
    463                 rtpc = tpc_bool;
    464                 break;
    465         case bo_plus:
    466         case bo_minus:
    467         case bo_mult:
    468                 /* Arithmetic -> int type */
    469                 rtpc = tpc_int;
    470                 break;
    471         }
    472 
    473         res_ti = tdata_item_new(tic_tprimitive);
    474         res_ti->u.tprimitive = tdata_primitive_new(rtpc);
    475 
    476         *rtitem = res_ti;
    477 }
    478 
    479 /** Type a binary operation with nil arguments. */
    480 static void stype_binop_nil(stype_t *stype, stree_binop_t *binop,
    481     tdata_item_t **rtitem)
    482 {
    483         (void) binop;
    484 
    485         printf("Unimplemented; Binary operation on nil.\n");
    486         stype_note_error(stype);
    487         *rtitem = stype_recovery_titem(stype);
    488 }
    489 
    490 /** Type a binary operation with string arguments. */
    491 static void stype_binop_string(stype_t *stype, stree_binop_t *binop,
    492     tdata_item_t **rtitem)
    493 {
    494         tprimitive_class_t rtpc;
    495         tdata_item_t *res_ti;
    496 
    497         if (binop->bc != bo_plus) {
    498                 printf("Unimplemented: Binary operation(%d) "
    499                     "on strings.\n", binop->bc);
    500                 stype_note_error(stype);
    501                 *rtitem = stype_recovery_titem(stype);
    502                 return;
    503         }
    504 
    505         rtpc = tpc_string;
    506 
    507         res_ti = tdata_item_new(tic_tprimitive);
    508         res_ti->u.tprimitive = tdata_primitive_new(rtpc);
    509 
    510         *rtitem = res_ti;
    511 }
    512 
    513 /** Type a binary operation with resource arguments. */
    514 static void stype_binop_resource(stype_t *stype, stree_binop_t *binop,
    515     tdata_item_t **rtitem)
    516 {
    517         tprimitive_class_t rtpc;
    518         tdata_item_t *res_ti;
    519 
    520         (void) binop;
    521 
    522         printf("Error: Cannot apply operator to resource type.\n");
    523         stype_note_error(stype);
    524         rtpc = tpc_resource;
    525 
    526         res_ti = tdata_item_new(tic_tprimitive);
    527         res_ti->u.tprimitive = tdata_primitive_new(rtpc);
    528 
    529         *rtitem = res_ti;
    530 }
    531 
    532 /** Type a binary operation with arguments of an object type. */
     376/** Type a binary operation arguments of an object type. */
    533377static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
    534378    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
     
    546390        case bo_equal:
    547391        case bo_notequal:
    548                 /* Comparing objects -> boolean type */
    549                 res_ti = stype_boolean_titem(stype);
     392                /* Comparing objects -> boolean (XXX int for now) type */
     393                res_ti = tdata_item_new(tic_tprimitive);
     394                res_ti->u.tprimitive = tdata_primitive_new(tpc_int);
    550395                break;
    551396        default:
    552397                printf("Error: Binary operation (%d) on objects.\n",
    553398                    binop->bc);
    554                 stype_note_error(stype);
    555                 *rtitem = stype_recovery_titem(stype);
     399                res_ti = NULL;
    556400                return;
    557401        }
     
    607451
    608452        switch (ta->u.tprimitive->tpc) {
    609         case tpc_bool:
    610                 rtpc = tpc_bool;
    611                 break;
    612453        case tpc_int:
    613454                rtpc = tpc_int;
     
    639480         */
    640481        run_texpr(stype->program, stype->current_csi, new_op->texpr, rtitem);
    641 
    642         if ((*rtitem)->tic == tic_ignore) {
    643                 /* An error occured when evaluating the type expression. */
    644                 stype_note_error(stype);
    645         }
    646482}
    647483
     
    674510        case tic_tarray:
    675511                stype_access_tarray(stype, access, arg_ti, rtitem);
     512                break;
     513        case tic_tgeneric:
     514                stype_access_tgeneric(stype, access, arg_ti, rtitem);
    676515                break;
    677516        case tic_tfun:
     
    727566                printf("' has no member named '%s'.\n",
    728567                    strtab_get_str(access->member_name->sid));
    729                 stype_note_error(stype);
    730568                *rtitem = stype_recovery_titem(stype);
    731569                return;
     
    777615
    778616        printf("Error: Unimplemented: Accessing array type '");
     617        tdata_item_print(arg_ti);
     618        printf("'.\n");
     619        stype_note_error(stype);
     620        *rtitem = stype_recovery_titem(stype);
     621}
     622
     623/** Type a generic access operation. */
     624static void stype_access_tgeneric(stype_t *stype, stree_access_t *access,
     625    tdata_item_t *arg_ti, tdata_item_t **rtitem)
     626{
     627        (void) stype;
     628        (void) access;
     629        (void) rtitem;
     630
     631        printf("Error: Unimplemented: Accessing generic type '");
    779632        tdata_item_print(arg_ti);
    780633        printf("'.\n");
     
    939792                stype_index_tarray(stype, index, base_ti, rtitem);
    940793                break;
     794        case tic_tgeneric:
     795                stype_index_tgeneric(stype, index, base_ti, rtitem);
     796                break;
    941797        case tic_tfun:
    942798                printf("Error: Indexing a function.\n");
     
    965821        if (tprimitive->tpc == tpc_string) {
    966822                titem = tdata_item_new(tic_tprimitive);
    967                 titem->u.tprimitive = tdata_primitive_new(tpc_char);
     823                titem->u.tprimitive = tdata_primitive_new(tpc_int);
    968824                *rtitem = titem;
    969825                return;
     
    1058914}
    1059915
     916/** Type a generic indexing operation. */
     917static void stype_index_tgeneric(stype_t *stype, stree_index_t *index,
     918    tdata_item_t *base_ti, tdata_item_t **rtitem)
     919{
     920        (void) stype;
     921        (void) index;
     922        (void) rtitem;
     923
     924        printf("Error: Unimplemented: Indexing generic type '");
     925        tdata_item_print(base_ti);
     926        printf("'.\n");
     927        stype_note_error(stype);
     928        *rtitem = stype_recovery_titem(stype);
     929}
     930
    1060931/** Type an assignment. */
    1061932static void stype_assign(stype_t *stype, stree_assign_t *assign,
  • uspace/app/sbi/src/symbol.c

    r1ef0fc3 r2721a75  
    6868                return b;
    6969        case tc_tapply:
    70                 return symbol_xlookup_in_csi(prog, scope,
    71                     texpr->u.tapply->gtype);
     70                printf("Internal error: Generic types not implemented.\n");
     71                exit(1);
    7272        default:
    7373                assert(b_false);
  • uspace/app/sbi/src/tdata.c

    r1ef0fc3 r2721a75  
    3131#include <stdlib.h>
    3232#include <assert.h>
    33 #include "list.h"
    3433#include "mytypes.h"
    3534#include "stree.h"
     
    4140static void tdata_tobject_print(tdata_object_t *tobject);
    4241static void tdata_tarray_print(tdata_array_t *tarray);
     42static void tdata_tgeneric_print(tdata_generic_t *tgeneric);
    4343static void tdata_tfun_print(tdata_fun_t *tfun);
    4444
     
    142142                tdata_tarray_print(titem->u.tarray);
    143143                break;
     144        case tic_tgeneric:
     145                tdata_tgeneric_print(titem->u.tgeneric);
     146                break;
    144147        case tic_tfun:
    145148                tdata_tfun_print(titem->u.tfun);
     
    154157{
    155158        switch (tprimitive->tpc) {
    156         case tpc_bool: printf("bool"); break;
    157         case tpc_char: printf("char"); break;
    158159        case tpc_int: printf("int"); break;
    159160        case tpc_nil: printf("nil"); break;
     
    166167{
    167168        stree_symbol_t *csi_sym;
    168         list_node_t *arg_n;
    169         tdata_item_t *arg;
    170169
    171170        csi_sym = csi_to_symbol(tobject->csi);
    172171        assert(csi_sym != NULL);
    173172        symbol_print_fqn(csi_sym);
    174 
    175         arg_n = list_first(&tobject->targs);
    176         while (arg_n != NULL) {
    177                 arg = list_node_data(arg_n, tdata_item_t *);
    178                 putchar('/');
    179                 tdata_item_print(arg);
    180                 arg_n = list_next(&tobject->targs, arg_n);
    181         }
    182173}
    183174
     
    194185}
    195186
     187static void tdata_tgeneric_print(tdata_generic_t *tgeneric)
     188{
     189        (void) tgeneric;
     190        printf("unimplemented(generic)");
     191}
     192
    196193static void tdata_tfun_print(tdata_fun_t *tfun)
    197194{
  • uspace/app/sbi/src/tdata_t.h

    r1ef0fc3 r2721a75  
    3434/** Class of primitive type. */
    3535typedef enum {
    36         /** Boolean type */
    37         tpc_bool,
    38         /** Character type */
    39         tpc_char,
    4036        /** Integer type */
    4137        tpc_int,
     
    6157        /** CSI definition */
    6258        struct stree_csi *csi;
    63 
    64         /** (Real) type arguments */
    65         list_t targs; /* of tdata_item_t */
    6659} tdata_object_t;
    6760
     
    7770        list_t extents; /* of stree_expr_t */
    7871} tdata_array_t;
     72
     73/** Generic type. */
     74typedef struct {
     75} tdata_generic_t;
    7976
    8077/** Functional type. */
     
    9390        /** Array type item */
    9491        tic_tarray,
     92        /** Generic type item */
     93        tic_tgeneric,
    9594        /** Function type item */
    9695        tic_tfun,
     
    107106                tdata_object_t *tobject;
    108107                tdata_array_t *tarray;
     108                tdata_generic_t *tgeneric;
    109109                tdata_fun_t *tfun;
    110110        } u;
  • uspace/dist/src/sysel/demos/list.sy

    r1ef0fc3 r2721a75  
    2727--
    2828
    29 -- Using the List class from the library.
     29-- Doubly-linked list implementation.
     30class List is
     31        var head : ListNode;
     32
     33        -- Initialize list.
     34        fun Init() is
     35                head = new ListNode();
     36                head.prev = head;
     37                head.next = head;
     38        end
     39
     40        -- Append new entry at the end of the list.
     41        fun Append(data : int) is
     42                var n : ListNode;
     43                var ntl : ListNode;
     44
     45                ntl = head.prev;
     46
     47                n = new ListNode();
     48                n.value = data;
     49
     50                n.prev = ntl;
     51                n.next = head;
     52                n.head = head;
     53
     54                ntl.next = n;
     55                head.prev = n;
     56        end
     57
     58        -- Return first node in the list or @c nil if there is none.
     59        prop First : ListNode is
     60                get is
     61                    return get_first();
     62                end
     63        end
     64
     65        -- Return first node in the list or @c nil if there is none.
     66        fun get_first() : ListNode is
     67                if head.next == head then
     68                        return nil;
     69                else
     70                        return head.next;
     71                end
     72        end
     73end
     74
     75class ListNode is
     76        var value : int;
     77
     78        var prev : ListNode;
     79        var next : ListNode;
     80        var head : ListNode;
     81
     82        -- Value stored in this node.
     83        prop Value : int is
     84                get is
     85                        return value;
     86                end
     87        end
     88
     89        -- Previous node in list.
     90        prop Prev : ListNode is
     91                get is
     92                        return get_prev();
     93                end
     94        end
     95
     96        -- Next node in list.
     97        prop Next : ListNode is
     98                get is
     99                        return get_next();
     100                end
     101        end
     102
     103        -- Get next node.
     104        fun get_next() : ListNode is
     105                if next != head then
     106                        return next;
     107                else
     108                        return nil;
     109                end
     110        end
     111
     112        -- Get previous node.
     113        fun get_prev() : ListNode is
     114                if prev != head then
     115                        return next;
     116                else
     117                        return nil;
     118                end
     119        end
     120
     121end
     122
    30123class ListDemo is
    31124        fun Main() is
    32125                var list : List;
    33                 var i : Int;
    34126
    35127                list = new List();
    36128                list.Init();
    37129
    38                 -- We need autoboxing or generics to get rid of this mess.
    39                 i = new Int(); i.Value = 5; list.Append(i);
    40                 i = new Int(); i.Value = 6; list.Append(i);
    41                 i = new Int(); i.Value = 7; list.Append(i);
    42                 i = new Int(); i.Value = 8; list.Append(i);
     130                list.Append(5);
     131                list.Append(6);
     132                list.Append(7);
     133                list.Append(8);
    43134
    44135                var n : ListNode;
     
    46137                n = list.First;
    47138                while n != nil do
    48                         Builtin.WriteLine((n.value as Int).Value);
     139                        Builtin.WriteLine(n.value);
    49140                        n = n.Next;
    50141                end
Note: See TracChangeset for help on using the changeset viewer.