~zarevucky-jiri/helenos/golang2

« back to all changes in this revision

Viewing changes to uspace/runtime/go/core/src/gccgo_defer.c

  • Committer: Ji?? Z?rev?cky
  • Date: 2013-07-22 13:41:46 UTC
  • Revision ID: zarevucky.jiri@gmail.com-20130722134146-nmzo0ccf7pscuqab
More stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
typedef void (*fn_t) (void *); 
3
 
 
4
 
struct defer_stack {
5
 
        fn_t fn;
6
 
        void *arg;
7
 
        void *frame;
8
 
        struct defer_stack *prev;
9
 
        struct defer_stack *next;
10
 
};
11
 
 
12
 
// FIXME: invisible for the GC.
13
 
static fibril_local defer_stack *dstack = NULL;
14
 
 
 
2
#include "gocore.h"
 
3
 
 
4
void __go_panic(struct __go_empty_interface arg);
 
5
void __go_defer(void *frame, void (*pfn) (void *), void *arg);
 
6
void __go_undefer(void *frame);
 
7
bool __go_set_defer_retaddr(void *retaddr);
 
8
struct __go_empty_interface __go_recover();
 
9
struct __go_empty_interface __go_deferred_recover();
 
10
bool __go_can_recover(const void* retaddr);
 
11
void *__go_return_address(intgo blah);
 
12
void __go_check_defer(void *frame);
 
13
void __go_runtime_error (int32 i);
15
14
 
16
15
void
17
16
__go_panic(struct __go_empty_interface arg)
18
17
{
19
 
        
 
18
        gocore_panicgo(arg);
20
19
}
21
20
 
22
21
void
23
22
__go_defer(void *frame, void (*pfn) (void *), void *arg)
24
23
{
25
 
        if (dstack == NULL) {
26
 
                dstack = gocore_mallocgc(sizeof(struct defer_stack));
27
 
        }
28
 
        if (dstack->next == NULL) {
29
 
                dstack->next = gocore_mallocgc(sizeof(struct defer_stack));
30
 
                dstack->next->prev = dstack;
31
 
        }
32
 
        dstack = dstack->next;
33
 
        dstack->fn = pfn;
34
 
        dstack->arg = arg;
35
 
        dstack->frame = frame;
 
24
        gocore_defer(frame, void (*pfn) (void *), void *arg);
36
25
}
37
26
 
38
27
void
39
28
__go_undefer(void *frame)
40
29
{
41
 
        while (dstack->frame == frame) {
42
 
                dstack = dstack->prev;
43
 
                dstack->next->fn(dstack->next->arg);
44
 
        }
 
30
        gocore_undefer(frame);
45
31
}
46
32
 
47
33
/* This function is called to record the address to which the deferred
114
100
        case SLICE_INDEX_OUT_OF_BOUNDS:
115
101
        case ARRAY_INDEX_OUT_OF_BOUNDS:
116
102
        case STRING_INDEX_OUT_OF_BOUNDS:
117
 
                runtime_panic("index out of range");
 
103
                gocore_panic("index out of range");
118
104
 
119
105
        case SLICE_SLICE_OUT_OF_BOUNDS:
120
106
        case ARRAY_SLICE_OUT_OF_BOUNDS:
121
107
        case STRING_SLICE_OUT_OF_BOUNDS:
122
 
                runtime_panic("slice bounds out of range");
 
108
                gocore_panic("slice bounds out of range");
123
109
 
124
110
        case NIL_DEREFERENCE:
125
 
                runtime_panic("nil pointer dereference");
 
111
                gocore_panic("nil pointer dereference");
126
112
 
127
113
        case MAKE_SLICE_OUT_OF_BOUNDS:
128
 
                runtime_panic("make slice len or cap out of range");
 
114
                gocore_panic("make slice len or cap out of range");
129
115
 
130
116
        case MAKE_MAP_OUT_OF_BOUNDS:
131
 
                runtime_panic("make map len out of range");
 
117
                gocore_panic("make map len out of range");
132
118
 
133
119
        case MAKE_CHAN_OUT_OF_BOUNDS:
134
 
                runtime_panic("make chan len out of range");
 
120
                gocore_panic("make chan len out of range");
135
121
 
136
122
        case DIVISION_BY_ZERO:
137
 
                runtime_panic("integer divide by zero");
 
123
                gocore_panic("integer divide by zero");
138
124
 
139
125
        default:
140
 
                runtime_panic("unknown runtime error");
 
126
                gocore_panic("unknown runtime error");
141
127
        }
142
128
}