Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_hthread_misc.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Functions

DUK_INTERNAL void duk_hthread_terminate (duk_hthread *thr)
 
DUK_INTERNAL duk_activationduk_hthread_get_current_activation (duk_hthread *thr)
 
DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc (duk_hthread *thr, duk_activation *act)
 
DUK_INTERNAL void duk_hthread_sync_currpc (duk_hthread *thr)
 
DUK_INTERNAL void duk_hthread_sync_and_null_currpc (duk_hthread *thr)
 

Function Documentation

◆ duk_hthread_get_act_prev_pc()

DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc ( duk_hthread * thr,
duk_activation * act )

Definition at line 63 of file duktape-1.5.2/src-separate/duk_hthread_misc.c.

63 {
64 duk_instr_t *bcode;
66
67 DUK_ASSERT(thr != NULL);
68 DUK_ASSERT(act != NULL);
69 DUK_UNREF(thr);
70
71 if (act->func && DUK_HOBJECT_IS_COMPILEDFUNCTION(act->func)) {
73 ret = (duk_uint_fast32_t) (act->curr_pc - bcode);
74 if (ret > 0) {
75 ret--;
76 }
77 return ret;
78 }
79 return 0;
80}
duk_uint32_t duk_uint_fast32_t
#define DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(heap, h)
#define DUK_HOBJECT_IS_COMPILEDFUNCTION(h)
duk_uint32_t duk_instr_t
#define NULL
Definition gmacros.h:924

References duk_activation::curr_pc, DUK_ASSERT, DUK_HCOMPILEDFUNCTION_GET_CODE_BASE, DUK_HOBJECT_IS_COMPILEDFUNCTION, DUK_UNREF, duk_activation::func, duk_hthread::heap, and NULL.

◆ duk_hthread_get_current_activation()

DUK_INTERNAL duk_activation * duk_hthread_get_current_activation ( duk_hthread * thr)

Definition at line 36 of file duktape-1.5.2/src-separate/duk_hthread_misc.c.

36 {
37 DUK_ASSERT(thr != NULL);
38
39 if (thr->callstack_top > 0) {
40 return thr->callstack + thr->callstack_top - 1;
41 } else {
42 return NULL;
43 }
44}

References duk_hthread::callstack, duk_hthread::callstack_top, DUK_ASSERT, and NULL.

◆ duk_hthread_sync_and_null_currpc()

DUK_INTERNAL void duk_hthread_sync_and_null_currpc ( duk_hthread * thr)

Definition at line 96 of file duktape-1.5.2/src-separate/duk_hthread_misc.c.

96 {
97 duk_activation *act;
98
99 DUK_ASSERT(thr != NULL);
100
101 if (thr->ptr_curr_pc != NULL) {
102 /* ptr_curr_pc != NULL only when bytecode executor is active. */
103 DUK_ASSERT(thr->callstack_top > 0);
104 act = thr->callstack + thr->callstack_top - 1;
105 act->curr_pc = *thr->ptr_curr_pc;
106 thr->ptr_curr_pc = NULL;
107 }
108}

References duk_hthread::callstack, duk_hthread::callstack_top, duk_activation::curr_pc, DUK_ASSERT, NULL, and duk_hthread::ptr_curr_pc.

◆ duk_hthread_sync_currpc()

DUK_INTERNAL void duk_hthread_sync_currpc ( duk_hthread * thr)

Definition at line 83 of file duktape-1.5.2/src-separate/duk_hthread_misc.c.

83 {
84 duk_activation *act;
85
86 DUK_ASSERT(thr != NULL);
87
88 if (thr->ptr_curr_pc != NULL) {
89 /* ptr_curr_pc != NULL only when bytecode executor is active. */
90 DUK_ASSERT(thr->callstack_top > 0);
91 act = thr->callstack + thr->callstack_top - 1;
92 act->curr_pc = *thr->ptr_curr_pc;
93 }
94}

References duk_hthread::callstack, duk_hthread::callstack_top, duk_activation::curr_pc, DUK_ASSERT, NULL, and duk_hthread::ptr_curr_pc.

◆ duk_hthread_terminate()

DUK_INTERNAL void duk_hthread_terminate ( duk_hthread * thr)

Definition at line 7 of file duktape-1.5.2/src-separate/duk_hthread_misc.c.

7 {
8 DUK_ASSERT(thr != NULL);
9
10 /* Order of unwinding is important */
11
13
14 duk_hthread_callstack_unwind(thr, 0); /* side effects, possibly errors */
15
16 thr->valstack_bottom = thr->valstack;
17 duk_set_top((duk_context *) thr, 0); /* unwinds valstack, updating refcounts */
18
20
21 /* Here we could remove references to built-ins, but it may not be
22 * worth the effort because built-ins are quite likely to be shared
23 * with another (unterminated) thread, and terminated threads are also
24 * usually garbage collected quite quickly. Also, doing DECREFs
25 * could trigger finalization, which would run on the current thread
26 * and have access to only some of the built-ins. Garbage collection
27 * deals with this correctly already.
28 */
29
30 /* XXX: Shrink the stacks to minimize memory usage? May not
31 * be worth the effort because terminated threads are usually
32 * garbage collected quite soon.
33 */
34}
DUK_INTERNAL_DECL void duk_hthread_catchstack_unwind(duk_hthread *thr, duk_size_t new_top)
DUK_INTERNAL_DECL void duk_hthread_callstack_unwind(duk_hthread *thr, duk_size_t new_top)
DUK_EXTERNAL void duk_set_top(duk_context *ctx, duk_idx_t index)
#define DUK_HTHREAD_STATE_TERMINATED

References DUK_ASSERT, duk_hthread_callstack_unwind(), duk_hthread_catchstack_unwind(), DUK_HTHREAD_STATE_TERMINATED, duk_set_top(), NULL, duk_hthread::state, duk_hthread::valstack, and duk_hthread::valstack_bottom.