Changeset b64eac6 in mainline


Ignore:
Timestamp:
2011-03-18T09:18:40Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
11ac272, 73751c0
Parents:
1614ce3 (diff), 306061a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Files:
3 added
43 edited
3 moved

Legend:

Unmodified
Added
Removed
  • Makefile

    r1614ce3 rb64eac6  
    4242CONFIG_HEADER = config.h
    4343
    44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check distfile dist
     44.PHONY: all precheck cscope autotool config_auto config_default config distclean clean check releasefile release
    4545
    4646all: $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER)
     
    8888        $(CONFIG) $<
    8989
    90 # Distribution files
     90# Release files
    9191
    92 distfile: all
    93         $(MAKE) -C dist distfile
     92releasefile: all
     93        $(MAKE) -C release releasefile
    9494
    95 dist:
    96         $(MAKE) -C dist dist
     95release:
     96        $(MAKE) -C release release
    9797
    9898# Cleaning
    9999
    100100distclean: clean
    101         rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc dist/HelenOS-*
     101        rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc release/HelenOS-*
    102102
    103103clean:
  • release/Makefile

    r1614ce3 rb64eac6  
    2828
    2929-include ../version
    30 -include ../Makefile.config
    31 -include ../boot/arch/$(BARCH)/Makefile.inc
    32 -include ../boot/Makefile.common
     30
     31EXPORT_DIR = /var/tmp/helenos/HelenOS-$(RELEASE)
     32SRC_ARCHIVE = HelenOS-$(RELEASE).tar.bz2
    3333
    3434PROFILES = amd64 arm32/GXemul arm32/integratorcp arm32/gta02 ia32 \
     
    3636    sparc64/serengeti sparc64/ultra
    3737
     38BZR = bzr
     39TAR = tar
     40
     41# To determine IMG_FILE
     42-include $(EXPORT_DIR)/Makefile.config
     43-include $(EXPORT_DIR)/boot/arch/$(BARCH)/Makefile.inc
     44-include $(EXPORT_DIR)/boot/Makefile.common
     45
    3846ifdef POST_OUTPUT
    39         IMGFILE = $(POST_OUTPUT)
     47        IMG_FILE = $(EXPORT_DIR)/boot/$(POST_OUTPUT)
    4048else
    41         IMGFILE = $(BOOT_OUTPUT)
     49        IMG_FILE = $(EXPORT_DIR)/boot/$(BOOT_OUTPUT)
    4250endif
    4351
    44 SUFFIX = $(suffix $(IMGFILE))
     52SUFFIX = $(suffix $(IMG_FILE))
    4553
    4654ifdef PROFILE
    47         DISTFILE = Helenos-$(shell echo $(PROFILE) | tr '/' '-')$(SUFFIX)
     55        RELEASE_FILE = HelenOS-$(RELEASE)-$(shell echo $(PROFILE) | tr '/' '-')$(SUFFIX)
    4856else
    49         DISTFILE = HelenOS-$(RELEASE)-$(PLATFORM)-$(MACHINE)-$(PROCESSOR)$(SUFFIX)
     57        RELEASE_FILE = HelenOS-$(RELEASE)-$(PLATFORM)-$(MACHINE)-$(PROCESSOR)$(SUFFIX)
    5058endif
    5159
    52 .PHONY: all clean dist distfile
     60.PHONY: all clean release releasefile export src_rel
    5361
    54 all: distfile
    55 distfile: $(DISTFILE)
     62all: releasefile
     63releasefile: $(RELEASE_FILE)
    5664
    57 $(DISTFILE): $(IMGFILE)
     65$(RELEASE_FILE): $(IMG_FILE)
    5866        cp $< $@
    5967
    60 $(IMGFILE):
    61         $(MAKE) -C ..
     68$(IMG_FILE):
     69        $(MAKE) -C $(EXPORT_DIR)
    6270
    63 dist:
     71release: src_rel
    6472        for profile in $(PROFILES); do \
    65                 $(MAKE) -C .. clean ; \
    66                 $(MAKE) -C .. PROFILE=$$profile distfile ; \
     73                $(MAKE) -C $(EXPORT_DIR) clean ; \
     74                $(MAKE) -C $(EXPORT_DIR) PROFILE=$$profile ; \
     75                $(MAKE) PROFILE=$$profile releasefile ; \
    6776        done
    6877
     78$(EXPORT_DIR) export:
     79        rm -rf $(EXPORT_DIR)
     80        mkdir -p $(EXPORT_DIR)
     81        $(BZR) export $(EXPORT_DIR)
     82
     83src_rel $(SRC_ARCHIVE): export
     84        $(TAR) -C $(shell dirname $(EXPORT_DIR)) \
     85            -cjf $(SRC_ARCHIVE) $(shell basename $(EXPORT_DIR))
     86
    6987clean:
    70         rm -f $(DISTFILE)
     88        rm -f $(RELEASE_FILE)
  • uspace/app/sbi/Makefile

    r1614ce3 rb64eac6  
    3535SOURCES = \
    3636        src/builtin/bi_boxed.c \
     37        src/builtin/bi_error.c \
    3738        src/builtin/bi_char.c \
    38         src/builtin/bi_error.c \
    39         src/builtin/bi_fun.c \
     39        src/builtin/bi_console.c \
    4040        src/builtin/bi_int.c \
     41        src/builtin/bi_task.c \
    4142        src/builtin/bi_textfile.c \
    4243        src/builtin/bi_string.c \
  • uspace/app/sbi/src/builtin.c

    r1614ce3 rb64eac6  
    4343#include "builtin/bi_error.h"
    4444#include "builtin/bi_char.h"
    45 #include "builtin/bi_fun.h"
     45#include "builtin/bi_console.h"
    4646#include "builtin/bi_int.h"
     47#include "builtin/bi_task.h"
    4748#include "builtin/bi_textfile.h"
    4849#include "builtin/bi_string.h"
     
    9394        bi_error_declare(bi);
    9495        bi_char_declare(bi);
    95         bi_fun_declare(bi);
     96        bi_console_declare(bi);
    9697        bi_int_declare(bi);
     98        bi_task_declare(bi);
    9799        bi_textfile_declare(bi);
    98100        bi_string_declare(bi);
     
    111113        bi_error_bind(bi);
    112114        bi_char_bind(bi);
    113         bi_fun_bind(bi);
     115        bi_console_bind(bi);
    114116        bi_int_bind(bi);
     117        bi_task_bind(bi);
    115118        bi_textfile_bind(bi);
    116119        bi_string_bind(bi);
  • uspace/app/sbi/src/builtin/bi_console.c

    r1614ce3 rb64eac6  
    2727 */
    2828
    29 /** @file Builtin functions. */
     29/** @file Console builtin binding. */
    3030
    3131#include <stdio.h>
     
    3636#include "../list.h"
    3737#include "../mytypes.h"
    38 #include "../os/os.h"
    3938#include "../run.h"
    4039#include "../stree.h"
     
    4241#include "../symbol.h"
    4342
    44 #include "bi_fun.h"
     43#include "bi_console.h"
    4544
    46 static void bi_fun_builtin_write(run_t *run);
    47 static void bi_fun_builtin_writeline(run_t *run);
    48 static void bi_fun_task_exec(run_t *run);
     45static void bi_console_write(run_t *run);
     46static void bi_console_writeline(run_t *run);
    4947
    50 /** Declare builtin functions.
     48/** Declare Console builtin.
    5149 *
    5250 * @param bi    Builtin object
    5351 */
    54 void bi_fun_declare(builtin_t *bi)
     52void bi_console_declare(builtin_t *bi)
    5553{
    5654        stree_modm_t *modm;
     
    6361
    6462        ident = stree_ident_new();
    65         ident->sid = strtab_get_sid("Builtin");
     63        ident->sid = strtab_get_sid("Console");
    6664
    6765        csi = stree_csi_new(csi_class);
     
    8987        fun_sym = builtin_declare_fun(csi, "WriteLine");
    9088        builtin_fun_add_arg(fun_sym, "arg");
    91 
    92         /* Declare class Task. */
    93 
    94         builtin_code_snippet(bi,
    95                 "class Task is\n"
    96                         "fun Exec(args : string[], packed), static, builtin;\n"
    97                 "end\n");
    9889}
    9990
     
    10293 * @param bi    Builtin object
    10394 */
    104 void bi_fun_bind(builtin_t *bi)
     95void bi_console_bind(builtin_t *bi)
    10596{
    106         builtin_fun_bind(bi, "Builtin", "Write", bi_fun_builtin_write);
    107         builtin_fun_bind(bi, "Builtin", "WriteLine", bi_fun_builtin_writeline);
    108         builtin_fun_bind(bi, "Task", "Exec", bi_fun_task_exec);
     97        builtin_fun_bind(bi, "Console", "Write", bi_console_write);
     98        builtin_fun_bind(bi, "Console", "WriteLine", bi_console_writeline);
    10999}
    110100
     
    113103 * @param run   Runner object
    114104 */
    115 static void bi_fun_builtin_write(run_t *run)
     105static void bi_console_write(run_t *run)
    116106{
    117107        rdata_var_t *var;
     
    120110
    121111#ifdef DEBUG_RUN_TRACE
    122         printf("Called Builtin.Write()\n");
     112        printf("Called Console.Write()\n");
    123113#endif
    124114        var = run_local_vars_lookup(run, strtab_get_sid("arg"));
     
    152142 * @param run   Runner object
    153143 */
    154 static void bi_fun_builtin_writeline(run_t *run)
     144static void bi_console_writeline(run_t *run)
    155145{
    156146#ifdef DEBUG_RUN_TRACE
    157         printf("Called Builtin.WriteLine()\n");
     147        printf("Called Console.WriteLine()\n");
    158148#endif
    159         bi_fun_builtin_write(run);
     149        bi_console_write(run);
    160150        putchar('\n');
    161151}
    162 
    163 /** Start an executable and wait for it to finish.
    164  *
    165  * @param run   Runner object
    166  */
    167 static void bi_fun_task_exec(run_t *run)
    168 {
    169         rdata_var_t *args;
    170         rdata_var_t *var;
    171         rdata_array_t *array;
    172         rdata_var_t *arg;
    173         int idx, dim;
    174         const char **cmd;
    175 
    176 #ifdef DEBUG_RUN_TRACE
    177         printf("Called Task.Exec()\n");
    178 #endif
    179         args = run_local_vars_lookup(run, strtab_get_sid("args"));
    180 
    181         assert(args);
    182         assert(args->vc == vc_ref);
    183 
    184         var = args->u.ref_v->vref;
    185         assert(var->vc == vc_array);
    186 
    187         array = var->u.array_v;
    188         assert(array->rank == 1);
    189         dim = array->extent[0];
    190 
    191         if (dim == 0) {
    192                 printf("Error: Builtin.Exec() expects at least one argument.\n");
    193                 exit(1);
    194         }
    195 
    196         cmd = calloc(dim + 1, sizeof(char *));
    197         if (cmd == NULL) {
    198                 printf("Memory allocation failed.\n");
    199                 exit(1);
    200         }
    201 
    202         for (idx = 0; idx < dim; ++idx) {
    203                 arg = array->element[idx];
    204                 if (arg->vc != vc_string) {
    205                         printf("Error: Argument to Builtin.Exec() must be "
    206                             "string (found %d).\n", arg->vc);
    207                         exit(1);
    208                 }
    209 
    210                 cmd[idx] = arg->u.string_v->value;
    211         }
    212 
    213         cmd[dim] = '\0';
    214 
    215         if (os_exec((char * const *)cmd) != EOK) {
    216                 printf("Error: Exec failed.\n");
    217                 exit(1);
    218         }
    219 }
  • uspace/app/sbi/src/builtin/bi_task.h

    r1614ce3 rb64eac6  
    2727 */
    2828
    29 #ifndef BI_FUN_H_
    30 #define BI_FUN_H_
     29#ifndef BI_TASK_H_
     30#define BI_TASK_H_
    3131
    3232#include "../mytypes.h"
    3333
    34 void bi_fun_declare(builtin_t *bi);
    35 void bi_fun_bind(builtin_t *bi);
     34void bi_task_declare(builtin_t *bi);
     35void bi_task_bind(builtin_t *bi);
    3636
    3737#endif
  • uspace/app/sbi/src/imode.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    178178                        /* Convert expression result to value item. */
    179179                        run_cvt_value_item(&run, rexpr, &rexpr_vi);
     180                        rdata_item_destroy(rexpr);
     181
     182                        /* Check for unhandled exceptions. */
     183                        run_exc_check_unhandled(&run);
     184                } else {
     185                        rexpr_vi = NULL;
     186                }
     187
     188                /*
     189                 * rexpr_vi can be NULL if either repxr was null or
     190                 * if the conversion to value item raised an exception.
     191                 */
     192                if (rexpr_vi != NULL) {
    180193                        assert(rexpr_vi->ic == ic_value);
    181194
     
    184197                        rdata_value_print(rexpr_vi->u.value);
    185198                        printf("\n");
     199
     200                        rdata_item_destroy(rexpr_vi);
    186201                }
    187202        }
     203
     204        run_proc_ar_destroy(&run, proc_ar);
    188205
    189206        /* Remove block visit record from the stack, */
  • uspace/app/sbi/src/intmap.c

    r1614ce3 rb64eac6  
    5050}
    5151
     52/** Deinitialize map.
     53 *
     54 * The map must be already empty.
     55 *
     56 * @param intmap        Map to initialize.
     57 */
     58void intmap_fini(intmap_t *intmap)
     59{
     60        list_fini(&intmap->elem);
     61}
     62
    5263/** Set value corresponding to a key.
    5364 *
     
    5667 * is removed from the map.
    5768 *
    58  * @param intmap        Map.
    59  * @param key           Key (integer).
    60  * @param value         Value (must be a pointer) or @c NULL.
     69 * @param intmap        Map
     70 * @param key           Key (integer)
     71 * @param value         Value (must be a pointer) or @c NULL
    6172 */
    6273void intmap_set(intmap_t *intmap, int key, void *value)
     
    7586                                /* Remove map element. */
    7687                                list_remove(&intmap->elem, node);
    77                                 node->data = NULL;
    78                                 free(node);
     88                                free(elem);
    7989                        }
    8090                        return;
     
    98108/** Get value corresponding to a key.
    99109 *
    100  * @param intmap        Map.
    101  * @param key           Key for which to retrieve mapping.
     110 * @param intmap        Map
     111 * @param key           Key for which to retrieve mapping
    102112 *
    103113 * @return              Value correspoding to @a key or @c NULL if no mapping
     
    121131        return NULL;
    122132}
     133
     134/** Get first element in the map.
     135 *
     136 * For iterating over the map, this returns the first element (in no
     137 * particular order).
     138 *
     139 * @param intmap        Map
     140 * @return              Map element or NULL if the map is empty
     141 */
     142map_elem_t *intmap_first(intmap_t *intmap)
     143{
     144        list_node_t *node;
     145
     146        node = list_first(&intmap->elem);
     147        if (node == NULL)
     148                return NULL;
     149
     150        return list_node_data(node, map_elem_t *);
     151}
     152
     153/** Get element key.
     154 *
     155 * Giver a map element, return the key.
     156 *
     157 * @param elem          Map element
     158 * @return              Key
     159 */
     160int intmap_elem_get_key(map_elem_t *elem)
     161{
     162        return elem->key;
     163}
     164
     165/** Get element value.
     166 *
     167 * Giver a map element, return the value.
     168 *
     169 * @param elem          Map element
     170 * @return              Value
     171 */
     172void *intmap_elem_get_value(map_elem_t *elem)
     173{
     174        return elem->value;
     175}
  • uspace/app/sbi/src/intmap.h

    r1614ce3 rb64eac6  
    3333
    3434void intmap_init(intmap_t *intmap);
     35void intmap_fini(intmap_t *intmap);
    3536void intmap_set(intmap_t *intmap, int key, void *data);
    3637void *intmap_get(intmap_t *intmap, int key);
     38map_elem_t *intmap_first(intmap_t *intmap);
     39int intmap_elem_get_key(map_elem_t *elem);
     40void *intmap_elem_get_value(map_elem_t *elem);
    3741
    3842#endif
  • uspace/app/sbi/src/lex.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4545#define TAB_WIDTH 8
    4646
     47typedef enum {
     48        cs_chr,
     49        cs_str
     50} chr_str_t;
     51
    4752static void lex_touch(lex_t *lex);
    4853static bool_t lex_read_try(lex_t *lex);
     
    5762static void lex_number(lex_t *lex);
    5863static void lex_string(lex_t *lex);
     64static void lex_char_string_core(lex_t *lex, chr_str_t cs);
    5965static int digit_value(char c);
    6066
     
    117123        { lc_string,    "string" },
    118124        { lc_struct,    "struct" },
     125        { lc_switch,    "switch" },
    119126        { lc_then,      "then" },
    120127        { lc_this,      "this" },
     
    122129        { lc_var,       "var" },
    123130        { lc_with,      "with" },
     131        { lc_when,      "when" },
    124132        { lc_while,     "while" },
    125133        { lc_yield,     "yield" },
     
    535543static void lex_char(lex_t *lex)
    536544{
    537         char *bp;
    538         int idx;
    539545        size_t len;
    540546        int char_val;
    541547
    542         bp = lex->ibp + 1;
    543         idx = 0;
    544 
    545         while (bp[idx] != '\'') {
    546                 if (idx >= SLBUF_SIZE) {
    547                         printf("Error: Character literal too long.\n");
    548                         exit(1);
    549                 }
    550 
    551                 if (bp[idx] == '\0') {
    552                         printf("Error: Unterminated character literal.\n");
    553                         exit(1);
    554                 }
    555 
    556                 strlit_buf[idx] = bp[idx];
    557                 ++idx;
    558         }
    559 
    560         lex->ibp = bp + idx + 1;
    561 
    562         strlit_buf[idx] = '\0';
     548        lex_char_string_core(lex, cs_chr);
     549
    563550        len = os_str_length(strlit_buf);
    564551        if (len != 1) {
     
    620607static void lex_string(lex_t *lex)
    621608{
    622         char *bp;
    623         int idx;
    624 
    625         bp = lex->ibp + 1;
    626         idx = 0;
    627 
    628         while (bp[idx] != '"') {
    629                 if (idx >= SLBUF_SIZE) {
    630                         printf("Error: String literal too long.\n");
    631                         exit(1);
    632                 }
    633 
    634                 if (bp[idx] == '\0') {
    635                         printf("Error: Unterminated string literal.\n");
    636                         exit(1);
    637                 }
    638 
    639                 strlit_buf[idx] = bp[idx];
    640                 ++idx;
    641         }
    642 
    643         lex->ibp = bp + idx + 1;
    644 
    645         strlit_buf[idx] = '\0';
     609        lex_char_string_core(lex, cs_str);
    646610
    647611        lex->current.lclass = lc_lit_string;
    648612        lex->current.u.lit_string.value = os_str_dup(strlit_buf);
     613}
     614
     615static void lex_char_string_core(lex_t *lex, chr_str_t cs)
     616{
     617        char *bp;
     618        int sidx, didx;
     619        char term;
     620        const char *descr, *cap_descr;
     621        char spchar;
     622
     623        /* Make compiler happy */
     624        term = '\0';
     625        descr = NULL;
     626        cap_descr = NULL;
     627
     628        switch (cs) {
     629        case cs_chr:
     630                term = '\'';
     631                descr = "character";
     632                cap_descr = "Character";
     633                break;
     634        case cs_str:
     635                term = '"';
     636                descr = "string";
     637                cap_descr = "String";
     638                break;
     639        }
     640
     641        bp = lex->ibp + 1;
     642        sidx = didx = 0;
     643
     644        while (bp[sidx] != term) {
     645                if (didx >= SLBUF_SIZE) {
     646                        printf("Error: %s literal too long.\n", cap_descr);
     647                        exit(1);
     648                }
     649
     650                if (bp[sidx] == '\0') {
     651                        printf("Error: Unterminated %s literal.\n", descr);
     652                        exit(1);
     653                }
     654
     655                if (bp[sidx] == '\\') {
     656                        switch (bp[sidx + 1]) {
     657                        case '\\':
     658                                spchar = '\\';
     659                                break;
     660                        case '\'':
     661                                spchar = '\'';
     662                                break;
     663                        case '"':
     664                                spchar = '"';
     665                                break;
     666                        case 'n':
     667                                spchar = '\n';
     668                                break;
     669                        case 't':
     670                                spchar = '\t';
     671                                break;
     672                        default:
     673                                printf("Error: Unknown character escape sequence.\n");
     674                                exit(1);
     675                        }
     676
     677                        strlit_buf[didx] = spchar;
     678                        ++didx;
     679                        sidx += 2;
     680                } else {
     681                        strlit_buf[didx] = bp[sidx];
     682                        ++sidx; ++didx;
     683                }
     684        }
     685
     686        lex->ibp = bp + sidx + 1;
     687
     688        strlit_buf[didx] = '\0';
    649689}
    650690
  • uspace/app/sbi/src/lex_t.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    8585        lc_string,
    8686        lc_struct,
     87        lc_switch,
    8788        lc_then,
    8889        lc_this,
     
    9091        lc_var,
    9192        lc_with,
     93        lc_when,
    9294        lc_while,
    9395        lc_yield,
  • uspace/app/sbi/src/list.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5757}
    5858
     59/** Deinitialize list.
     60 *
     61 * @param list  List to deinitialize.
     62 */
     63void list_fini(list_t *list)
     64{
     65        assert(list_is_empty(list));
     66
     67        list->head.prev = NULL;
     68        list->head.next = NULL;
     69}
     70
    5971/** Append data to list.
    6072 *
  • uspace/app/sbi/src/list.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434
    3535void list_init(list_t *list);
     36void list_fini(list_t *list);
    3637void list_append(list_t *list, void *data);
    3738void list_prepend(list_t *list, void *data);
  • uspace/app/sbi/src/parse.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    8282static stree_vdecl_t *parse_vdecl(parse_t *parse);
    8383static stree_if_t *parse_if(parse_t *parse);
     84static stree_switch_t *parse_switch(parse_t *parse);
    8485static stree_while_t *parse_while(parse_t *parse);
    8586static stree_for_t *parse_for(parse_t *parse);
     
    667668        stree_prop_t *prop;
    668669        stree_symbol_t *symbol;
    669         bool_t body_expected;
    670670
    671671        stree_ident_t *ident;
     
    720720        /* Parse attributes. */
    721721        parse_symbol_attrs(parse, symbol);
    722 
    723         body_expected = (outer_csi->cc != csi_interface);
    724722
    725723        lmatch(parse, lc_is);
     
    10701068        stree_vdecl_t *vdecl_s;
    10711069        stree_if_t *if_s;
     1070        stree_switch_t *switch_s;
    10721071        stree_while_t *while_s;
    10731072        stree_for_t *for_s;
     
    10921091                stat->u.if_s = if_s;
    10931092                break;
     1093        case lc_switch:
     1094                switch_s = parse_switch(parse);
     1095                stat = stree_stat_new(st_switch);
     1096                stat->u.switch_s = switch_s;
     1097                break;
    10941098        case lc_while:
    10951099                while_s = parse_while(parse);
     
    12141218        lmatch(parse, lc_end);
    12151219        return if_s;
     1220}
     1221
     1222/** Parse @c switch statement.
     1223 *
     1224 * @param parse         Parser object.
     1225 * @return              New syntax tree node.
     1226 */
     1227static stree_switch_t *parse_switch(parse_t *parse)
     1228{
     1229        stree_switch_t *switch_s;
     1230        stree_when_t *when_c;
     1231        stree_expr_t *expr;
     1232
     1233#ifdef DEBUG_PARSE_TRACE
     1234        printf("Parse 'switch' statement.\n");
     1235#endif
     1236        lmatch(parse, lc_switch);
     1237
     1238        switch_s = stree_switch_new();
     1239        list_init(&switch_s->when_clauses);
     1240
     1241        switch_s->expr = parse_expr(parse);
     1242        lmatch(parse, lc_is);
     1243
     1244        /* Parse @c when clauses. */
     1245        while (lcur_lc(parse) == lc_when) {
     1246                lskip(parse);
     1247                when_c = stree_when_new();
     1248                list_init(&when_c->exprs);
     1249                while (b_true) {
     1250                        expr = parse_expr(parse);
     1251                        list_append(&when_c->exprs, expr);
     1252                        if (lcur_lc(parse) != lc_comma)
     1253                                break;
     1254                        lskip(parse);
     1255                }
     1256
     1257                lmatch(parse, lc_do);
     1258                when_c->block = parse_block(parse);
     1259
     1260                list_append(&switch_s->when_clauses, when_c);
     1261        }
     1262
     1263        /* Parse @c else clause. */
     1264        if (lcur_lc(parse) == lc_else) {
     1265                lskip(parse);
     1266                lmatch(parse, lc_do);
     1267                switch_s->else_block = parse_block(parse);
     1268        } else {
     1269                switch_s->else_block = NULL;
     1270        }
     1271
     1272        lmatch(parse, lc_end);
     1273        return switch_s;
    12161274}
    12171275
     
    16541712        case lc_except:
    16551713        case lc_finally:
     1714        case lc_when:
    16561715                return b_true;
    16571716        default:
  • uspace/app/sbi/src/rdata.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949#include <assert.h>
    5050#include "bigint.h"
     51#include "list.h"
    5152#include "mytypes.h"
    5253#include "stree.h"
     
    6970static void rdata_symbol_copy(rdata_symbol_t *src, rdata_symbol_t **dest);
    7071
     72static void rdata_var_destroy_inner(rdata_var_t *var);
     73
     74static void rdata_bool_destroy(rdata_bool_t *bool_v);
     75static void rdata_char_destroy(rdata_char_t *char_v);
     76static void rdata_int_destroy(rdata_int_t *int_v);
     77static void rdata_string_destroy(rdata_string_t *string_v);
     78static void rdata_ref_destroy(rdata_ref_t *ref_v);
     79static void rdata_deleg_destroy(rdata_deleg_t *deleg_v);
     80static void rdata_enum_destroy(rdata_enum_t *enum_v);
     81static void rdata_array_destroy(rdata_array_t *array_v);
     82static void rdata_object_destroy(rdata_object_t *object_v);
     83static void rdata_resource_destroy(rdata_resource_t *resource_v);
     84static void rdata_symbol_destroy(rdata_symbol_t *symbol_v);
     85
    7186static int rdata_array_get_dim(rdata_array_t *array);
     87static void rdata_var_copy_to(rdata_var_t *src, rdata_var_t *dest);
    7288
    7389static void rdata_address_print(rdata_address_t *address);
     
    414430/** Allocate array elements.
    415431 *
    416  * Allocates var nodes for elements of @a array.
     432 * Allocates element array of @a array.
    417433 *
    418434 * @param array         Array.
     
    420436void rdata_array_alloc_element(rdata_array_t *array)
    421437{
    422         int dim, idx;
     438        int dim;
    423439
    424440        dim = rdata_array_get_dim(array);
     
    428444                printf("Memory allocation failed.\n");
    429445                exit(1);
    430         }
    431 
    432         for (idx = 0; idx < dim; ++idx) {
    433                 array->element[idx] = calloc(1, sizeof(rdata_var_t));
    434                 if (array->element[idx] == NULL) {
    435                         printf("Memory allocation failed.\n");
    436                         exit(1);
    437                 }
    438446        }
    439447}
     
    457465}
    458466
     467/** Deallocate item.
     468 *
     469 * @param item  Item node
     470 */
     471void rdata_item_delete(rdata_item_t *item)
     472{
     473        assert(item != NULL);
     474        free(item);
     475}
     476
     477/** Deallocate variable address.
     478 *
     479 * @param addr_var      Variable address node
     480 */
     481void rdata_addr_var_delete(rdata_addr_var_t *addr_var)
     482{
     483        assert(addr_var != NULL);
     484        free(addr_var);
     485}
     486
     487/** Deallocate property address.
     488 *
     489 * @param addr_prop     Variable address node
     490 */
     491void rdata_addr_prop_delete(rdata_addr_prop_t *addr_prop)
     492{
     493        assert(addr_prop != NULL);
     494        free(addr_prop);
     495}
     496
     497/** Deallocate named property address.
     498 *
     499 * @param aprop_named   Variable address node
     500 */
     501void rdata_aprop_named_delete(rdata_aprop_named_t *aprop_named)
     502{
     503        assert(aprop_named != NULL);
     504        free(aprop_named);
     505}
     506
     507/** Deallocate indexed property address.
     508 *
     509 * @param aprop_indexed Variable address node
     510 */
     511void rdata_aprop_indexed_delete(rdata_aprop_indexed_t *aprop_indexed)
     512{
     513        assert(aprop_indexed != NULL);
     514        free(aprop_indexed);
     515}
     516
     517/** Deallocate address.
     518 *
     519 * @param address       Address node
     520 */
     521void rdata_address_delete(rdata_address_t *address)
     522{
     523        assert(address != NULL);
     524        free(address);
     525}
     526
     527/** Deallocate value.
     528 *
     529 * @param value         Value node
     530 */
     531void rdata_value_delete(rdata_value_t *value)
     532{
     533        assert(value != NULL);
     534        free(value);
     535}
     536
     537/** Deallocate var node.
     538 *
     539 * @param var   Var node
     540 */
     541void rdata_var_delete(rdata_var_t *var)
     542{
     543        assert(var != NULL);
     544        free(var);
     545}
     546
     547/** Deallocate boolean.
     548 *
     549 * @param bool_v                Boolean
     550 */
     551void rdata_bool_delete(rdata_bool_t *bool_v)
     552{
     553        assert(bool_v != NULL);
     554        free(bool_v);
     555}
     556
     557/** Deallocate character.
     558 *
     559 * @param char_v        Character
     560 */
     561void rdata_char_delete(rdata_char_t *char_v)
     562{
     563        assert(char_v != NULL);
     564        free(char_v);
     565}
     566
     567/** Deallocate integer.
     568 *
     569 * @param int_v         Integer
     570 */
     571void rdata_int_delete(rdata_int_t *int_v)
     572{
     573        assert(int_v != NULL);
     574        free(int_v);
     575}
     576
     577/** Deallocate string.
     578 *
     579 * @param string_v      String
     580 */
     581void rdata_string_delete(rdata_string_t *string_v)
     582{
     583        assert(string_v != NULL);
     584        free(string_v);
     585}
     586
     587/** Deallocate reference.
     588 *
     589 * @param ref_v         Reference
     590 */
     591void rdata_ref_delete(rdata_ref_t *ref_v)
     592{
     593        assert(ref_v != NULL);
     594        free(ref_v);
     595}
     596
     597/** Deallocate delegate.
     598 *
     599 * @param deleg_v               Reference
     600 */
     601void rdata_deleg_delete(rdata_deleg_t *deleg_v)
     602{
     603        assert(deleg_v != NULL);
     604        free(deleg_v);
     605}
     606
     607/** Deallocate enum.
     608 *
     609 * @param enum_v                Reference
     610 */
     611void rdata_enum_delete(rdata_enum_t *enum_v)
     612{
     613        assert(enum_v != NULL);
     614        free(enum_v);
     615}
     616
     617/** Deallocate array.
     618 *
     619 * @param array_v               Array
     620 */
     621void rdata_array_delete(rdata_array_t *array_v)
     622{
     623        assert(array_v != NULL);
     624        free(array_v);
     625}
     626
     627/** Deallocate object.
     628 *
     629 * @param object_v              Object
     630 */
     631void rdata_object_delete(rdata_object_t *object_v)
     632{
     633        assert(object_v != NULL);
     634        free(object_v);
     635}
     636
     637/** Deallocate resource.
     638 *
     639 * @param resource_v            Resource
     640 */
     641void rdata_resource_delete(rdata_resource_t *resource_v)
     642{
     643        assert(resource_v != NULL);
     644        free(resource_v);
     645}
     646
     647/** Deallocate symbol.
     648 *
     649 * @param symbol_v              Symbol
     650 */
     651void rdata_symbol_delete(rdata_symbol_t *symbol_v)
     652{
     653        assert(symbol_v != NULL);
     654        free(symbol_v);
     655}
     656
     657/** Copy value.
     658 *
     659 * @param src           Input value
     660 * @param dest          Place to store pointer to new value
     661 */
     662void rdata_value_copy(rdata_value_t *src, rdata_value_t **dest)
     663{
     664        assert(src != NULL);
     665
     666        *dest = rdata_value_new();
     667        rdata_var_copy(src->var, &(*dest)->var);
     668}
     669
    459670/** Make copy of a variable.
    460671 *
     
    470681
    471682        nvar = rdata_var_new(src->vc);
     683        rdata_var_copy_to(src, nvar);
     684
     685        *dest = nvar;
     686}
     687
     688/** Copy variable content to another variable.
     689 *
     690 * Writes an exact copy of an existing var node to another var node.
     691 * The varclass of @a src and @a dest must match. The content of
     692 * @a dest.u must be invalid.
     693 *
     694 * @param src           Source var node.
     695 * @param dest          Destination var node.
     696 */
     697static void rdata_var_copy_to(rdata_var_t *src, rdata_var_t *dest)
     698{
     699        dest->vc = src->vc;
    472700
    473701        switch (src->vc) {
    474702        case vc_bool:
    475                 rdata_bool_copy(src->u.bool_v, &nvar->u.bool_v);
     703                rdata_bool_copy(src->u.bool_v, &dest->u.bool_v);
    476704                break;
    477705        case vc_char:
    478                 rdata_char_copy(src->u.char_v, &nvar->u.char_v);
     706                rdata_char_copy(src->u.char_v, &dest->u.char_v);
    479707                break;
    480708        case vc_int:
    481                 rdata_int_copy(src->u.int_v, &nvar->u.int_v);
     709                rdata_int_copy(src->u.int_v, &dest->u.int_v);
    482710                break;
    483711        case vc_string:
    484                 rdata_string_copy(src->u.string_v, &nvar->u.string_v);
     712                rdata_string_copy(src->u.string_v, &dest->u.string_v);
    485713                break;
    486714        case vc_ref:
    487                 rdata_ref_copy(src->u.ref_v, &nvar->u.ref_v);
     715                rdata_ref_copy(src->u.ref_v, &dest->u.ref_v);
    488716                break;
    489717        case vc_deleg:
    490                 rdata_deleg_copy(src->u.deleg_v, &nvar->u.deleg_v);
     718                rdata_deleg_copy(src->u.deleg_v, &dest->u.deleg_v);
    491719                break;
    492720        case vc_enum:
    493                 rdata_enum_copy(src->u.enum_v, &nvar->u.enum_v);
     721                rdata_enum_copy(src->u.enum_v, &dest->u.enum_v);
    494722                break;
    495723        case vc_array:
    496                 rdata_array_copy(src->u.array_v, &nvar->u.array_v);
     724                rdata_array_copy(src->u.array_v, &dest->u.array_v);
    497725                break;
    498726        case vc_object:
    499                 rdata_object_copy(src->u.object_v, &nvar->u.object_v);
     727                rdata_object_copy(src->u.object_v, &dest->u.object_v);
    500728                break;
    501729        case vc_resource:
    502                 rdata_resource_copy(src->u.resource_v, &nvar->u.resource_v);
     730                rdata_resource_copy(src->u.resource_v, &dest->u.resource_v);
    503731                break;
    504732        case vc_symbol:
    505                 rdata_symbol_copy(src->u.symbol_v, &nvar->u.symbol_v);
    506                 break;
    507         }
    508 
    509         *dest = nvar;
    510 }
     733                rdata_symbol_copy(src->u.symbol_v, &dest->u.symbol_v);
     734                break;
     735        }
     736}
     737
    511738
    512739/** Copy boolean.
    513740 *
    514  * @param src           Source boolean.
    515  * @param dest          Place to store pointer to new boolean.
     741 * @param src           Source boolean
     742 * @param dest          Place to store pointer to new boolean
    516743 */
    517744static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest)
     
    523750/** Copy character.
    524751 *
    525  * @param src           Source character.
    526  * @param dest          Place to store pointer to new character.
     752 * @param src           Source character
     753 * @param dest          Place to store pointer to new character
    527754 */
    528755static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest)
     
    534761/** Copy integer.
    535762 *
    536  * @param src           Source integer.
    537  * @param dest          Place to store pointer to new integer.
     763 * @param src           Source integer
     764 * @param dest          Place to store pointer to new integer
    538765 */
    539766static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
     
    632859        *dest = rdata_symbol_new();
    633860        (*dest)->sym = src->sym;
     861}
     862
     863/** Destroy var node.
     864 *
     865 * @param var   Var node
     866 */
     867void rdata_var_destroy(rdata_var_t *var)
     868{
     869        /* First destroy class-specific part */
     870        rdata_var_destroy_inner(var);
     871
     872        /* Deallocate var node */
     873        rdata_var_delete(var);
     874}
     875
     876/** Destroy inside of var node.
     877 *
     878 * Destroy content of var node, but do not deallocate the var node
     879 * itself.
     880 *
     881 * @param var   Var node
     882 */
     883static void rdata_var_destroy_inner(rdata_var_t *var)
     884{
     885        /* First destroy class-specific part */
     886
     887        switch (var->vc) {
     888        case vc_bool:
     889                rdata_bool_destroy(var->u.bool_v);
     890                break;
     891        case vc_char:
     892                rdata_char_destroy(var->u.char_v);
     893                break;
     894        case vc_int:
     895                rdata_int_destroy(var->u.int_v);
     896                break;
     897        case vc_string:
     898                rdata_string_destroy(var->u.string_v);
     899                break;
     900        case vc_ref:
     901                rdata_ref_destroy(var->u.ref_v);
     902                break;
     903        case vc_deleg:
     904                rdata_deleg_destroy(var->u.deleg_v);
     905                break;
     906        case vc_enum:
     907                rdata_enum_destroy(var->u.enum_v);
     908                break;
     909        case vc_array:
     910                rdata_array_destroy(var->u.array_v);
     911                break;
     912        case vc_object:
     913                rdata_object_destroy(var->u.object_v);
     914                break;
     915        case vc_resource:
     916                rdata_resource_destroy(var->u.resource_v);
     917                break;
     918        case vc_symbol:
     919                rdata_symbol_destroy(var->u.symbol_v);
     920                break;
     921        }
     922}
     923
     924/** Destroy item.
     925 *
     926 * Destroy an item including the value or address within.
     927 *
     928 * @param item  Item
     929 */
     930void rdata_item_destroy(rdata_item_t *item)
     931{
     932        /* First destroy class-specific part */
     933
     934        switch (item->ic) {
     935        case ic_address:
     936                rdata_address_destroy(item->u.address);
     937                break;
     938        case ic_value:
     939                rdata_value_destroy(item->u.value);
     940                break;
     941        }
     942
     943        /* Deallocate item node */
     944        rdata_item_delete(item);
     945}
     946
     947/** Destroy address.
     948 *
     949 * Destroy an address node.
     950 *
     951 * @param address       Address
     952 */
     953void rdata_address_destroy(rdata_address_t *address)
     954{
     955        switch (address->ac) {
     956        case ac_var:
     957                rdata_addr_var_destroy(address->u.var_a);
     958                break;
     959        case ac_prop:
     960                rdata_addr_prop_destroy(address->u.prop_a);
     961                break;
     962        }
     963
     964        /* Deallocate address node */
     965        rdata_address_delete(address);
     966}
     967
     968/** Destroy variable address.
     969 *
     970 * Destroy a variable address node.
     971 *
     972 * @param addr_var      Variable address
     973 */
     974void rdata_addr_var_destroy(rdata_addr_var_t *addr_var)
     975{
     976        addr_var->vref = NULL;
     977
     978        /* Deallocate variable address node */
     979        rdata_addr_var_delete(addr_var);
     980}
     981
     982/** Destroy property address.
     983 *
     984 * Destroy a property address node.
     985 *
     986 * @param addr_prop     Property address
     987 */
     988void rdata_addr_prop_destroy(rdata_addr_prop_t *addr_prop)
     989{
     990        switch (addr_prop->apc) {
     991        case apc_named:
     992                rdata_aprop_named_destroy(addr_prop->u.named);
     993                break;
     994        case apc_indexed:
     995                rdata_aprop_indexed_destroy(addr_prop->u.indexed);
     996                break;
     997        }
     998
     999        if (addr_prop->tvalue != NULL) {
     1000                rdata_value_destroy(addr_prop->tvalue);
     1001                addr_prop->tvalue = NULL;
     1002        }
     1003
     1004        addr_prop->tpos = NULL;
     1005
     1006        /* Deallocate property address node */
     1007        rdata_addr_prop_delete(addr_prop);
     1008}
     1009
     1010/** Destroy named property address.
     1011 *
     1012 * Destroy a named property address node.
     1013 *
     1014 * @param aprop_named   Named property address
     1015 */
     1016void rdata_aprop_named_destroy(rdata_aprop_named_t *aprop_named)
     1017{
     1018        rdata_deleg_destroy(aprop_named->prop_d);
     1019
     1020        /* Deallocate named property address node */
     1021        rdata_aprop_named_delete(aprop_named);
     1022}
     1023
     1024/** Destroy indexed property address.
     1025 *
     1026 * Destroy a indexed property address node.
     1027 *
     1028 * @param aprop_indexed         Indexed property address
     1029 */
     1030void rdata_aprop_indexed_destroy(rdata_aprop_indexed_t *aprop_indexed)
     1031{
     1032        list_node_t *arg_node;
     1033        rdata_item_t *arg_i;
     1034
     1035        /* Destroy the object delegate. */
     1036        rdata_deleg_destroy(aprop_indexed->object_d);
     1037
     1038        /*
     1039         * Walk through all argument items (indices) and destroy them,
     1040         * removing them from the list as well.
     1041         */
     1042        while (!list_is_empty(&aprop_indexed->args)) {
     1043                arg_node = list_first(&aprop_indexed->args);
     1044                arg_i = list_node_data(arg_node, rdata_item_t *);
     1045
     1046                rdata_item_destroy(arg_i);
     1047                list_remove(&aprop_indexed->args, arg_node);
     1048        }
     1049
     1050        /* Destroy the now empty list */
     1051        list_fini(&aprop_indexed->args);
     1052
     1053        /* Deallocate indexed property address node */
     1054        rdata_aprop_indexed_delete(aprop_indexed);
     1055}
     1056
     1057/** Destroy value.
     1058 *
     1059 * Destroy a value node.
     1060 *
     1061 * @param value         Value
     1062 */
     1063void rdata_value_destroy(rdata_value_t *value)
     1064{
     1065        /* Assumption: Var nodes in values are not shared. */
     1066        rdata_var_destroy(value->var);
     1067
     1068        /* Deallocate value node */
     1069        rdata_value_delete(value);
     1070}
     1071
     1072/** Destroy boolean.
     1073 *
     1074 * @param bool_v                Boolean
     1075 */
     1076static void rdata_bool_destroy(rdata_bool_t *bool_v)
     1077{
     1078        rdata_bool_delete(bool_v);
     1079}
     1080
     1081/** Destroy character.
     1082 *
     1083 * @param char_v        Character
     1084 */
     1085static void rdata_char_destroy(rdata_char_t *char_v)
     1086{
     1087        bigint_destroy(&char_v->value);
     1088        rdata_char_delete(char_v);
     1089}
     1090
     1091/** Destroy integer.
     1092 *
     1093 * @param int_v         Integer
     1094 */
     1095static void rdata_int_destroy(rdata_int_t *int_v)
     1096{
     1097        bigint_destroy(&int_v->value);
     1098        rdata_int_delete(int_v);
     1099}
     1100
     1101/** Destroy string.
     1102 *
     1103 * @param string_v      String
     1104 */
     1105static void rdata_string_destroy(rdata_string_t *string_v)
     1106{
     1107        /*
     1108         * String values are shared so we cannot free them. Just deallocate
     1109         * the node.
     1110         */
     1111        rdata_string_delete(string_v);
     1112}
     1113
     1114/** Destroy reference.
     1115 *
     1116 * @param ref_v         Reference
     1117 */
     1118static void rdata_ref_destroy(rdata_ref_t *ref_v)
     1119{
     1120        ref_v->vref = NULL;
     1121        rdata_ref_delete(ref_v);
     1122}
     1123
     1124/** Destroy delegate.
     1125 *
     1126 * @param deleg_v               Reference
     1127 */
     1128static void rdata_deleg_destroy(rdata_deleg_t *deleg_v)
     1129{
     1130        deleg_v->obj = NULL;
     1131        deleg_v->sym = NULL;
     1132        rdata_deleg_delete(deleg_v);
     1133}
     1134
     1135/** Destroy enum.
     1136 *
     1137 * @param enum_v                Reference
     1138 */
     1139static void rdata_enum_destroy(rdata_enum_t *enum_v)
     1140{
     1141        enum_v->value = NULL;
     1142        rdata_enum_delete(enum_v);
     1143}
     1144
     1145/** Destroy array.
     1146 *
     1147 * @param array_v               Array
     1148 */
     1149static void rdata_array_destroy(rdata_array_t *array_v)
     1150{
     1151        int d;
     1152        size_t n_elems, p;
     1153
     1154        /*
     1155         * Compute total number of elements in array.
     1156         * At the same time zero out the extent array.
     1157         */
     1158        n_elems = 1;
     1159        for (d = 0; d < array_v->rank; d++) {
     1160                n_elems = n_elems * array_v->extent[d];
     1161                array_v->extent[d] = 0;
     1162        }
     1163
     1164        /* Destroy all elements and zero out the array */
     1165        for (p = 0; p < n_elems; p++) {
     1166                rdata_var_delete(array_v->element[p]);
     1167                array_v->element[p] = NULL;
     1168        }
     1169
     1170        /* Free the arrays */
     1171        free(array_v->element);
     1172        free(array_v->extent);
     1173
     1174        array_v->rank = 0;
     1175
     1176        /* Deallocate the node */
     1177        rdata_array_delete(array_v);
     1178}
     1179
     1180/** Destroy object.
     1181 *
     1182 * @param object_v              Object
     1183 */
     1184static void rdata_object_destroy(rdata_object_t *object_v)
     1185{
     1186        /* XXX TODO */
     1187        rdata_object_delete(object_v);
     1188}
     1189
     1190/** Destroy resource.
     1191 *
     1192 * @param resource_v            Resource
     1193 */
     1194static void rdata_resource_destroy(rdata_resource_t *resource_v)
     1195{
     1196        /*
     1197         * XXX Presumably this should be handled by the appropriate
     1198         * built-in module, so, some call-back function would be required.
     1199         */
     1200        resource_v->data = NULL;
     1201        rdata_resource_delete(resource_v);
     1202}
     1203
     1204/** Destroy symbol.
     1205 *
     1206 * @param symbol_v              Symbol
     1207 */
     1208static void rdata_symbol_destroy(rdata_symbol_t *symbol_v)
     1209{
     1210        symbol_v->sym = NULL;
     1211        rdata_symbol_delete(symbol_v);
    6341212}
    6351213
     
    6711249void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
    6721250{
    673         rdata_var_t *nvar;
     1251        /* Free old content of var->u */
     1252        rdata_var_destroy_inner(var);
    6741253
    6751254        /* Perform a shallow copy of @c value->var. */
    676         rdata_var_copy(value->var, &nvar);
    677 
    678         /* XXX do this in a prettier way. */
    679 
    680         var->vc = nvar->vc;
    681         switch (nvar->vc) {
    682         case vc_bool: var->u.bool_v = nvar->u.bool_v; break;
    683         case vc_char: var->u.char_v = nvar->u.char_v; break;
    684         case vc_int: var->u.int_v = nvar->u.int_v; break;
    685         case vc_string: var->u.string_v = nvar->u.string_v; break;
    686         case vc_ref: var->u.ref_v = nvar->u.ref_v; break;
    687         case vc_deleg: var->u.deleg_v = nvar->u.deleg_v; break;
    688         case vc_enum: var->u.enum_v = nvar->u.enum_v; break;
    689         case vc_array: var->u.array_v = nvar->u.array_v; break;
    690         case vc_object: var->u.object_v = nvar->u.object_v; break;
    691         case vc_resource: var->u.resource_v = nvar->u.resource_v; break;
    692         case vc_symbol: var->u.symbol_v = nvar->u.symbol_v; break;
    693         }
    694 
    695         /* XXX We should free some stuff around here. */
     1255        rdata_var_copy_to(value->var, var);
    6961256}
    6971257
  • uspace/app/sbi/src/rdata.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141
    4242rdata_var_t *rdata_var_new(var_class_t vc);
     43void rdata_var_delete(rdata_var_t *var);
    4344rdata_ref_t *rdata_ref_new(void);
    4445rdata_deleg_t *rdata_deleg_new(void);
     
    5354rdata_symbol_t *rdata_symbol_new(void);
    5455
     56void rdata_address_delete(rdata_address_t *address);
     57void rdata_value_delete(rdata_value_t *value);
     58void rdata_var_delete(rdata_var_t *var);
     59void rdata_item_delete(rdata_item_t *item);
     60void rdata_addr_var_delete(rdata_addr_var_t *addr_var);
     61void rdata_addr_prop_delete(rdata_addr_prop_t *addr_prop);
     62void rdata_aprop_named_delete(rdata_aprop_named_t *aprop_named);
     63void rdata_aprop_indexed_delete(rdata_aprop_indexed_t *aprop_indexed);
     64
     65void rdata_bool_delete(rdata_bool_t *bool_v);
     66void rdata_char_delete(rdata_char_t *char_v);
     67void rdata_int_delete(rdata_int_t *int_v);
     68void rdata_string_delete(rdata_string_t *string_v);
     69void rdata_ref_delete(rdata_ref_t *ref_v);
     70void rdata_deleg_delete(rdata_deleg_t *deleg_v);
     71void rdata_enum_delete(rdata_enum_t *enum_v);
     72void rdata_array_delete(rdata_array_t *array_v);
     73void rdata_object_delete(rdata_object_t *object_v);
     74void rdata_resource_delete(rdata_resource_t *resource_v);
     75void rdata_symbol_delete(rdata_symbol_t *symbol_v);
     76
    5577void rdata_array_alloc_element(rdata_array_t *array);
     78void rdata_value_copy(rdata_value_t *val, rdata_value_t **rval);
    5679void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest);
     80
     81void rdata_address_destroy(rdata_address_t *address);
     82void rdata_addr_var_destroy(rdata_addr_var_t *addr_var);
     83void rdata_addr_prop_destroy(rdata_addr_prop_t *addr_prop);
     84void rdata_aprop_named_destroy(rdata_aprop_named_t *aprop_named);
     85void rdata_aprop_indexed_destroy(rdata_aprop_indexed_t *aprop_indexed);
     86void rdata_value_destroy(rdata_value_t *value);
     87void rdata_var_destroy(rdata_var_t *var);
     88void rdata_item_destroy(rdata_item_t *item);
    5789
    5890void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem);
  • uspace/app/sbi/src/rdata_t.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    272272typedef struct rdata_value {
    273273        /**
    274          * Read-only Variable holding a copy of the data. The same @c var
    275          * can be shared between different instances of @c rdata_value_t.
     274         * Read-only Variable holding a copy of the data. Currently we don't
     275         * allow sharing the same @c var node between different value nodes
     276         * so that when destroying the value we can destroy the var.
     277         *
     278         * We could share this, but would need to reference-count it.
    276279         */
    277280        rdata_var_t *var;
  • uspace/app/sbi/src/run.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5353static void run_vdecl(run_t *run, stree_vdecl_t *vdecl);
    5454static void run_if(run_t *run, stree_if_t *if_s);
     55static void run_switch(run_t *run, stree_switch_t *switch_s);
    5556static void run_while(run_t *run, stree_while_t *while_s);
    5657static void run_raise(run_t *run, stree_raise_t *raise_s);
     
    142143        run_proc_ar_set_args(run, proc_ar, &main_args);
    143144        run_proc(run, proc_ar, &res);
     145        run_proc_ar_destroy(run, proc_ar);
    144146
    145147        run_exc_check_unhandled(run);
     
    272274        assert(list_node_data(node, run_block_ar_t *) == block_ar);
    273275        list_remove(&proc_ar->block_ar, node);
     276
     277        /* Deallocate block activation record. */
     278        run_block_ar_destroy(run, block_ar);
    274279}
    275280
     
    303308                run_if(run, stat->u.if_s);
    304309                break;
     310        case st_switch:
     311                run_switch(run, stat->u.switch_s);
     312                break;
    305313        case st_while:
    306314                run_while(run, stat->u.while_s);
     
    342350        run_expr(run, exps->expr, &rexpr);
    343351
     352        /*
     353         * If the expression has a value, the caller should have asked for it.
     354         */
     355        assert(res != NULL || rexpr == NULL);
     356
    344357        if (res != NULL)
    345358                *res = rexpr;
     
    355368        run_block_ar_t *block_ar;
    356369        rdata_var_t *var, *old_var;
    357         tdata_item_t *var_ti;
    358370
    359371#ifdef DEBUG_RUN_TRACE
    360372        printf("Executing variable declaration statement.\n");
    361373#endif
    362         /* Compute variable type. XXX Memoize. */
    363         run_texpr(run->program, run_get_current_csi(run), vdecl->type,
    364             &var_ti);
    365 
    366374        /* Create variable and initialize with default value. */
    367         run_var_new(run, var_ti, &var);
     375        run_var_new(run, vdecl->titem, &var);
    368376
    369377        block_ar = run_get_current_block_ar(run);
     
    393401        list_node_t *ifc_node;
    394402        stree_if_clause_t *ifc;
    395         bool_t clause_fired;
     403        bool_t rcond_b, clause_fired;
    396404
    397405#ifdef DEBUG_RUN_TRACE
     
    411419                        return;
    412420
    413                 if (run_item_boolean_value(run, rcond) == b_true) {
     421                rcond_b = run_item_boolean_value(run, rcond);
     422                rdata_item_destroy(rcond);
     423
     424                if (rcond_b == b_true) {
    414425#ifdef DEBUG_RUN_TRACE
    415426                        printf("Taking non-default path.\n");
     
    436447}
    437448
     449/** Run @c switch statement.
     450 *
     451 * @param run           Runner object
     452 * @param switch_s      Switch statement to run
     453 */
     454static void run_switch(run_t *run, stree_switch_t *switch_s)
     455{
     456        rdata_item_t *rsexpr, *rsexpr_vi;
     457        rdata_item_t *rwexpr, *rwexpr_vi;
     458        list_node_t *whenc_node;
     459        stree_when_t *whenc;
     460        list_node_t *expr_node;
     461        stree_expr_t *expr;
     462        bool_t clause_fired;
     463        bool_t equal;
     464
     465#ifdef DEBUG_RUN_TRACE
     466        printf("Executing switch statement.\n");
     467#endif
     468        rsexpr_vi = NULL;
     469
     470        /* Evaluate switch expression */
     471        run_expr(run, switch_s->expr, &rsexpr);
     472        if (run_is_bo(run))
     473                goto cleanup;
     474
     475        /* Convert to value item */
     476        run_cvt_value_item(run, rsexpr, &rsexpr_vi);
     477        rdata_item_destroy(rsexpr);
     478        if (run_is_bo(run))
     479                goto cleanup;
     480
     481        clause_fired = b_false;
     482        whenc_node = list_first(&switch_s->when_clauses);
     483
     484        /* Walk through all when clauses and see if they fire. */
     485
     486        while (whenc_node != NULL) {
     487                /* Get when clause */
     488                whenc = list_node_data(whenc_node, stree_when_t *);
     489
     490                expr_node = list_first(&whenc->exprs);
     491
     492                /* Walk through all expressions in the when clause */
     493                while (expr_node != NULL) {
     494                        /* Get expression */
     495                        expr = list_node_data(expr_node, stree_expr_t *);
     496
     497                        /* Evaluate expression */
     498                        run_expr(run, expr, &rwexpr);
     499                        if (run_is_bo(run))
     500                                goto cleanup;
     501
     502                        /* Convert to value item */
     503                        run_cvt_value_item(run, rwexpr, &rwexpr_vi);
     504                        rdata_item_destroy(rwexpr);
     505                        if (run_is_bo(run)) {
     506                                rdata_item_destroy(rwexpr_vi);
     507                                goto cleanup;
     508                        }
     509
     510                        /* Check if values are equal ('==') */
     511                        run_equal(run, rsexpr_vi->u.value,
     512                            rwexpr_vi->u.value, &equal);
     513                        rdata_item_destroy(rwexpr_vi);
     514                        if (run_is_bo(run))
     515                                goto cleanup;
     516
     517                        if (equal) {
     518#ifdef DEBUG_RUN_TRACE
     519                                printf("Taking non-default path.\n");
     520#endif
     521                                run_block(run, whenc->block);
     522                                clause_fired = b_true;
     523                                break;
     524                        }
     525
     526                        expr_node = list_next(&whenc->exprs, expr_node);
     527                }
     528
     529                if (clause_fired)
     530                        break;
     531
     532                whenc_node = list_next(&switch_s->when_clauses, whenc_node);
     533        }
     534
     535        /* If no when clause fired, invoke the else clause. */
     536        if (clause_fired == b_false && switch_s->else_block != NULL) {
     537#ifdef DEBUG_RUN_TRACE
     538                printf("Taking default path.\n");
     539#endif
     540                run_block(run, switch_s->else_block);
     541        }
     542cleanup:
     543        if (rsexpr_vi != NULL)
     544                rdata_item_destroy(rsexpr_vi);
     545
     546#ifdef DEBUG_RUN_TRACE
     547        printf("Switch statement terminated.\n");
     548#endif
     549}
     550
    438551/** Run @c while statement.
    439552 *
     
    453566
    454567        while (run_item_boolean_value(run, rcond) == b_true) {
     568                rdata_item_destroy(rcond);
    455569                run_block(run, while_s->body);
    456570                run_expr(run, while_s->cond, &rcond);
     
    459573        }
    460574
     575        if (rcond != NULL)
     576                rdata_item_destroy(rcond);
     577
    461578        if (run->thread_ar->bo_mode == bm_stat) {
    462579                /* Bailout due to break statement */
     
    487604
    488605        run_cvt_value_item(run, rexpr, &rexpr_vi);
     606        rdata_item_destroy(rexpr);
     607        if (run_is_bo(run))
     608                return;
    489609
    490610        /* Store expression cspan in thread AR. */
     
    492612
    493613        /* Store expression result in thread AR. */
     614        /* XXX rexpr_vi is leaked here, we only return ->u.value */
    494615        run->thread_ar->exc_payload = rexpr_vi->u.value;
    495616
     
    541662
    542663                run_cvt_value_item(run, rexpr, &rexpr_vi);
     664                rdata_item_destroy(rexpr);
     665                if (run_is_bo(run))
     666                        return;
    543667
    544668                /* Store expression result in procedure AR. */
     
    632756{
    633757        stree_csi_t *exc_csi;
    634         tdata_item_t *etype;
    635758
    636759        /* Get CSI of active exception. */
    637760        exc_csi = run_exc_payload_get_csi(run);
    638761
    639         /* Evaluate type expression in except clause. */
    640         run_texpr(run->program, run_get_current_csi(run), except_c->etype,
    641             &etype);
    642 
    643762        /* Determine if active exc. is derived from type in exc. clause. */
    644763        /* XXX This is wrong, it does not work with generics. */
    645         return tdata_is_csi_derived_from_ti(exc_csi, etype);
     764        return tdata_is_csi_derived_from_ti(exc_csi, except_c->titem);
    646765}
    647766
     
    10091128        (void) run;
    10101129
    1011         /* Create function activation record. */
     1130        /* Create procedure activation record. */
    10121131        proc_ar = run_proc_ar_new();
    10131132        proc_ar->obj = obj;
     
    10241143        *rproc_ar = proc_ar;
    10251144}
     1145
     1146/** Destroy a procedure AR.
     1147 *
     1148 * @param run           Runner object
     1149 * @param proc_ar       Pointer to procedure activation record
     1150 */
     1151void run_proc_ar_destroy(run_t *run, run_proc_ar_t *proc_ar)
     1152{
     1153        list_node_t *ar_node;
     1154        run_block_ar_t *block_ar;
     1155
     1156        (void) run;
     1157
     1158        /* Destroy special block activation record. */
     1159        ar_node = list_first(&proc_ar->block_ar);
     1160        block_ar = list_node_data(ar_node, run_block_ar_t *);
     1161        list_remove(&proc_ar->block_ar, ar_node);
     1162        run_block_ar_destroy(run, block_ar);
     1163
     1164        /* Destroy procedure activation record. */
     1165        proc_ar->obj = NULL;
     1166        proc_ar->proc = NULL;
     1167        list_fini(&proc_ar->block_ar);
     1168        proc_ar->retval = NULL;
     1169        run_proc_ar_delete(proc_ar);
     1170}
     1171
    10261172
    10271173/** Fill arguments in a procedure AR.
     
    10551201        rdata_ref_t *ref;
    10561202        rdata_array_t *array;
     1203        rdata_var_t *elem_var;
    10571204        int n_vargs, idx;
    10581205
     
    11471294                        assert(rarg->ic == ic_value);
    11481295
    1149                         rdata_var_write(array->element[idx], rarg->u.value);
     1296                        run_value_item_to_var(rarg, &elem_var);
     1297                        array->element[idx] = elem_var;
    11501298
    11511299                        rarg_n = list_next(arg_vals, rarg_n);
     
    12411389}
    12421390
     1391/** Destroy a block AR.
     1392 *
     1393 * @param run           Runner object
     1394 * @param proc_ar       Pointer to block activation record
     1395 */
     1396void run_block_ar_destroy(run_t *run, run_block_ar_t *block_ar)
     1397{
     1398        map_elem_t *elem;
     1399        rdata_var_t *var;
     1400        int key;
     1401
     1402        (void) run;
     1403
     1404        elem = intmap_first(&block_ar->vars);
     1405        while (elem != NULL) {
     1406                /* Destroy the variable */
     1407                var = intmap_elem_get_value(elem);
     1408                rdata_var_destroy(var);
     1409
     1410                /* Remove the map element */
     1411                key = intmap_elem_get_key(elem);
     1412                intmap_set(&block_ar->vars, key, NULL);
     1413
     1414                elem = intmap_first(&block_ar->vars);
     1415        }
     1416
     1417        intmap_fini(&block_ar->vars);
     1418        run_block_ar_delete(block_ar);
     1419}
     1420
    12431421/** Convert item to value item.
    12441422 *
     
    12691447        }
    12701448
    1271         /* It already is a value, we can share the @c var. */
     1449        /* Make a copy of the var node within. */
    12721450        value = rdata_value_new();
    1273         value->var = item->u.value->var;
     1451        rdata_var_copy(item->u.value->var, &value->var);
    12741452        *ritem = rdata_item_new(ic_value);
    12751453        (*ritem)->u.value = value;
     
    13581536{
    13591537        (void) run;
     1538        assert(ritem != NULL);
    13601539
    13611540        switch (address->ac) {
     
    13681547        }
    13691548
    1370         assert((*ritem)->ic == ic_value);
     1549        assert(*ritem == NULL || (*ritem)->ic == ic_value);
    13711550}
    13721551
     
    14571636        run_proc(run, proc_ar, ritem);
    14581637
     1638        /* Destroy procedure activation record. */
     1639        run_proc_ar_destroy(run, proc_ar);
     1640
    14591641#ifdef DEBUG_RUN_TRACE
    14601642        printf("Getter returns ");
     
    15291711        /* Setter should not return a value. */
    15301712        assert(ritem == NULL);
     1713
     1714        /* Destroy procedure activation record. */
     1715        run_proc_ar_destroy(run, proc_ar);
    15311716
    15321717#ifdef DEBUG_RUN_TRACE
     
    15901775#endif
    15911776        run_cvt_value_item(run, ref, &ref_val);
     1777        if (run_is_bo(run)) {
     1778                *ritem = run_recovery_item(run);
     1779                return;
     1780        }
     1781
    15921782        assert(ref_val->u.value->var->vc == vc_ref);
    15931783
     
    15981788        address->u.var_a = addr_var;
    15991789        addr_var->vref = ref_val->u.value->var->u.ref_v->vref;
     1790
     1791        rdata_item_destroy(ref_val);
    16001792
    16011793        if (addr_var->vref == NULL) {
     
    18402032}
    18412033
    1842 /** Construct a new procedure activation record.
    1843  *
    1844  * @param run   Runner object
     2034/** Allocate a new procedure activation record.
     2035 *
    18452036 * @return      New procedure AR.
    18462037 */
     
    18582049}
    18592050
    1860 /** Construct a new block activation record.
     2051/** Deallocate a procedure activation record.
     2052 *
     2053 * @return      New procedure AR.
     2054 */
     2055void run_proc_ar_delete(run_proc_ar_t *proc_ar)
     2056{
     2057        assert(proc_ar != NULL);
     2058        free(proc_ar);
     2059}
     2060
     2061/** Allocate a new block activation record.
    18612062 *
    18622063 * @param run   Runner object
     
    18752076        return block_ar;
    18762077}
     2078
     2079/** Deallocate a new block activation record.
     2080 *
     2081 * @param run   Runner object
     2082 * @return      New block AR.
     2083 */
     2084void run_block_ar_delete(run_block_ar_t *block_ar)
     2085{
     2086        assert(block_ar != NULL);
     2087        free(block_ar);
     2088}
  • uspace/app/sbi/src/run.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6161void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc,
    6262    run_proc_ar_t **rproc_ar);
     63void run_proc_ar_destroy(run_t *run, run_proc_ar_t *proc_ar);
    6364
    6465var_class_t run_item_get_vc(run_t *run, rdata_item_t *item);
     
    7980run_thread_ar_t *run_thread_ar_new(void);
    8081run_proc_ar_t *run_proc_ar_new(void);
     82void run_proc_ar_delete(run_proc_ar_t *proc_ar);
    8183run_block_ar_t *run_block_ar_new(void);
     84void run_block_ar_delete(run_block_ar_t *block_ar);
     85void run_proc_ar_delete(run_proc_ar_t *proc_ar);
     86void run_block_ar_destroy(run_t *run, run_block_ar_t *block_ar);
     87
    8288
    8389#endif
  • uspace/app/sbi/src/run_expr.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    113113static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res);
    114114static void run_call_args(run_t *run, list_t *args, list_t *arg_vals);
     115static void run_destroy_arg_vals(list_t *arg_vals);
    115116
    116117static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res);
     
    200201        rdata_address_t *address;
    201202        rdata_addr_var_t *addr_var;
     203        rdata_addr_prop_t *addr_prop;
     204        rdata_aprop_named_t *aprop_named;
     205        rdata_deleg_t *deleg_p;
    202206        rdata_value_t *value;
    203207        rdata_var_t *var;
     
    334338                break;
    335339        case sc_var:
    336 #ifdef DEBUG_RUN_TRACE
    337                 printf("Referencing member variable.\n");
    338 #endif
    339                 /* There should be no global variables. */
     340        case sc_prop:
     341#ifdef DEBUG_RUN_TRACE
     342                if (sym->sc == sc_var)
     343                        printf("Referencing member variable.\n");
     344                else
     345                        printf("Referencing unqualified property.\n");
     346#endif
     347                /* There should be no global variables or properties. */
    340348                assert(csi != NULL);
    341349
    342350                if (symbol_search_csi(run->program, csi, nameref->name)
    343351                    == NULL && !stree_symbol_is_static(sym)) {
    344                         /* Variable is not in the current object. */
     352                        /* Symbol is not in the current object. */
    345353                        printf("Error: Cannot access non-static member "
    346354                            "variable '");
     
    352360                }
    353361
     362                /*
     363                 * Determine object in which the symbol resides
     364                 */
    354365                if (stree_symbol_is_static(sym)) {
    355366                        /*
     367                         * Class object
    356368                         * XXX This is too slow!
    357369                         *
     
    365377                        aobj = sobj->u.object_v;
    366378                } else {
    367                         aobj = obj;
     379                        /*
     380                         * Instance object. Currently we don't support
     381                         * true inner classes, thus we know the symbol is
     382                         * in the active object (there is no dynamic parent).
     383                         */
     384                        sobj = proc_ar->obj;
     385                        aobj = sobj->u.object_v;;
    368386                }
    369387
    370                 /* Find member variable in object. */
    371                 member_var = intmap_get(&aobj->fields, nameref->name->sid);
    372                 assert(member_var != NULL);
    373 
    374                 /* Return address of the variable. */
    375                 item = rdata_item_new(ic_address);
    376                 address = rdata_address_new(ac_var);
    377                 addr_var = rdata_addr_var_new();
    378 
    379                 item->u.address = address;
    380                 address->u.var_a = addr_var;
    381                 addr_var->vref = member_var;
    382 
    383                 *res = item;
    384                 break;
    385         case sc_prop:
    386                 /* XXX TODO */
    387                 printf("Unimplemented: Property name reference.\n");
    388                 abort();
     388                if (sym->sc == sc_var) {
     389                        /* Find member variable in object. */
     390                        member_var = intmap_get(&aobj->fields,
     391                            nameref->name->sid);
     392                        assert(member_var != NULL);
     393
     394                        /* Return address of the variable. */
     395                        item = rdata_item_new(ic_address);
     396                        address = rdata_address_new(ac_var);
     397                        addr_var = rdata_addr_var_new();
     398
     399                        item->u.address = address;
     400                        address->u.var_a = addr_var;
     401                        addr_var->vref = member_var;
     402
     403                        *res = item;
     404                } else {
     405                        /* Construct named property address. */
     406                        item = rdata_item_new(ic_address);
     407                        address = rdata_address_new(ac_prop);
     408                        addr_prop = rdata_addr_prop_new(apc_named);
     409                        aprop_named = rdata_aprop_named_new();
     410                        item->u.address = address;
     411                        address->u.prop_a = addr_prop;
     412                        addr_prop->u.named = aprop_named;
     413
     414                        deleg_p = rdata_deleg_new();
     415                        deleg_p->obj = sobj;
     416                        deleg_p->sym = sym;
     417                        addr_prop->u.named->prop_d = deleg_p;
     418
     419                        *res = item;
     420                }
    389421                break;
    390422        }
     
    611643        rdata_value_t *v1, *v2;
    612644
     645        rarg1_i = NULL;
     646        rarg2_i = NULL;
     647        rarg1_vi = NULL;
     648        rarg2_vi = NULL;
     649
    613650#ifdef DEBUG_RUN_TRACE
    614651        printf("Run binary operation.\n");
     
    616653        run_expr(run, binop->arg1, &rarg1_i);
    617654        if (run_is_bo(run)) {
    618                 *res = NULL;
    619                 return;
     655                *res = run_recovery_item(run);
     656                goto cleanup;
     657        }
     658
     659#ifdef DEBUG_RUN_TRACE
     660        printf("Check binop argument result.\n");
     661#endif
     662        run_cvt_value_item(run, rarg1_i, &rarg1_vi);
     663        if (run_is_bo(run)) {
     664                *res = run_recovery_item(run);
     665                goto cleanup;
    620666        }
    621667
    622668        run_expr(run, binop->arg2, &rarg2_i);
    623669        if (run_is_bo(run)) {
    624                 *res = NULL;
    625                 return;
    626         }
    627 
    628 #ifdef DEBUG_RUN_TRACE
    629         printf("Check binop argument results.\n");
    630 #endif
    631 
    632         run_cvt_value_item(run, rarg1_i, &rarg1_vi);
     670                *res = run_recovery_item(run);
     671                goto cleanup;
     672        }
     673
     674#ifdef DEBUG_RUN_TRACE
     675        printf("Check binop argument result.\n");
     676#endif
    633677        run_cvt_value_item(run, rarg2_i, &rarg2_vi);
     678        if (run_is_bo(run)) {
     679                *res = run_recovery_item(run);
     680                goto cleanup;
     681        }
    634682
    635683        v1 = rarg1_vi->u.value;
     
    668716                assert(b_false);
    669717        }
     718
     719cleanup:
     720        if (rarg1_i != NULL)
     721                rdata_item_destroy(rarg1_i);
     722        if (rarg2_i != NULL)
     723                rdata_item_destroy(rarg2_i);
     724        if (rarg1_vi != NULL)
     725                rdata_item_destroy(rarg1_vi);
     726        if (rarg2_vi != NULL)
     727                rdata_item_destroy(rarg2_vi);
    670728}
    671729
     
    10541112        rdata_bool_t *bool_v;
    10551113
    1056         rdata_var_t *ref1, *ref2;
     1114        stree_embr_t *e1, *e2;
    10571115
    10581116        (void) run;
     
    10671125        var->u.bool_v = bool_v;
    10681126
    1069         ref1 = v1->var->u.ref_v->vref;
    1070         ref2 = v2->var->u.ref_v->vref;
     1127        e1 = v1->var->u.enum_v->value;
     1128        e2 = v2->var->u.enum_v->value;
    10711129
    10721130        switch (binop->bc) {
    10731131        case bo_equal:
    1074                 bool_v->value = (ref1 == ref2);
     1132                bool_v->value = (e1 == e2);
    10751133                break;
    10761134        case bo_notequal:
    1077                 bool_v->value = (ref1 != ref2);
     1135                bool_v->value = (e1 != e2);
    10781136                break;
    10791137        default:
     
    11001158        printf("Run unary operation.\n");
    11011159#endif
     1160        rarg_i = NULL;
     1161        rarg_vi = NULL;
     1162
    11021163        run_expr(run, unop->arg, &rarg_i);
    11031164        if (run_is_bo(run)) {
    1104                 *res = NULL;
    1105                 return;
     1165                *res = run_recovery_item(run);
     1166                goto cleanup;
    11061167        }
    11071168
     
    11101171#endif
    11111172        run_cvt_value_item(run, rarg_i, &rarg_vi);
     1173        if (run_is_bo(run)) {
     1174                *res = run_recovery_item(run);
     1175                goto cleanup;
     1176        }
    11121177
    11131178        val = rarg_vi->u.value;
     
    11241189                    "type %d.\n", val->var->vc);
    11251190                run_raise_error(run);
    1126                 *res = NULL;
    1127                 break;
    1128         }
     1191                *res = run_recovery_item(run);
     1192                break;
     1193        }
     1194cleanup:
     1195        if (rarg_i != NULL)
     1196                rdata_item_destroy(rarg_i);
     1197        if (rarg_vi != NULL)
     1198                rdata_item_destroy(rarg_vi);
    11291199}
    11301200
     
    12081278        *res = item;
    12091279}
     1280
     1281/** Run equality comparison of two values
     1282 *
     1283 * This should be equivalent to equality ('==') binary operation.
     1284 * XXX Duplicating code of run_binop_xxx().
     1285 *
     1286 * @param run           Runner object
     1287 * @param v1            Value of first argument
     1288 * @param v2            Value of second argument
     1289 * @param res           Place to store result (plain boolean value)
     1290 */
     1291void run_equal(run_t *run, rdata_value_t *v1, rdata_value_t *v2, bool_t *res)
     1292{
     1293        bool_t b1, b2;
     1294        bigint_t *c1, *c2;
     1295        bigint_t *i1, *i2;
     1296        bigint_t diff;
     1297        const char *s1, *s2;
     1298        rdata_var_t *ref1, *ref2;
     1299        stree_embr_t *e1, *e2;
     1300
     1301        (void) run;
     1302        assert(v1->var->vc == v2->var->vc);
     1303
     1304        switch (v1->var->vc) {
     1305        case vc_bool:
     1306                b1 = v1->var->u.bool_v->value;
     1307                b2 = v2->var->u.bool_v->value;
     1308
     1309                *res = (b1 == b2);
     1310                break;
     1311        case vc_char:
     1312                c1 = &v1->var->u.char_v->value;
     1313                c2 = &v2->var->u.char_v->value;
     1314
     1315                bigint_sub(c1, c2, &diff);
     1316                *res = bigint_is_zero(&diff);
     1317                break;
     1318        case vc_int:
     1319                i1 = &v1->var->u.int_v->value;
     1320                i2 = &v2->var->u.int_v->value;
     1321
     1322                bigint_sub(i1, i2, &diff);
     1323                *res = bigint_is_zero(&diff);
     1324                break;
     1325        case vc_string:
     1326                s1 = v1->var->u.string_v->value;
     1327                s2 = v2->var->u.string_v->value;
     1328
     1329                *res = os_str_cmp(s1, s2) == 0;
     1330                break;
     1331        case vc_ref:
     1332                ref1 = v1->var->u.ref_v->vref;
     1333                ref2 = v2->var->u.ref_v->vref;
     1334
     1335                *res = (ref1 == ref2);
     1336                break;
     1337        case vc_enum:
     1338                e1 = v1->var->u.enum_v->value;
     1339                e2 = v2->var->u.enum_v->value;
     1340
     1341                *res = (e1 == e2);
     1342                break;
     1343
     1344        case vc_deleg:
     1345        case vc_array:
     1346        case vc_object:
     1347        case vc_resource:
     1348        case vc_symbol:
     1349                assert(b_false);
     1350        }
     1351}
     1352
    12101353
    12111354/** Evaluate @c new operation.
     
    12971440                run_expr(run, expr, &rexpr);
    12981441                if (run_is_bo(run)) {
    1299                         *res = NULL;
     1442                        *res = run_recovery_item(run);
    13001443                        return;
    13011444                }
    13021445
    13031446                run_cvt_value_item(run, rexpr, &rexpr_vi);
     1447                if (run_is_bo(run)) {
     1448                        *res = run_recovery_item(run);
     1449                        return;
     1450                }
     1451
    13041452                assert(rexpr_vi->ic == ic_value);
    13051453                rexpr_var = rexpr_vi->u.value->var;
     
    13751523        run_call_args(run, &new_op->ctor_args, &arg_vals);
    13761524        if (run_is_bo(run)) {
    1377                 *res = NULL;
     1525                *res = run_recovery_item(run);
    13781526                return;
    13791527        }
     
    13871535        assert(obj_i->u.address->ac == ac_var);
    13881536        run_object_ctor(run, obj_i->u.address->u.var_a->vref, &arg_vals);
     1537        rdata_item_destroy(obj_i);
     1538
     1539        /* Destroy argument values */
     1540        run_destroy_arg_vals(&arg_vals);
    13891541}
    13901542
     
    14041556        printf("Run access operation.\n");
    14051557#endif
     1558        rarg = NULL;
     1559
    14061560        run_expr(run, access->arg, &rarg);
    14071561        if (run_is_bo(run)) {
    1408                 *res = NULL;
    1409                 return;
     1562                *res = run_recovery_item(run);
     1563                goto cleanup;
    14101564        }
    14111565
     
    14161570
    14171571        run_access_item(run, access, rarg, res);
     1572cleanup:
     1573        if (rarg != NULL)
     1574                rdata_item_destroy(rarg);
    14181575}
    14191576
     
    14841641        /* Try again. */
    14851642        run_access_item(run, access, darg, res);
     1643
     1644        /* Destroy temporary */
     1645        rdata_item_destroy(darg);
    14861646}
    14871647
     
    17901950#endif
    17911951        run_cvt_value_item(run, arg, &arg_vi);
     1952        if (run_is_bo(run)) {
     1953                *res = run_recovery_item(run);
     1954                return;
     1955        }
     1956
    17921957        arg_val = arg_vi->u.value;
    17931958        assert(arg_val->var->vc == vc_symbol);
     
    18001965        embr = stree_enum_find_mbr(symbol_v->sym->u.enum_d,
    18011966            access->member_name);
     1967
     1968        rdata_item_destroy(arg_vi);
    18021969
    18031970        /* Member existence should be ensured by static type checking. */
     
    18412008        printf("Run call operation.\n");
    18422009#endif
     2010        rdeleg = NULL;
     2011        rdeleg_vi = NULL;
     2012
    18432013        run_expr(run, call->fun, &rdeleg);
    18442014        if (run_is_bo(run)) {
    1845                 *res = NULL;
    1846                 return;
    1847         }
    1848 
    1849         if (run->thread_ar->bo_mode != bm_none) {
    18502015                *res = run_recovery_item(run);
    1851                 return;
     2016                goto cleanup;
    18522017        }
    18532018
    18542019        run_cvt_value_item(run, rdeleg, &rdeleg_vi);
     2020        if (run_is_bo(run)) {
     2021                *res = run_recovery_item(run);
     2022                goto cleanup;
     2023        }
     2024
    18552025        assert(rdeleg_vi->ic == ic_value);
    18562026
     
    18772047        run_call_args(run, &call->args, &arg_vals);
    18782048        if (run_is_bo(run)) {
    1879                 *res = NULL;
    1880                 return;
     2049                *res = run_recovery_item(run);
     2050                goto cleanup;
    18812051        }
    18822052
     
    18892059        /* Fill in argument values. */
    18902060        run_proc_ar_set_args(run, proc_ar, &arg_vals);
     2061
     2062        /* Destroy arg_vals, they are no longer needed. */
     2063        run_destroy_arg_vals(&arg_vals);
    18912064
    18922065        /* Run the function. */
     
    19002073        }
    19012074
     2075        /* Destroy procedure activation record. */
     2076        run_proc_ar_destroy(run, proc_ar);
     2077
     2078cleanup:
     2079        if (rdeleg != NULL)
     2080                rdata_item_destroy(rdeleg);
     2081        if (rdeleg_vi != NULL)
     2082                rdata_item_destroy(rdeleg_vi);
     2083
    19022084#ifdef DEBUG_RUN_TRACE
    19032085        printf("Returned from function call.\n");
     
    19282110                run_expr(run, arg, &rarg_i);
    19292111                if (run_is_bo(run))
    1930                         return;
     2112                        goto error;
    19312113
    19322114                run_cvt_value_item(run, rarg_i, &rarg_vi);
     2115                rdata_item_destroy(rarg_i);
     2116                if (run_is_bo(run))
     2117                        goto error;
    19332118
    19342119                list_append(arg_vals, rarg_vi);
    19352120                arg_n = list_next(args, arg_n);
    19362121        }
     2122        return;
     2123
     2124error:
     2125        /*
     2126         * An exception or error occured while evaluating one of the
     2127         * arguments. Destroy already obtained argument values and
     2128         * dismantle the list.
     2129         */
     2130        run_destroy_arg_vals(arg_vals);
     2131}
     2132
     2133/** Destroy list of evaluated arguments.
     2134 *
     2135 * Provided a list of evaluated arguments, destroy them, removing them
     2136 * from the list and fini the list itself.
     2137 *
     2138 * @param arg_vals      List of evaluated arguments (value items,
     2139 *                      rdata_item_t).
     2140 */
     2141static void run_destroy_arg_vals(list_t *arg_vals)
     2142{
     2143        list_node_t *val_n;
     2144        rdata_item_t *val_i;
     2145
     2146        /*
     2147         * An exception or error occured while evaluating one of the
     2148         * arguments. Destroy already obtained argument values and
     2149         * dismantle the list.
     2150         */
     2151        while (!list_is_empty(arg_vals)) {
     2152                val_n = list_first(arg_vals);
     2153                val_i = list_node_data(val_n, rdata_item_t *);
     2154
     2155                rdata_item_destroy(val_i);
     2156                list_remove(arg_vals, val_n);
     2157        }
     2158        list_fini(arg_vals);
    19372159}
    19382160
     
    19542176        var_class_t vc;
    19552177        list_t arg_vals;
     2178        list_node_t *val_n;
     2179        rdata_item_t *val_i;
    19562180
    19572181#ifdef DEBUG_RUN_TRACE
     
    19602184        run_expr(run, index->base, &rbase);
    19612185        if (run_is_bo(run)) {
    1962                 *res = NULL;
     2186                *res = run_recovery_item(run);
    19632187                return;
    19642188        }
     
    19692193        if (vc == vc_ref) {
    19702194                run_dereference(run, rbase, index->base->cspan, &base_i);
     2195                rdata_item_destroy(rbase);
    19712196                if (run_is_bo(run)) {
    1972                         *res = NULL;
     2197                        *res = run_recovery_item(run);
    19732198                        return;
    19742199                }
     
    19872212                run_expr(run, arg, &rarg_i);
    19882213                if (run_is_bo(run)) {
    1989                         *res = NULL;
    1990                         return;
     2214                        *res = run_recovery_item(run);
     2215                        goto cleanup;
    19912216                }
    19922217
    19932218                run_cvt_value_item(run, rarg_i, &rarg_vi);
     2219                rdata_item_destroy(rarg_i);
     2220                if (run_is_bo(run)) {
     2221                        *res = run_recovery_item(run);
     2222                        goto cleanup;
     2223                }
    19942224
    19952225                list_append(&arg_vals, rarg_vi);
     
    20122242                exit(1);
    20132243        }
     2244
     2245        /* Destroy the indexing base temporary */
     2246        rdata_item_destroy(base_i);
     2247cleanup:
     2248        /*
     2249         * An exception or error occured while evaluating one of the
     2250         * arguments. Destroy already obtained argument values and
     2251         * dismantle the list.
     2252         */
     2253        while (!list_is_empty(&arg_vals)) {
     2254                val_n = list_first(&arg_vals);
     2255                val_i = list_node_data(val_n, rdata_item_t *);
     2256
     2257                rdata_item_destroy(val_i);
     2258                list_remove(&arg_vals, val_n);
     2259        }
     2260
     2261        list_fini(&arg_vals);
    20142262}
    20152263
     
    21362384
    21372385        list_node_t *node;
    2138         rdata_item_t *arg;
     2386        rdata_item_t *arg, *arg_copy;
    21392387
    21402388#ifdef DEBUG_RUN_TRACE
     
    21862434        while (node != NULL) {
    21872435                arg = list_node_data(node, rdata_item_t *);
    2188                 list_append(&aprop_indexed->args, arg);
     2436
     2437                /*
     2438                 * Clone argument so that original can
     2439                 * be freed.
     2440                 */
     2441                assert(arg->ic == ic_value);
     2442                arg_copy = rdata_item_new(ic_value);
     2443                rdata_value_copy(arg->u.value, &arg_copy->u.value);
     2444
     2445                list_append(&aprop_indexed->args, arg_copy);
    21892446                node = list_next(args, node);
    21902447        }
     
    22252482
    22262483        run_cvt_value_item(run, base, &base_vi);
     2484        if (run_is_bo(run)) {
     2485                *res = run_recovery_item(run);
     2486                return;
     2487        }
     2488
    22272489        assert(base_vi->u.value->var->vc == vc_string);
    22282490        string = base_vi->u.value->var->u.string_v;
     
    22772539                    index->expr->cspan);
    22782540                *res = run_recovery_item(run);
    2279                 return;
     2541                goto cleanup;
    22802542        }
    22812543
     
    22912553
    22922554        *res = ritem;
     2555cleanup:
     2556        rdata_item_destroy(base_vi);
    22932557}
    22942558
     
    23102574        printf("Run assign operation.\n");
    23112575#endif
     2576        rdest_i = NULL;
     2577        rsrc_i = NULL;
     2578        rsrc_vi = NULL;
     2579
    23122580        run_expr(run, assign->dest, &rdest_i);
    23132581        if (run_is_bo(run)) {
    2314                 *res = NULL;
    2315                 return;
     2582                *res = run_recovery_item(run);
     2583                goto cleanup;
    23162584        }
    23172585
    23182586        run_expr(run, assign->src, &rsrc_i);
    23192587        if (run_is_bo(run)) {
    2320                 *res = NULL;
    2321                 return;
     2588                *res = run_recovery_item(run);
     2589                goto cleanup;
    23222590        }
    23232591
    23242592        run_cvt_value_item(run, rsrc_i, &rsrc_vi);
     2593        if (run_is_bo(run)) {
     2594                *res = run_recovery_item(run);
     2595                goto cleanup;
     2596        }
     2597
    23252598        assert(rsrc_vi->ic == ic_value);
    23262599
     
    23342607
    23352608        *res = NULL;
     2609cleanup:
     2610        if (rdest_i != NULL)
     2611                rdata_item_destroy(rdest_i);
     2612        if (rsrc_i != NULL)
     2613                rdata_item_destroy(rsrc_i);
     2614        if (rsrc_vi != NULL)
     2615                rdata_item_destroy(rsrc_vi);
    23362616}
    23372617
     
    23592639        run_expr(run, as_op->arg, &rarg_i);
    23602640        if (run_is_bo(run)) {
    2361                 *res = NULL;
     2641                *res = run_recovery_item(run);
    23622642                return;
    23632643        }
     
    23692649        assert(run_item_get_vc(run, rarg_i) == vc_ref);
    23702650        run_cvt_value_item(run, rarg_i, &rarg_vi);
     2651        rdata_item_destroy(rarg_i);
     2652
     2653        if (run_is_bo(run)) {
     2654                *res = run_recovery_item(run);
     2655                return;
     2656        }
     2657
    23712658        assert(rarg_vi->ic == ic_value);
    23722659
     
    24052692        }
    24062693
     2694        /* The dereferenced item is not used anymore. */
     2695        rdata_item_destroy(rarg_di);
     2696
    24072697        *res = rarg_vi;
    24082698}
     
    24352725        run_expr(run, box->arg, &rarg_i);
    24362726        if (run_is_bo(run)) {
    2437                 *res = NULL;
     2727                *res = run_recovery_item(run);
    24382728                return;
    24392729        }
    24402730
    24412731        run_cvt_value_item(run, rarg_i, &rarg_vi);
     2732        rdata_item_destroy(rarg_i);
     2733        if (run_is_bo(run)) {
     2734                *res = run_recovery_item(run);
     2735                return;
     2736        }
     2737
    24422738        assert(rarg_vi->ic == ic_value);
    24432739
     
    24822778
    24832779        rdata_var_write(mbr_var, rarg_vi->u.value);
     2780        rdata_item_destroy(rarg_vi);
    24842781}
    24852782
     
    26572954        assert(res == NULL);
    26582955
     2956        /* Destroy procedure activation record. */
     2957        run_proc_ar_destroy(run, proc_ar);
     2958
    26592959#ifdef DEBUG_RUN_TRACE
    26602960        printf("Returned from constructor..\n");
     
    26752975        rdata_item_t *vitem;
    26762976        rdata_var_t *var;
     2977        bool_t res;
    26772978
    26782979        (void) run;
    26792980        run_cvt_value_item(run, item, &vitem);
     2981        if (run_is_bo(run))
     2982                return b_true;
    26802983
    26812984        assert(vitem->ic == ic_value);
     
    26832986
    26842987        assert(var->vc == vc_bool);
    2685         return var->u.bool_v->value;
    2686 }
     2988        res = var->u.bool_v->value;
     2989
     2990        /* Free value item */
     2991        rdata_item_destroy(vitem);
     2992        return res;
     2993}
  • uspace/app/sbi/src/run_expr.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939    rdata_var_t **res);
    4040
     41void run_equal(run_t *run, rdata_value_t *v1, rdata_value_t *v2, bool_t *res);
    4142bool_t run_item_boolean_value(run_t *run, rdata_item_t *item);
    4243
  • uspace/app/sbi/src/stree.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    397397}
    398398
     399/** Allocate new @c switch statement.
     400 *
     401 * @return      New @c if statement
     402 */
     403stree_switch_t *stree_switch_new(void)
     404{
     405        stree_switch_t *switch_s;
     406
     407        switch_s = calloc(1, sizeof(stree_switch_t));
     408        if (switch_s == NULL) {
     409                printf("Memory allocation failed.\n");
     410                exit(1);
     411        }
     412
     413        return switch_s;
     414}
     415
    399416/** Allocate new @c while statement.
    400417 *
     
    548565
    549566        return if_clause;
     567}
     568
     569/** Allocate new @c when clause.
     570 *
     571 * @return      New @c when clause
     572 */
     573stree_when_t *stree_when_new(void)
     574{
     575        stree_when_t *when_c;
     576
     577        when_c = calloc(1, sizeof(stree_when_t));
     578        if (when_c == NULL) {
     579                printf("Memory allocation failed.\n");
     580                exit(1);
     581        }
     582
     583        return when_c;
    550584}
    551585
  • uspace/app/sbi/src/stree.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5555stree_vdecl_t *stree_vdecl_new(void);
    5656stree_if_t *stree_if_new(void);
     57stree_switch_t *stree_switch_new(void);
    5758stree_while_t *stree_while_new(void);
    5859stree_for_t *stree_for_new(void);
     
    6566stree_except_t *stree_except_new(void);
    6667stree_if_clause_t *stree_if_clause_new(void);
     68stree_when_t *stree_when_new(void);
    6769stree_block_t *stree_block_new(void);
    6870
  • uspace/app/sbi/src/stree_t.h

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    364364} texpr_class_t;
    365365
    366 /** Arithmetic expression */
     366/** Type expression */
    367367typedef struct stree_texpr {
    368368        texpr_class_t tc;
     
    394394        stree_ident_t *name;
    395395        stree_texpr_t *type;
     396
     397        /** Type of this variable or @c NULL if not typed yet */
     398        struct tdata_item *titem;
    396399} stree_vdecl_t;
    397400
     
    401404        stree_texpr_t *etype;
    402405        stree_block_t *block;
     406
     407        /** Evaluated etype or @c NULL if not typed yet */
     408        struct tdata_item *titem;
    403409} stree_except_t;
    404410
     
    418424} stree_if_t;
    419425
     426/** @c when clause */
     427typedef struct {
     428        /** List of expressions -- cases -- for this clause */
     429        list_t exprs; /* of stree_expr_t */
     430        stree_block_t *block;
     431} stree_when_t;
     432
     433/** Switch statement */
     434typedef struct {
     435        /** Switch expression */
     436        stree_expr_t *expr;
     437
     438        /** When clauses */
     439        list_t when_clauses; /* of stree_when_t */
     440
     441        /** Else block */
     442        stree_block_t *else_block;
     443} stree_switch_t;
     444
    420445/** While statement */
    421446typedef struct {
     
    448473} stree_exps_t;
    449474
    450 /** With-try-except-finally statement (WEF) */
     475/** With-try-except-finally (WEF) statement */
    451476typedef struct {
    452477        stree_block_t *with_block;
     
    459484        st_vdecl,
    460485        st_if,
     486        st_switch,
    461487        st_while,
    462488        st_for,
     
    475501                stree_vdecl_t *vdecl_s;
    476502                stree_if_t *if_s;
     503                stree_switch_t *switch_s;
    477504                stree_while_t *while_s;
    478505                stree_for_t *for_s;
     
    510537/** Function signature.
    511538 *
    512  * Foormal parameters and return type. This is common to function and delegate
     539 * Formal parameters and return type. This is common to function and delegate
    513540 * delcarations.
    514541 */
     
    788815        } u;
    789816
    790         /** Containing CSI (for all symbols) */
     817        /** Containing CSI */
    791818        stree_csi_t *outer_csi;
    792819
    793         /** Containing block (for block-level symbols) */
    794         stree_block_t *outer_block;
    795 
    796         /** Symbol attributes. */
     820        /** Symbol attributes */
    797821        list_t attr; /* of stree_symbol_attr_t */
    798822} stree_symbol_t;
  • uspace/app/sbi/src/stype.c

    r1614ce3 rb64eac6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7676static void stype_vdecl(stype_t *stype, stree_vdecl_t *vdecl_s);
    7777static void stype_if(stype_t *stype, stree_if_t *if_s);
     78static void stype_switch(stype_t *stype, stree_switch_t *switch_s);
    7879static void stype_while(stype_t *stype, stree_while_t *while_s);
    7980static void stype_for(stype_t *stype, stree_for_t *for_s);
     
    889890        case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break;
    890891        case st_if: stype_if(stype, stat->u.if_s); break;
     892        case st_switch: stype_switch(stype, stat->u.switch_s); break;
    891893        case st_while: stype_while(stype, stat->u.while_s); break;
    892894        case st_for: stype_for(stype, stat->u.for_s); break;
     
    931933        }
    932934
     935        /* Annotate with variable type */
     936        vdecl_s->titem = titem;
     937
    933938        intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s);
    934939}
     
    973978        if (if_s->else_block != NULL)
    974979                stype_block(stype, if_s->else_block);
     980}
     981
     982/** Type @c switch statement.
     983 *
     984 * @param stype         Static typing object
     985 * @param switch_s      @c switch statement
     986 */
     987static void stype_switch(stype_t *stype, stree_switch_t *switch_s)
     988{
     989        stree_expr_t *expr, *cexpr;
     990        list_node_t *whenc_node;
     991        stree_when_t *whenc;
     992        list_node_t *expr_node;
     993        tdata_item_t *titem1, *titem2;
     994
     995#ifdef DEBUG_TYPE_TRACE
     996        printf("Type 'switch' statement.\n");
     997#endif
     998        stype_expr(stype, switch_s->expr);
     999
     1000        titem1 = switch_s->expr->titem;
     1001        if (titem1 == NULL) {
     1002                cspan_print(switch_s->expr->cspan);
     1003                printf(" Error: Switch expression has no value.\n");
     1004                stype_note_error(stype);
     1005                return;
     1006        }
     1007
     1008        /* Walk through all when clauses. */
     1009        whenc_node = list_first(&switch_s->when_clauses);
     1010
     1011        while (whenc_node != NULL) {
     1012                /* Get when clause */
     1013                whenc = list_node_data(whenc_node, stree_when_t *);
     1014
     1015                /* Walk through all expressions of the when clause */
     1016                expr_node = list_first(&whenc->exprs);
     1017                while (expr_node != NULL) {
     1018                        expr = list_node_data(expr_node, stree_expr_t *);
     1019
     1020                        stype_expr(stype, expr);
     1021                        titem2 = expr->titem;
     1022                        if (titem2 == NULL) {
     1023                                cspan_print(expr->cspan);
     1024                                printf(" Error: When expression has no value.\n");
     1025                                stype_note_error(stype);
     1026                                return;
     1027                        }
     1028
     1029                        /* Convert expression to same type as switch expr. */
     1030                        cexpr = stype_convert(stype, expr, titem1);
     1031
     1032                        /* Patch code with augmented expression. */
     1033                        list_node_setdata(expr_node, cexpr);
     1034
     1035                        expr_node = list_next(&whenc->exprs, expr_node);
     1036                }
     1037
     1038                /* Type the @c when block */
     1039                stype_block(stype, whenc->block);
     1040
     1041                whenc_node = list_next(&switch_s->when_clauses, whenc_node);
     1042        }
     1043
     1044        /* Type the @c else block */
     1045        if (switch_s->else_block != NULL)
     1046                stype_block(stype, switch_s->else_block);
    9751047}
    9761048
     
    11681240        while (ec_n != NULL) {
    11691241                ec = list_node_data(ec_n, stree_except_t *);
     1242                run_texpr(stype->program, stype->current_csi, ec->etype,
     1243                    &ec->titem);
    11701244                stype_block(stype, ec->block);
    11711245
  • uspace/app/sbi/src/stype_expr.c

    r1614ce3 rb64eac6  
    894894
    895895        titem = unop->arg->titem;
     896        if (titem == NULL) {
     897                cspan_print(unop->arg->cspan);
     898                printf(" Error: Argument of unary operation has no value.\n");
     899                stype_note_error(stype);
     900                *rtitem = stype_recovery_titem(stype);
     901                return;
     902        }
    896903
    897904        if (titem->tic == tic_ignore) {
  • uspace/dist/src/sysel/demos/arith.sy

    r1614ce3 rb64eac6  
    3030        fun Main(), static is
    3131                -- Test addition, multiplication and precedence.
    32                 Builtin.Write("2*2 + 2*2 = ");
    33                 Builtin.Write(2*2 + 2*2);
    34                 Builtin.WriteLine(" (expected: 8)");
     32                Console.Write("2*2 + 2*2 = ");
     33                Console.Write(2*2 + 2*2);
     34                Console.WriteLine(" (expected: 8)");
    3535
    3636                -- Test subtraction, multiplication and precedence.
    37                 Builtin.Write("1111 - 1 - 10 - 10*10 - 10*10*10 = ");
    38                 Builtin.Write(1111 - 1 - 10 - 10*10 - 10*10*10);
    39                 Builtin.WriteLine(" (expected: 0)");
     37                Console.Write("1111 - 1 - 10 - 10*10 - 10*10*10 = ");
     38                Console.Write(1111 - 1 - 10 - 10*10 - 10*10*10);
     39                Console.WriteLine(" (expected: 0)");
    4040
    4141                -- Test parenthesized sub-expressions.
    42                 Builtin.Write("10 * (1 - 1) = ");
    43                 Builtin.Write(10 * (1 - 1));
    44                 Builtin.WriteLine(" (expected: 0)");
     42                Console.Write("10 * (1 - 1) = ");
     43                Console.Write(10 * (1 - 1));
     44                Console.WriteLine(" (expected: 0)");
    4545
    4646                -- Test unary plus and minus.
    47                 Builtin.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = ");
    48                 Builtin.Write((+1) - (-1) - (+(+1)) + (+(-1)));
    49                 Builtin.WriteLine(" (expected: 0)");
     47                Console.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = ");
     48                Console.Write((+1) - (-1) - (+(+1)) + (+(-1)));
     49                Console.WriteLine(" (expected: 0)");
    5050
    5151                -- Test signed multiplication.
    52                 Builtin.Write("+1 * +1 = ");
    53                 Builtin.Write(+1 * +1);
    54                 Builtin.WriteLine(" (expected: 1)");
     52                Console.Write("+1 * +1 = ");
     53                Console.Write(+1 * +1);
     54                Console.WriteLine(" (expected: 1)");
    5555
    56                 Builtin.Write("-1 * -1 = ");
    57                 Builtin.Write(-1 * -1);
    58                 Builtin.WriteLine(" (expected: 1)");
     56                Console.Write("-1 * -1 = ");
     57                Console.Write(-1 * -1);
     58                Console.WriteLine(" (expected: 1)");
    5959
    60                 Builtin.Write("+1 * -1 = ");
    61                 Builtin.Write(+1 * -1);
    62                 Builtin.WriteLine(" (expected: -1)");
     60                Console.Write("+1 * -1 = ");
     61                Console.Write(+1 * -1);
     62                Console.WriteLine(" (expected: -1)");
    6363
    64                 Builtin.Write("-1 * +1 = ");
    65                 Builtin.Write(-1 * +1);
    66                 Builtin.WriteLine(" (expected: -1)");
     64                Console.Write("-1 * +1 = ");
     65                Console.Write(-1 * +1);
     66                Console.WriteLine(" (expected: -1)");
    6767
    6868                -- Test multiplication with large result.
    69                 Builtin.Write("1000000 * 1000000 * 1000000 * 1000000 = ");
    70                 Builtin.Write(1000000 * 1000000 * 1000000 * 1000000);
    71                 Builtin.WriteLine(" (expected: 1000000000000000000000000)");
     69                Console.Write("1000000 * 1000000 * 1000000 * 1000000 = ");
     70                Console.Write(1000000 * 1000000 * 1000000 * 1000000);
     71                Console.WriteLine(" (expected: 1000000000000000000000000)");
    7272
    7373                -- Test large literals.
    74                 Builtin.Write("1000000000000000000000000 = ");
    75                 Builtin.Write(1000000000000000000000000);
    76                 Builtin.WriteLine(" (expected: 1000000000000000000000000)");
     74                Console.Write("1000000000000000000000000 = ");
     75                Console.Write(1000000000000000000000000);
     76                Console.WriteLine(" (expected: 1000000000000000000000000)");
    7777
    7878                -- Test large factorials.
    7979                var n : int;
    8080
    81                 Builtin.WriteLine("Factorials:");
     81                Console.WriteLine("Factorials:");
    8282                n = 1;
    8383                while n <= 40 do
    84                         Builtin.WriteLine(Factorial(n));
     84                        Console.WriteLine(Factorial(n));
    8585                        n = n + 1;
    8686                end
  • uspace/dist/src/sysel/demos/array.sy

    r1614ce3 rb64eac6  
    4040                i = 0;
    4141                while i < 3 do
    42                         Builtin.WriteLine(a[i, 0]);
     42                        Console.WriteLine(a[i, 0]);
    4343                        i = i + 1;
    4444                end
  • uspace/dist/src/sysel/demos/autobox.sy

    r1614ce3 rb64eac6  
    3939                --
    4040                b = true;
    41                 Builtin.WriteLine(b.Value);
     41                Console.WriteLine(b.Value);
    4242                c = 'a';
    43                 Builtin.WriteLine(c.Value);
     43                Console.WriteLine(c.Value);
    4444                i = 1;
    45                 Builtin.WriteLine(i.Value);
     45                Console.WriteLine(i.Value);
    4646                s = "Hello";
    47                 Builtin.WriteLine(s.Value);
     47                Console.WriteLine(s.Value);
    4848
    4949                -- Anything can be converted to Object.
  • uspace/dist/src/sysel/demos/count.sy

    r1614ce3 rb64eac6  
    3333                i = a;
    3434                while i < b do
    35                         Builtin.WriteLine(i);
     35                        Console.WriteLine(i);
    3636                        i = i + 1;
    3737                end
  • uspace/dist/src/sysel/demos/ctor.sy

    r1614ce3 rb64eac6  
    3232
    3333                a = new A(1);
    34                 Builtin.Write("a.v = ");
    35                 Builtin.WriteLine(a.v);
     34                Console.Write("a.v = ");
     35                Console.WriteLine(a.v);
    3636        end
    3737end
     
    4141
    4242        new(i : int) is
    43                 Builtin.WriteLine("A.new()");
     43                Console.WriteLine("A.new()");
    4444                v = i;
    4545        end
  • uspace/dist/src/sysel/demos/deleg.sy

    r1614ce3 rb64eac6  
    5555        -- Function having delegate as the first parameger
    5656        fun Operate(op : BinaryOp; opName : string) is
    57                 Builtin.Write(opName + "(1, 2): ");
    58                 Builtin.WriteLine(op(1, 2));
     57                Console.Write(opName + "(1, 2): ");
     58                Console.WriteLine(op(1, 2));
    5959        end
    6060
  • uspace/dist/src/sysel/demos/enum.sy

    r1614ce3 rb64eac6  
    3131                var color : ChessColor;
    3232
    33                 Builtin.WriteLine("Set color to ChessColor.Black.");
     33                Console.WriteLine("Set color to ChessColor.Black.");
    3434                color = ChessColor.Black;
    3535
    36                 Builtin.Write("Test color == ChessColor.Black.. ");
     36                Console.Write("Test color == ChessColor.Black.. ");
    3737                if color == ChessColor.Black then
    38                         Builtin.WriteLine("True - OK");
     38                        Console.WriteLine("True - OK");
    3939                else
    40                         Builtin.WriteLine("False - Fail!");
     40                        Console.WriteLine("False - Fail!");
    4141                        raise new Error.Base();
    4242                end
    4343
    44                 Builtin.Write("Test color != ChessColor.Black.. ");
     44                Console.Write("Test color != ChessColor.Black.. ");
    4545                if color != ChessColor.Black then
    46                         Builtin.WriteLine("True - Fail!");
     46                        Console.WriteLine("True - Fail!");
    4747                        raise new Error.Base();
    4848                else
    49                         Builtin.WriteLine("False - OK");
     49                        Console.WriteLine("False - OK");
    5050                end
    5151
    52                 Builtin.Write("Test color == ChessColor.White.. ");
     52                Console.Write("Test color == ChessColor.White.. ");
    5353                if color == ChessColor.White then
    54                         Builtin.WriteLine("True - Fail!");
     54                        Console.WriteLine("True - Fail!");
    5555                        raise new Error.Base();
    5656                else
    57                         Builtin.WriteLine("False - OK");
     57                        Console.WriteLine("False - OK");
    5858                end
    5959
    60                 Builtin.Write("Test color != ChessColor.White.. ");
     60                Console.Write("Test color != ChessColor.White.. ");
    6161                if color != ChessColor.White then
    62                         Builtin.WriteLine("True - OK");
     62                        Console.WriteLine("True - OK");
    6363                else
    64                         Builtin.WriteLine("False - Fail!");
     64                        Console.WriteLine("False - Fail!");
    6565                        raise new Error.Base();
    6666                end
    6767
    68                 Builtin.WriteLine("Success");
     68                Console.WriteLine("Success");
    6969
    7070                -- Test enum declared in non-CSI scope
  • uspace/dist/src/sysel/demos/except.sy

    r1614ce3 rb64eac6  
    2929class ExceptionDemo is
    3030        fun foo(), static is
    31                 Builtin.WriteLine("Entered foo().");
     31                Console.WriteLine("Entered foo().");
    3232                raise new BaseException();
    3333        end
     
    3838                        foo();
    3939                except e : DerivedException do
    40                         Builtin.WriteLine("Caught derived exception.");
     40                        Console.WriteLine("Caught derived exception.");
    4141                except e : BaseException do
    42                         Builtin.WriteLine("Caught base exception.");
     42                        Console.WriteLine("Caught base exception.");
    4343                finally do
    44                         Builtin.WriteLine("Finally.");
     44                        Console.WriteLine("Finally.");
    4545                end
    4646        end
  • uspace/dist/src/sysel/demos/gen.sy

    r1614ce3 rb64eac6  
    3131class GenericsDemo is
    3232        fun Main(), static is
    33                 Builtin.WriteLine("Let's try some generics.");
     33                Console.WriteLine("Let's try some generics.");
    3434
    3535                var f : B/int/string;
  • uspace/dist/src/sysel/demos/hello.sy

    r1614ce3 rb64eac6  
    2929class HelloWorld is
    3030        fun Main(), static is
    31                 Builtin.WriteLine("Hello world!");
     31                Console.WriteLine("Hello world!");
    3232        end
    3333end
  • uspace/dist/src/sysel/demos/htxtfile.sy

    r1614ce3 rb64eac6  
    4545                while not in_file.EOF do
    4646                        line = in_file.ReadLine();
    47                         Builtin.WriteLine(name + ": " + line);
     47                        Console.WriteLine(name + ": " + line);
    4848                        out_file.WriteLine(name + ": " + line);
    4949                end
  • uspace/dist/src/sysel/demos/iface.sy

    r1614ce3 rb64eac6  
    4343                f = g as Foo;
    4444
    45                 Builtin.WriteLine(g.a());
     45                Console.WriteLine(g.a());
    4646        end
    4747end
  • uspace/dist/src/sysel/demos/inherit.sy

    r1614ce3 rb64eac6  
    2929class A is
    3030        fun Foo() is
    31                 Builtin.WriteLine("A.Foo()");
     31                Console.WriteLine("A.Foo()");
    3232        end
    3333end
     
    3535class B : A is
    3636        fun Foo() is
    37                 Builtin.WriteLine("B.Foo()");
     37                Console.WriteLine("B.Foo()");
    3838        end
    3939end
  • uspace/dist/src/sysel/demos/list.sy

    r1614ce3 rb64eac6  
    4343                e = list.GetEnumerator();
    4444                while e.MoveNext() do
    45                         Builtin.WriteLine(e.Data);
     45                        Console.WriteLine(e.Data);
    4646                end
    4747        end
  • uspace/dist/src/sysel/demos/map.sy

    r1614ce3 rb64eac6  
    4343                e = map.GetEnumerator();
    4444                while e.MoveNext() do
    45                         Builtin.Write(e.Data);
    46                         Builtin.Write(" -> ");
    47                         Builtin.WriteLine(map[e.Data]);
     45                        Console.Write(e.Data);
     46                        Console.Write(" -> ");
     47                        Console.WriteLine(map[e.Data]);
    4848                end
    4949        end
  • uspace/dist/src/sysel/demos/property.sy

    r1614ce3 rb64eac6  
    3333        prop X : int is
    3434                get is
    35                         Builtin.Write("Getting value of X which is ");
    36                         Builtin.WriteLine(x);
     35                        Console.Write("Getting value of X which is ");
     36                        Console.WriteLine(x);
    3737                        return x;
    3838                end
    3939
    4040                set value is
    41                         Builtin.Write("Setting value of X to ");
    42                         Builtin.WriteLine(value);
     41                        Console.Write("Setting value of X to ");
     42                        Console.WriteLine(value);
    4343                        x = value;
    4444                end
     45        end
     46
     47        -- Test accessing property via an unqualified name
     48        fun TestUnqualPropAcc() is
     49                var i : int;
     50
     51                X = 1;
     52                i = X;
     53
     54                Console.Write("TestUnqualPropAcc(): Got ");
     55                Console.WriteLine(i);
    4556        end
    4657
     
    5162        prop self[index : int] : int is
    5263                get is
    53                         Builtin.Write("Getting property with index ");
    54                         Builtin.Write(index);
    55                         Builtin.Write(" which is ");
    56                         Builtin.WriteLine(iprops[index]);
     64                        Console.Write("Getting property with index ");
     65                        Console.Write(index);
     66                        Console.Write(" which is ");
     67                        Console.WriteLine(iprops[index]);
    5768
    5869                        return iprops[index];
     
    6071
    6172                set value is
    62                         Builtin.Write("Setting property with index ");
    63                         Builtin.Write(index);
    64                         Builtin.Write(" to ");
    65                         Builtin.WriteLine(value);
     73                        Console.Write("Setting property with index ");
     74                        Console.Write(index);
     75                        Console.Write(" to ");
     76                        Console.WriteLine(value);
    6677
    6778                        iprops[index] = value;
     
    8293        prop B : Bar is
    8394                get is
    84                         Builtin.WriteLine("Getting B");
     95                        Console.WriteLine("Getting B");
    8596                        return bprop;
    8697                end
    8798                set value is
    88                         Builtin.WriteLine("Setting B");
     99                        Console.WriteLine("Setting B");
    89100                        bprop = value;
    90101                end
     
    110121                i = a.X;
    111122
    112                 Builtin.Write("Main(): Got ");
    113                 Builtin.WriteLine(i);
     123                Console.Write("Main(): Got ");
     124                Console.WriteLine(i);
     125
     126                a.TestUnqualPropAcc();
    114127
    115128                a.iprops = new int[5];
     
    121134                i = a[1];
    122135
    123                 Builtin.Write("Main(): Got ");
    124                 Builtin.WriteLine(i);
     136                Console.Write("Main(): Got ");
     137                Console.WriteLine(i);
    125138
    126139                -- Property field access
     
    132145                a.bprop = b;
    133146
    134                 Builtin.WriteLine(a.bprop.i);
     147                Console.WriteLine(a.bprop.i);
    135148                a.bprop.i = 2;
    136                 Builtin.WriteLine(a.bprop.i);
     149                Console.WriteLine(a.bprop.i);
    137150        end
    138151end
  • uspace/dist/src/sysel/demos/string.sy

    r1614ce3 rb64eac6  
    3030        fun Main(), static is
    3131                -- Concatenate some strings.
    32                 Builtin.WriteLine("One-" + "two-" + "three!");
     32                Console.WriteLine("One-" + "two-" + "three!");
    3333
    3434                -- Extract characters from a string.
     
    3636                i = 0;
    3737                while i < 5 do
    38                         Builtin.WriteLine("ABCDE"[i]);
     38                        Console.WriteLine("ABCDE"[i]);
    3939                        i = i + 1;
    4040                end
    4141
    42                 Builtin.WriteLine("Abracadabra".Slice(2, 4));
     42                Console.WriteLine("Abracadabra".Slice(2, 4));
    4343        end
    4444end
  • uspace/dist/src/sysel/demos/svar.sy

    r1614ce3 rb64eac6  
    3131                -- Test static member variable
    3232                A.B.a = 1;
    33                 Builtin.WriteLine(A.B.a);
     33                Console.WriteLine(A.B.a);
    3434                A.B.a = 2;
    35                 Builtin.WriteLine(A.B.a);
     35                Console.WriteLine(A.B.a);
    3636
    3737                -- Test static property
    3838                A.B.P = 1;
    39                 Builtin.WriteLine(A.B.P);
     39                Console.WriteLine(A.B.P);
    4040                A.B.P = 2;
    41                 Builtin.WriteLine(A.B.P);
     41                Console.WriteLine(A.B.P);
    4242        end
    4343end
  • uspace/dist/src/sysel/demos/varargs.sy

    r1614ce3 rb64eac6  
    4444                        -- implemented...
    4545                        do
    46                                 Builtin.WriteLine(args[i]);
     46                                Console.WriteLine(args[i]);
    4747                        except e : Error.OutOfBounds do
    4848                                error = true;
  • uspace/srv/hid/console/gcons.c

    r1614ce3 rb64eac6  
    285285        ssize_t nx = (ssize_t) mouse_x + dx;
    286286        ssize_t ny = (ssize_t) mouse_y + dy;
    287 
    288         if (!use_gcons)
     287       
     288        /* Until gcons is initalized we don't have the screen resolution */
     289        if (xres == 0 || yres == 0)
    289290                return;
    290291       
Note: See TracChangeset for help on using the changeset viewer.