Skip to content

Commit 7d2f81a

Browse files
committed
value model
1 parent 4b718d7 commit 7d2f81a

File tree

5 files changed

+92
-12
lines changed

5 files changed

+92
-12
lines changed

doc/language/syntax/attributes.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,35 @@
44

55
[_fqname_](fqname.md) __(__ `(` [_argument_list_](argument_list.md) `)` __)?__
66

7+
78
## Semantics
89

910
If the [_fqname_](fqname.md) is a single name,
1011
then this attribute is required. A required attribute must be handled by the compiler.
1112
If the compiler does not know how to handle the attribute it is an error.
1213

13-
If the [_fqname_](fqname.md) has the `std` prefix
14+
If the [_fqname_](fqname.md) has the `std.` prefix
1415
it is a well-known optional attribute. These attributes don't change the semantic
1516
meaning of the program, instead they are directives to the compiler to create
1617
better code.
1718

1819
Other prefixes are attributes that are handled by specific compilers. Compilers
1920
should ignore any attributes that do not match their own prefix.
2021

21-
### abi()
22+
### abi(x)
2223
Make this function available for linking with an application written in a
2324
different language; using a different ABI (Application Binary Interface).
2425

25-
- __c__: Use the C ABI.
26-
- __cpp__: Use the C++ ABI.
26+
On a type this will change how the memory layout is for an object.
27+
28+
- "c": Use the C ABI. (same as aligned)
29+
- "c++": Use the C++ ABI. (same as aligned)
30+
- "aligned": Keep members in a struct in given order, and align members.
31+
- "reorder": Reorder members in a struct, pack while maintaining alignment. (default)
32+
- "pack": Keep members in a struct in given order, ignore natural alignment of members. This will
33+
cause member access to use possible slower, but valid, unaligned access.
34+
- "compress": Use niche-mask to further compress members in a struct. Access to members may
35+
require shifts and masks.
2736

2837
### no_return
2938
This function will not return.
@@ -37,22 +46,24 @@ Pre-condition is checked before calling the function.
3746
### post()
3847
Post-condition is checked after calling the function.
3948

49+
A post-condition on a type will run after an object is modified.
50+
4051

4152
### std.no_inline
4253
Calls to this function are never inlined.
4354

4455
This is a strong optimization lever:
4556
- It reduces code size by not inlining the code, which will reduce
46-
code-cache usage.
57+
instruction-cache usage.
4758
- It significantly reduce register pressure, which will reduce the
4859
amount of reads/writes to memory. And may in turn reduce size of the
4960
code; which in turn may allow more inlining.
5061

51-
### std.depricated, std.depricated()
62+
### std.depricated, std.depricated(msg)
5263
This function is depricated print a warning. A reason for deprication can
5364
be passed as a constant-string.
5465

55-
### std.discard
66+
### std.discard, std.discard(msg)
5667
The return value of this function is allowed to be discarded by the caller.
5768

5869
Discarding a return value is:

src/values/builtin_long.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#pragma once
3+
4+
#include "symbol.hpp"
5+
#include <stdint.h>
6+
7+
namespace hk::builtin {
8+
9+
using int_reg_t = intptr_t;
10+
11+
struct builtin_long : public symbol_type {
12+
union {
13+
int_reg_t value = 0;
14+
int_reg_t *ptr;
15+
};
16+
uint32_t size = 0;
17+
uint32_t capacity = 0;
18+
};
19+
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#pragma once
3+
4+
#include "long.hpp"
5+
6+
namespace hk::builtin {
7+
8+
struct long_interval : public symbol_type {
9+
builtin_long lo;
10+
builtin_long hi;
11+
};
12+
13+
14+
}

src/values/symbol.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#pragma once
3+
4+
#include <memory>
5+
6+
namespace hk {
7+
8+
struct symbol_type;
9+
10+
struct symbol_value_base {
11+
virtual ~symbol_value_base() = default;
12+
13+
std::unique_ptr<symbol_type> type;
14+
};
15+
16+
template<typename T>
17+
struct symbol_value : public symbol_value_base {
18+
T value;
19+
};
20+
21+
template<typename T>
22+
struct symbol_type : public symbol_value<T> {
23+
24+
};
25+
26+
struct symbol_instance {
27+
symbol_type type;
28+
symbol_value_base value;
29+
};
30+
31+
}

src/values/symbol_table.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11

22
#include "symbol_table.hpp"
33
#include "utility/algorithm.hpp"
4+
#include <algorithm>
45

56
namespace hk {
67

7-
symbol_table::symbol_table(std::span<symbol_table const*> tables)
8+
symbol_table::symbol_table(std::span<symbol_table const*> tables) : _tables()
89
{
9-
auto tables_ = std::vector<container_type const*>{};
10-
tables_.reserve(tables.size());
10+
auto const size = std::accumulate(tables.begin(), tables.end(), 0uz, [](auto const& item) {
11+
return item.size();
12+
});
13+
_tables.reserve(size)
14+
1115
for (auto const& table : tables) {
12-
tables_.push_back(std::addressof(table->_table));
16+
_table.append_range(*table);
1317
}
1418

15-
multi_merge(tables_, _table);
19+
std::sort(_tables.begin(), _tables.end());
1620
}
1721

1822
hk::symbol *symbol_table::add(fqname name, std::shared_ptr<hk::symbol> symbol)

0 commit comments

Comments
 (0)