-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathframes.h
111 lines (95 loc) · 2.61 KB
/
frames.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Copyright 2001-2004 David Abrahams.
Copyright 2022 René Ferdinand Rivera Morell
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
*/
#ifndef B2_FRAMES_H
#define B2_FRAMES_H
#include "config.h"
#include "lists.h"
#include "modules.h"
#include "object.h"
#include "value.h"
typedef struct frame FRAME;
void frame_init(FRAME *);
void frame_free(FRAME *);
struct frame
{
FRAME * prev;
FRAME * prev_user; /* The nearest enclosing frame for which
module->user_module is true. */
LOL args[1];
module_t * module;
OBJECT * file;
int line;
char const * rulename;
#ifdef JAM_DEBUGGER
void * function;
#endif
inline frame() { frame_init(this); }
inline ~frame() { frame_free(this); }
inline frame(const frame & other)
: prev(other.prev)
, prev_user(other.prev_user)
, module(other.module)
, file(other.file)
, line(other.line)
, rulename(other.rulename)
#ifdef JAM_DEBUGGER
, function(other.function)
#endif
{
lol_init(args);
for (int32_t a = 0; a < other.args->count; ++a)
{
lol_add(args, list_copy(other.args->list[a]));
}
}
};
/* When a call into Python is in progress, this variable points to the bjam
* frame that was current at the moment of the call. When the call completes,
* the variable is not defined. Furthermore, if Jam calls Python which calls Jam
* and so on, this variable only keeps the most recent Jam frame.
*/
extern FRAME * frame_before_python_call;
namespace b2 { namespace jam {
struct module_scope
{
inline module_scope(FRAME * frame_, const char * module_name_)
: module_frame(frame_)
{
if (module_frame)
{
module_saved = module_frame->module;
module_frame->module
= b2::ensure_valid(bindmodule(value_ref(module_name_)));
}
}
inline ~module_scope()
{
if (module_frame && module_saved)
{
module_frame->module = b2::ensure_valid(module_saved);
}
}
inline value_ref name() const { return module_frame->module->name; }
inline FRAME * frame() const { return module_frame; }
inline operator module_ptr() const { return module_frame->module; }
private:
FRAME * module_frame = nullptr;
module_t * module_saved = nullptr;
};
struct module_scope_in_function
{
module_scope_in_function(FRAME * frame_, const char * module_name_);
~module_scope_in_function();
inline value_ref name() const { return module_frame->module->name; }
inline FRAME * frame() const { return module_frame; }
inline operator module_ptr() const { return module_frame->module; }
private:
FRAME * module_frame = nullptr;
module_t * saved_module = nullptr;
};
}} // namespace b2::jam
#endif