[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 |
|
---|
[d0febca] | 46 | /** Procedure activation record
|
---|
[09ababb7] | 47 | *
|
---|
[d0febca] | 48 | * A procedure can be a member function, a named property or an indexed
|
---|
| 49 | * property. A procedure activation record is created whenever a procedure
|
---|
| 50 | * is invoked.
|
---|
[09ababb7] | 51 | */
|
---|
[d0febca] | 52 | typedef struct run_proc_ar {
|
---|
| 53 | /** Object on which the procedure is being invoked or @c NULL. */
|
---|
[fa36f29] | 54 | struct rdata_var *obj;
|
---|
| 55 |
|
---|
[39e8406] | 56 | /** Procedure being invoked */
|
---|
| 57 | struct stree_proc *proc;
|
---|
[09ababb7] | 58 |
|
---|
| 59 | /** Block activation records */
|
---|
| 60 | list_t block_ar; /* of run_block_ar_t */
|
---|
[fa36f29] | 61 |
|
---|
[d0febca] | 62 | /** Procedure return value or @c NULL if not set. */
|
---|
[fa36f29] | 63 | struct rdata_item *retval;
|
---|
[d0febca] | 64 | } run_proc_ar_t;
|
---|
[09ababb7] | 65 |
|
---|
[fa36f29] | 66 | /** Bailout mode
|
---|
| 67 | *
|
---|
| 68 | * Determines whether control is bailing out of a statement, function, etc.
|
---|
| 69 | */
|
---|
| 70 | typedef enum {
|
---|
| 71 | /** Normal execution */
|
---|
| 72 | bm_none,
|
---|
| 73 |
|
---|
| 74 | /** Break from statement */
|
---|
| 75 | bm_stat,
|
---|
| 76 |
|
---|
[d0febca] | 77 | /** Return from procedure */
|
---|
| 78 | bm_proc,
|
---|
[94d484a] | 79 |
|
---|
| 80 | /** Exception */
|
---|
[1ebc1a62] | 81 | bm_exc,
|
---|
| 82 |
|
---|
| 83 | /** Unrecoverable runtime error */
|
---|
| 84 | bm_error
|
---|
[94d484a] | 85 | } run_bailout_mode_t;
|
---|
[fa36f29] | 86 |
|
---|
[09ababb7] | 87 | /** Thread activation record
|
---|
| 88 | *
|
---|
| 89 | * We can walk the list of function ARs to get a function call backtrace.
|
---|
| 90 | */
|
---|
| 91 | typedef struct run_thread_ar {
|
---|
[fa36f29] | 92 | /** Function activation records */
|
---|
[d0febca] | 93 | list_t proc_ar; /* of run_proc_ar_t */
|
---|
[fa36f29] | 94 |
|
---|
| 95 | /** Bailout mode */
|
---|
[94d484a] | 96 | run_bailout_mode_t bo_mode;
|
---|
| 97 |
|
---|
[051bc69a] | 98 | /** Exception cspan */
|
---|
| 99 | struct cspan *exc_cspan;
|
---|
| 100 |
|
---|
[94d484a] | 101 | /** Exception payload */
|
---|
| 102 | struct rdata_value *exc_payload;
|
---|
[1ebc1a62] | 103 |
|
---|
| 104 | /** @c b_true if a run-time error occured. */
|
---|
| 105 | bool_t error;
|
---|
[09ababb7] | 106 | } run_thread_ar_t;
|
---|
| 107 |
|
---|
| 108 | /** Runner state object */
|
---|
| 109 | typedef struct run {
|
---|
| 110 | /** Code of the program being executed */
|
---|
| 111 | struct stree_program *program;
|
---|
| 112 |
|
---|
| 113 | /** Thread-private state */
|
---|
| 114 | run_thread_ar_t *thread_ar;
|
---|
[c5cb943d] | 115 |
|
---|
| 116 | /** Global state */
|
---|
| 117 | struct rdata_var *gdata;
|
---|
[09ababb7] | 118 | } run_t;
|
---|
| 119 |
|
---|
| 120 | #endif
|
---|