Skip to content

Commit 407dea1

Browse files
committed
Some build fixes and some work on making .Compiler a runtime library load
1 parent 23f111e commit 407dea1

8 files changed

Lines changed: 40 additions & 16 deletions

File tree

.github/vc.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
3+
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
4+
set InstallDir=%%i
5+
)
6+
7+
if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
8+
"%InstallDir%\Common7\Tools\vsdevcmd.bat" %*
9+
)

codegen/metac_codegen.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,6 @@ void MetaCCodegen_Init(metac_bytecode_ctx_t* self, metac_alloc_t* parentAlloc)
477477
// ARENA_ARRAY_INIT(sema_decl_variable_t, self->Locals, &self->Allocator);
478478
ARENA_ARRAY_INIT(BCValue, self->Globals, &self->Allocator);
479479
self->GlobalMemoryOffset = 4;
480-
481-
#if METAC_COMPILER_INTERFACE
482-
metac_external_entry_t* extCompP = self->Externals + 0;
483-
extCompP->externalAddress = &compiler;
484-
extCompP->externalSize = sizeof(compiler);
485-
self->ExternalsCount = 1;
486-
#endif
487480
}
488481

489482
void MetaCCodegen_Free(metac_bytecode_ctx_t* self)
@@ -533,7 +526,7 @@ static void InitCompilerInterface(metac_bytecode_ctx_t* ctx)
533526
ctx->Sema->CompilerInterface->TypeIndex.Index;
534527

