Skip to content

Commit 5d7224a

Browse files
committed
WIP.
1 parent 28a7e38 commit 5d7224a

7 files changed

Lines changed: 41 additions & 59 deletions

File tree

lib/bl/api/builtin/a.bl

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
// =================================================================================================
2-
// bl
3-
//
4-
// File: _builtin.bl
5-
// Author: Martin Dorazil
6-
// Date: 2/11/19
7-
//
8-
// Copyright 2018 Martin Dorazil
9-
//
10-
// Permission is hereby granted, free of charge, to any person obtaining a copy
11-
// of this software and associated documentation files (the "Software"), to deal
12-
// in the Software without restriction, including without limitation the rights
13-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14-
// copies of the Software, and to permit persons to whom the Software is
15-
// furnished to do so, subject to the following conditions:
16-
//
17-
// The above copyright notice and this permission notice shall be included in
18-
// all copies or substantial portions of the Software.
19-
//
20-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26-
// SOFTWARE.
27-
// =================================================================================================
28-
291
#load "std/memory.bl"
302
#load "std/debug.bl"
313
#load "std/utils.bl"

lib/bl/api/std/type_utils/type_utils.bl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ enum_variant_value :: fn (T: type #comptime, index: s64) T #inline {
7878
return auto info.variants[index].value;
7979
}
8080

81+
enum_next_variant :: fn (current: ?T) T #inline {
82+
info :: cast(*TypeInfoEnum) typeinfo(current);
83+
return auto info.variants[0].value;
84+
85+
// static_assert(info.kind == TypeKind.ENUM);
86+
// loop i := 0; i < info.variants.len; i += 1 {
87+
// if info.variants[i].value == cast(s64) current {
88+
// if i+1 < info.variants.len {
89+
// return auto info.variants[i+1].value;
90+
// }
91+
// return auto info.variants[0].value;
92+
// }
93+
// }
94+
95+
// panic("Current variant '%' does not exist in the enum.", current);
96+
// return auto 0;
97+
}
8198
//
8299
// Struct utility functions.
83100
//

src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ _Pragma("GCC diagnostic push") \
3838
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
3939
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
4040
_Pragma("GCC diagnostic ignored \"-Wsign-conversion\"")
41+
_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
4142
// clang-format on
4243

4344
#define _SHUT_UP_END _Pragma("GCC diagnostic pop")

src/llvm_api.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
// =================================================================================================
2-
// bl
3-
//
4-
// File: llvm_api.h
5-
// Author: Martin Dorazil
6-
// Date: 9/21/19
7-
//
8-
// Copyright 2019 Martin Dorazil
9-
//
10-
// Permission is hereby granted, free of charge, to any person obtaining a copy
11-
// of this software and associated documentation files (the "Software"), to deal
12-
// in the Software without restriction, including without limitation the rights
13-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14-
// copies of the Software, and to permit persons to whom the Software is
15-
// furnished to do so, subject to the following conditions:
16-
//
17-
// The above copyright notice and this permission notice shall be included in
18-
// all copies or substantial portions of the Software.
19-
//
20-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26-
// SOFTWARE.
27-
// =================================================================================================
28-
291
#include "llvm_api.h"
302

313
#undef array

src/mir_printer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,11 @@ void print_instr_decl_direct_ref(struct context *ctx, struct mir_instr_decl_dire
873873

874874
void print_instr_const(struct context *ctx, struct mir_instr_const *cnst) {
875875
print_instr_head(ctx, &cnst->base, "const");
876-
print_const_value(ctx, &cnst->base.value);
876+
if (cnst->base.id == 28208) {
877+
fprintf(ctx->stream, "!!! try to read: %p", cnst->base.value.data);
878+
} else {
879+
print_const_value(ctx, &cnst->base.value);
880+
}
877881
}
878882

879883
void print_instr_call(struct context *ctx, struct mir_instr_call *call) {

src/vm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,10 +2251,18 @@ void eval_instr_decl_var(struct virtual_machine UNUSED(*vm), struct mir_instr_de
22512251
bassert(var->value.data && "Invalid variable initializer!");
22522252
}
22532253

2254+
void mir_writer_run(struct assembly *assembly);
2255+
22542256
void eval_instr_cast(struct virtual_machine UNUSED(*vm), struct mir_instr_cast *cast) {
22552257
struct mir_type *dest_type = cast->base.value.type;
22562258
struct mir_type *src_type = cast->expr->value.type;
22572259
vm_stack_ptr_t src = cast->expr->value.data;
2260+
2261+
if (cast->base.id == 24998) {
2262+
mir_writer_run(vm->assembly);
2263+
abort();
2264+
}
2265+
22582266
vm_do_cast(cast->base.value.data, src, dest_type, src_type, cast->op);
22592267
}
22602268

tests/test.bl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ x :: foo() catch {}
2020

2121
*/
2222

23+
#import "std/type_utils"
2324
#import "std/print"
2425

26+
Foo :: enum {
27+
A;
28+
B;
29+
C;
30+
}
31+
2532
main :: fn () s32 {
26-
print("Hello!\n");
27-
return 10;
33+
v :: Foo.B;
34+
x :: enum_next_variant(v);
35+
return 0;
2836
}

0 commit comments

Comments
 (0)