[09ababb7] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #ifndef RUN_T_H_
|
---|
| 30 | #define RUN_T_H_
|
---|
| 31 |
|
---|
[37f527b] | 32 | #include "intmap_t.h"
|
---|
[09ababb7] | 33 | #include "list_t.h"
|
---|
| 34 |
|
---|
| 35 | /** Block activation record
|
---|
| 36 | *
|
---|
| 37 | * One block AR is created for each block that we enter. A variable declaration
|
---|
| 38 | * statement inserts the variable here. Upon exiting the block we pop from the
|
---|
| 39 | * stack, thus all the variables declared in that block are forgotten.
|
---|
| 40 | */
|
---|
| 41 | typedef struct run_block_ar {
|
---|
| 42 | /** Variables in this block */
|
---|
| 43 | intmap_t vars; /* of rdata_var_t */
|
---|
| 44 | } run_block_ar_t;
|
---|
| 45 |
|
---|
[fa36f29] | 46 |
|
---|
[d0febca] | 47 | /** Procedure activation record
|
---|
[09ababb7] | 48 | *
|
---|
[d0febca] | 49 | * A procedure can be a member function, a named property or an indexed
|
---|
| 50 | * property. A procedure activation record is created whenever a procedure
|
---|
| 51 | * is invoked.
|
---|
[09ababb7] | 52 | */
|
---|
[d0febca] | 53 | typedef struct run_proc_ar {
|
---|
| 54 | /** Object on which the procedure is being invoked or @c NULL. */
|
---|
[fa36f29] | 55 | struct rdata_var *obj;
|
---|
| 56 |
|
---|
[39e8406] | 57 | /** Procedure being invoked */
|
---|
| 58 | struct stree_proc *proc;
|
---|
[09ababb7] | 59 |
|
---|
| 60 | /** Block activation records */
|
---|
| 61 | list_t block_ar; /* of run_block_ar_t */
|
---|
[fa36f29] | 62 |
|
---|
[d0febca] | 63 | /** Procedure return value or @c NULL if not set. */
|
---|
[fa36f29] | 64 | struct rdata_item *retval;
|
---|
[d0febca] | 65 | } run_proc_ar_t;
|
---|
[09ababb7] | 66 |
|
---|
[fa36f29] | 67 | /** Bailout mode
|
---|
| 68 | *
|
---|
| 69 | * Determines whether control is bailing out of a statement, function, etc.
|
---|
| 70 | */
|
---|
| 71 | typedef enum {
|
---|
| 72 | /** Normal execution */
|
---|
| 73 | bm_none,
|
---|
| 74 |
|
---|
| 75 | /** Break from statement */
|
---|
| 76 | bm_stat,
|
---|
| 77 |
|
---|
[d0febca] | 78 | /** Return from procedure */
|
---|
| 79 | bm_proc,
|
---|
[94d484a] | 80 |
|
---|
| 81 | /** Exception */
|
---|
[1ebc1a62] | 82 | bm_exc,
|
---|
| 83 |
|
---|
| 84 | /** Unrecoverable runtime error */
|
---|
| 85 | bm_error
|
---|
[94d484a] | 86 | } run_bailout_mode_t;
|
---|
[fa36f29] | 87 |
|
---|
[09ababb7] | 88 | /** Thread activation record
|
---|
| 89 | *
|
---|
| 90 | * We can walk the list of function ARs to get a function call backtrace.
|
---|
| 91 | */
|
---|
| 92 | typedef struct run_thread_ar {
|
---|
[fa36f29] | 93 | /** Function activation records */
|
---|
[d0febca] | 94 | list_t proc_ar; /* of run_proc_ar_t */
|
---|
[fa36f29] | 95 |
|
---|
| 96 | /** Bailout mode */
|
---|
[94d484a] | 97 | run_bailout_mode_t bo_mode;
|
---|
| 98 |
|
---|
| 99 | /** Exception payload */
|
---|
| 100 | struct rdata_value *exc_payload;
|
---|
[1ebc1a62] | 101 |
|
---|
| 102 | /** @c b_true if a run-time error occured. */
|
---|
| 103 | bool_t error;
|
---|
[09ababb7] | 104 | } run_thread_ar_t;
|
---|
| 105 |
|
---|
| 106 | /** Runner state object */
|
---|
| 107 | typedef struct run {
|
---|
| 108 | /** Code of the program being executed */
|
---|
| 109 | struct stree_program *program;
|
---|
| 110 |
|
---|
| 111 | /** Thread-private state */
|
---|
| 112 | run_thread_ar_t *thread_ar;
|
---|
| 113 | } run_t;
|
---|
| 114 |
|
---|
| 115 | #endif
|
---|