535528
ctx->CompilerInterfaceValue = gen.GenExternal(c, compilerInterfaceType, ".compiler");
536-
gen.MapExternal(c, &ctx->CompilerInterfaceValue, &compiler, sizeof(compiler));
529+
// gen.MapExternal(c, &ctx->CompilerInterfaceValue, &compiler, sizeof(compiler));
537530
ctx->Externals[0].ExtValue = ctx->CompilerInterfaceValue;
538531
ctx->ExternalsCount += 1;
539532
}
@@ -695,7 +688,7 @@ metac_bytecode_function_t MetaCCodegen_GenerateFunction(metac_bytecode_ctx_t* ct
695688
ctx->Sema->CompilerInterface->TypeIndex.Index;
696689

697690
ctx->CompilerInterfaceValue = gen.GenExternal(c, compilerInterfaceType, ".compiler");
698-
gen.MapExternal(c, &ctx->CompilerInterfaceValue, &compiler, sizeof(compiler));
691+
// gen.MapExternal(c, &ctx->CompilerInterfaceValue, &compiler, sizeof(compiler));
699692
ctx->Externals[0].ExtValue = ctx->CompilerInterfaceValue;
700693
frameSize += sizeof(void*);
701694
}
@@ -920,7 +913,10 @@ static void MetaCCodegen_doCastExpr(metac_bytecode_ctx_t* ctx,
920913

921914
assert(exp->Kind == expr_cast);
922915

923-
if (TYPE_INDEX_KIND(castToType) == TYPE_INDEX_KIND(castFromType) && )
916+
if (castToKind == castFromKind && castToKind == type_index_ptr)
917+
{
918+
919+
}
924920

925921
if (castToType.v == TYPE_INDEX_V(type_index_basic, type_float))
926922
{
@@ -1422,7 +1418,7 @@ static void MetaCCodegen_doExpr(metac_bytecode_ctx_t* ctx,
14221418
}
14231419
sz = imm32(currentOffset);
14241420

1425-
BCValue address = gen.GenTemporary(c, BCType_u64);
1421+
BCValue address = gen.GenTemporary(c, BCType_u32);
14261422
gen.Alloc(c, &address, &sz);
14271423
gen.Set(c, result, &address);
14281424
for(uint32_t i = 0; i < exp->TupleExprCount; i++)

gen_code.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ $CC $CFLAGS utils/gen_metac_keyword_keys.c -o gen_metac_keyword_keys
1313

1414
$CC $CFLAGS utils/gen_metac_match_keyword.c -o gen_metac_match_keyword
1515
./gen_metac_match_keyword > generated/metac_match_keyword.inl
16+
17+
$CC $CFLAGS utils/gen_metac_type_kind.c -o gen_metac_type_kind -g3 \
18+
-DHEADER_PATH=\"compiler_intrinsics/metac_type_kind.h\" \
19+
-DCODE_PATH=\"compiler_intrinsics/metac_type_kind.c\"
20+
21+
./gen_metac_type_kind

libinterpret/bc_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ BCTypeEnum BCTypeEnum_commonTypeEnum(BCTypeEnum lhs, BCTypeEnum rhs)
957957
static const BCType BCType_i32 = {BCTypeEnum_i32};
958958
static const BCType BCType_u32 = {BCTypeEnum_u32};
959959

960+
static const BCType BCType_u64 = {BCTypeEnum_u64};
960961

961962
static inline BCValue BCValue_u32(const BCValue* v)
962963
{
@@ -965,6 +966,13 @@ static inline BCValue BCValue_u32(const BCValue* v)
965966
return result;
966967
}
967968

969+
static inline BCValue BCValue_u64(const BCValue* v)
970+
{
971+
BCValue result = *v;
972+
result.type = BCType_u64;
973+
return result;
974+
}
975+
968976
#undef offsetof
969977

970978
#endif

libinterpret/bc_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,12 @@ static const BCTypeEnum smallIntegerTypes[] = {BCTypeEnum_u16, BCTypeEnum_u8,
426426

427427
static const BCType BCType_i32;
428428
static const BCType BCType_u32;
429+
static const BCType BCType_u64;
429430

430431

431432
EXTERN_C BCTypeEnum BCTypeEnum_commonTypeEnum(BCTypeEnum lhs, BCTypeEnum rhs);
432433
static inline BCValue BCValue_u32(const BCValue* v);
434+
static inline BCValue BCValue_u64(const BCValue* v);
433435

434436
static inline void AllocDefaultHeap(BCHeap* newHeap);
435437

repl/linenoise_repl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int main(int argc, const char* argv[])
158158
linenoiseHistoryLoad(".repl_history");
159159

160160
#ifdef METAC_COMPILER_INTERFACE
161-
compiler.Message = doUiMessage;
161+
// compiler.Message = doUiMessage;
162162
#endif
163163
g_uiContext = &ctx;
164164
#if !defined(NO_FIBERS)

repl/repl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../parser/metac_parser_obj.c"
1010
#include "../semantic/metac_semantic_obj.c"
11-
#include "../compiler_intrinsics/metac_compiler_interface.c"
11+
#include "../compiler_intrinsics/metac_compiler_interface.h"
1212
#include "../driver/metac_driver.c"
1313
#include "../os/bsr.h"
1414
#include "../hash/crc32c.h"
@@ -34,8 +34,6 @@ uint64_t endTs;
3434

3535
uint64_t get_timestamp_micros() {
3636
struct timespec ts;
37-
// CLOCK_MONOTONIC ist am besten für Intervalle
38-
// CLOCK_MONOTONIC_RAW kann noch präziser sein, aber manchmal teurer abzufragen
3937
clock_gettime(CLOCK_MONOTONIC, &ts);
4038
return (uint64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
4139
}

utils/gen_metac_type_kind.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ int main(int argc, const char* argv[])
4444
typeKindNames = malloc(sizeof(char *) * typeKindCount);
4545

4646
{
47+
#ifndef HEADER_PATH
4748
#define HEADER_PATH "../compiler_intrinsics/metac_type_kind.h"
49+
#endif
4850
FILE *header = fopen(HEADER_PATH ,"w+");
4951

5052
fprintf(header, "#ifndef %s\n", INCLUDE_GUARD_NAME);
@@ -74,7 +76,10 @@ int main(int argc, const char* argv[])
7476
}
7577

7678
{
77-
FILE *code = fopen("../compiler_intrinsics/metac_type_kind.c","w+");
79+
#ifndef HEADER_PATH
80+
#define CODE_PATH "../compiler_intrinsics/metac_type_kind.c"
81+
#endif
82+
FILE *code = fopen(CODE_PATH, "w+");
7883

7984
fprintf(code, "#include \"" HEADER_PATH "\"\n");
8085
fprintf(code, "const char* MetaCTypeKind_toChars(%s value)\n", enumName);

0 commit comments

Comments
 (0)