/
mercury.c
132 lines (107 loc) · 3.09 KB
/
mercury.c
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1999-2003, 2006, 2011 The University of Melbourne.
// Copyright (C) 2016, 2018 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// mercury.c - This file defines the builtin functions, constants, etc. that
// are used when generating high-level C code.
// (For the low-level C code, see mercury_imp.h.)
#ifndef MR_HIGHLEVEL_CODE
#include "mercury_imp.h"
#endif
#include "mercury.h"
#include "mercury_type_info.h" // for MR_TYPECTOR_REP*
#include "mercury_type_desc.h" // for MR_TypeCtorDesc
#include "mercury_misc.h" // for MR_fatal_error()
#include "mercury_heap.h" // for MR_create[1-3]() prototypes
#include "mercury_builtin_types.h"
#ifdef MR_HIGHLEVEL_CODE
////////////////////////////////////////////////////////////////////////////
// Variable definitions.
#ifdef MR_NATIVE_GC
void *mercury__private_builtin__stack_chain;
#endif
MR_Word mercury__private_builtin__dummy_var;
////////////////////////////////////////////////////////////////////////////
// Provide definitions for functions declared `extern inline'.
// Note that this code duplicates the code in mercury.h/mercury_heap.h.
MR_OUTLINE_DEFN(
MR_Word
MR_create1_func(MR_Word w1)
,
{
MR_Word *p = (MR_Word *) MR_new_object(MR_Word, 1 * sizeof(MR_Word),
NULL, "create1");
p[0] = w1;
return (MR_Word) p;
}
)
MR_OUTLINE_DEFN(
MR_Word
MR_create2_func(MR_Word w1, MR_Word w2)
,
{
MR_Word *p = (MR_Word *) MR_new_object(MR_Word, 2 * sizeof(MR_Word),
NULL, "create2");
p[0] = w1;
p[1] = w2;
return (MR_Word) p;
}
)
MR_OUTLINE_DEFN(
MR_Word
MR_create3_func(MR_Word w1, MR_Word w2, MR_Word w3)
,
{
MR_Word *p = (MR_Word *) MR_new_object(MR_Word, 3 * sizeof(MR_Word),
NULL, "create3");
p[0] = w1;
p[1] = w2;
p[2] = w3;
return (MR_Word) p;
}
)
#if defined(MR_BOXED_FLOAT) && !defined(MR_GNUC)
MR_OUTLINE_DEFN(
MR_Box
MR_box_float(MR_Float f)
,
{
MR_Float *ptr;
MR_make_hp_float_aligned();
ptr = (MR_Float *) MR_new_object_atomic(MR_Float, sizeof(MR_Float),
MR_ALLOC_SITE_FLOAT, NULL);
*ptr = f;
return (MR_Box) ptr;
}
)
#endif // MR_BOXED_FLOAT && !MR_GNUC
#if defined(MR_BOXED_INT64S) && !defined(MR_GNUC)
MR_OUTLINE_DEFN(
MR_Box
MR_box_int64(int64_t i)
,
{
int64_t *ptr;
MR_make_hp_int64_aligned();
ptr = MR_new_object_atomic(int64_t, sizeof(int64_t),
MR_ALLOC_SITE_INT64, NULL);
*ptr = i;
return (MR_Box) ptr;
}
)
MR_OUTLINE_DEFN(
MR_Box
MR_box_uint64(uint64_t i)
,
{
uint64_t *ptr;
MR_make_hp_uint64_aligned();
ptr = MR_new_object_atomic(uint64_t, sizeof(uint64_t),
MR_ALLOC_SITE_UINT64, NULL);
*ptr = i;
return (MR_Box) ptr;
}
)
#endif // MR_BOXED_INT64S && !MR_GNUC
#endif // ! MR_HIGHLEVEL_CODE
////////////////////////////////////////////////////////////////////////////