Skip to content

Commit b331731

Browse files
committed
Fix a couple of bugs
1 parent c62829f commit b331731

9 files changed

Lines changed: 43 additions & 43 deletions

File tree

codegen/metac_codegen.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,10 @@ void MetaCCodegen_doDeref(metac_bytecode_ctx_t* ctx,
896896
metac_type_index_t varType,
897897
BCValue* result)
898898
{
899-
{
900-
assert(!"doDeref not implemented right now");
901-
}
899+
BackendInterface gen = *ctx->gen;
900+
void* c = ctx->c;
901+
// this only works for pointers to 32bit basic types
902+
gen.Load32(c, result, addr);
902903
}
903904

904905
static void MetaCCodegen_doCastExpr(metac_bytecode_ctx_t* ctx,
@@ -1011,7 +1012,7 @@ static void MetaCCodegen_doArrowExpr(metac_bytecode_ctx_t* ctx,
10111012
metac_type_index_kind_t aggKind = type_index_invalid;
10121013
metac_type_aggregate_field_t* field = 0;
10131014
metac_type_index_t aggTypeIndex;
1014-
BCType addrType = {BCTypeEnum_Ptr};
1015+
BCType addrType = {BCTypeEnum_i32};
10151016
BCValue addr;
10161017
BCValue e1Value = {BCValueType_Unknown};
10171018
BCValue offsetVal = {BCValueType_Unknown};

compiler_intrinsics/metac_compiler_interface.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,6 @@ metac_node_t compiler_ResolveNode(struct metac_compiler_t* compilerP, const char
7575

7676

7777

78-
uint32_t (*CurrentTimeStamp) ();
79-
80-
const char* (*Help) ();
81-
82-
void (*Message) (struct metac_compiler_t* compilerP,
83-
const char* str);
84-
85-
void (*Error) (struct metac_compiler_t* compilerP,
86-
const char* str);
87-
88-
type_kind_t (*GetTypeKind) (struct metac_compiler_t* compilerP, type* T);
89-
90-
void (*PrintInt) (int32_t value);
91-
92-
metac_enum_members_t* (*GetEnumMembers) (struct metac_compiler_t* compilerP, type* T);
93-
94-
metac_node_t (*ResolveNode)(struct metac_compiler_t* compilerP, const char* name);
95-
96-
9778
metac_compiler_t compiler = {
9879
0,
9980

@@ -112,5 +93,6 @@ metac_compiler_t compiler = {
11293
compiler_ResolveNode,
11394

11495
"v0.1",
96+
20260205,
11597
};
11698

compiler_intrinsics/metac_compiler_interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
typedef void* type;
66
# endif
77

8+
typedef unsigned int uint32_t;
9+
typedef int int32_t;
10+
811
typedef enum type_kind_t
912
{
1013
TypeKind_Invalid,
@@ -43,7 +46,9 @@ typedef struct metac_compiler_t
4346
metac_node_t (*ResolveNode)(struct metac_compiler_t* compilerP, const char* name);
4447

4548
const char* Version;
49+
unsigned int IntVersion;
4650
} metac_compiler_t;
51+
// uint32_t ;
4752

4853
/* Proposed Interface:
4954
typedef struct {

libinterpret/bc_common.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,30 @@ EXTERN_C bool BCValue_isStackValueOrParameter(const BCValue* val)
589589
#define VM_SIZE_RO_METADATA (256 * 1024 * 1024)
590590
#define VM_LIMIT_RECURSION 2000
591591

592+
uint32_t AddressFrom(address_kind_t kind, uint32_t offset)
593+
{
594+
uint32_t result = 0;
595+
switch (kind)
596+
{
597+
case AddressKind_Heap: {
598+
result = VM_ADDR_HEAP_START + offset;
599+
} break;
600+
case AddressKind_Stack: {
601+
result = VM_ADDR_STACK_START + offset;
602+
} break;
603+
case AddressKind_Register: {
604+
result = VM_ADDR_REG_PAGE + offset;
605+
} break;
606+
case AddressKind_ROMetadata: {
607+
result = VM_ADDR_RO_METADATA + offset;
608+
} break;
609+
case AddressKind_External: {
610+
result = VM_ADDR_EXTERNAL_START + offset;
611+
} break;
612+
default : assert(0);
613+
}
614+
return result;
615+
}
592616

593617
address_kind_t ClassifyAddress(uint32_t addr, uint32_t* out_offset)
594618
{
@@ -607,7 +631,7 @@ address_kind_t ClassifyAddress(uint32_t addr, uint32_t* out_offset)
607631
else if (top == 0)
608632
{
609633
// Stack grows up, starts at 0x4000
610-
if (addr >= VM_ADDR_STACK_START)
634+
if (addr >= VM_ADDR_STACK_START)
611635
{
612636
kind = AddressKind_Stack;
613637
offset = addr - VM_ADDR_STACK_START;
@@ -618,10 +642,10 @@ address_kind_t ClassifyAddress(uint32_t addr, uint32_t* out_offset)
618642
// kind = AddressKind_Invalid; // Guard Hit
619643
}
620644
// 4KB Register Page (0x2000 - 0x2FFF)
621-
else if (addr >= 0x2000)
645+
else if (addr >= VM_ADDR_REG_PAGE)
622646
{
623647
kind = AddressKind_Register;
624-
offset = addr - 0x2000;
648+
offset = addr - VM_ADDR_REG_PAGE;
625649
}
626650
// 8KB NULL trap (0x0000 - 0x1FFF)
627651
else
@@ -635,7 +659,7 @@ address_kind_t ClassifyAddress(uint32_t addr, uint32_t* out_offset)
635659
{
636660
// Shadow Return Stack (dedicated for 32-bit return addresses)
637661
// this is address invalid
638-
if (addr < VM_ADDR_RETURN_STACK)
662+
if (addr < VM_ADDR_RETURN_STACK)
639663
{
640664
// kind = AddressKind_ReturnStack;
641665
// offset = addr - VM_ADDR_RETURN_STACK;
@@ -658,7 +682,7 @@ address_kind_t ClassifyAddress(uint32_t addr, uint32_t* out_offset)
658682
else if (top <= 32)
659683
{
660684
kind = AddressKind_External;
661-
offset = VM_ADDR_EXTERNAL_START;
685+
offset = addr - VM_ADDR_EXTERNAL_START;
662686
}
663687

664688
*out_offset = offset;

libinterpret/bc_common.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,6 @@ typedef struct CndJmpBegin
219219
bool ifTrue;
220220
} CndJmpBegin;
221221

222-
// heap address 00 - 10
223-
// external address 10
224-
// stack address 11
225-
226-
227-
#define AddrMask ((1U << 31) | \
228-
(1U << 30))
229-
230-
#define stackAddrMask ((1U << 31) | (1U << 30))
231-
#define externalAddrMask (1U << 31 | 0U << 30)
232-
#define heapAddrMask (0U << 31 | 0U << 30)
233-
234222
typedef enum address_kind_t
235223
{
236224
AddressKind_Invalid,

libinterpret/bc_interpreter_backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ BCValue BCGen_interpret(BCGen* self, uint32_t fnIdx, BCValue* args, uint32_t n_a
19491949

19501950
external.size = mapSize;
19511951
external.addr = (void*) addrInt;
1952-
external.mapAddr = state.mapPtr | externalAddrMask;
1952+
external.mapAddr = AddressFrom(AddressKind_External, state.mapPtr);
19531953
state.mapPtr += align4(external.size);
19541954

19551955
state.externals[state.externalsCount++] = external;

repl/completion_trie.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ void CompletionTrie_Add(completion_trie_root_t* root, const char* word, uint32_t
456456
completion_trie_node_t* parentNode =
457457
CompletionTrie_FindLongestMatchingPrefix(root, word, &remaining_length);
458458

459-
460459
if (remaining_length)
461460
{
462461
int posWord = length - remaining_length;

repl/repl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ void Presemantic_(repl_state_t* self)
306306
{
307307
metac_lpp_t tmpLpp;
308308
decl_array_t decls = {0};
309+
AddIdentifierToCompletion(self, "Compiler");
309310
{
310311
MetaCLPP_Init(&tmpLpp, &PresemanticAlloc, 0);
311312
#if 1

semantic/metac_type_semantic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
11351135

11361136
metac_type_typedef_t key = {
11371137
{decl_type_typedef, 0, hash},
1138-
zeroIdx, elementTypeIndex, typedef_->Identifier
1138+
zeroIdx, elementTypeIndex, semaId
11391139
};
11401140

11411141
result =

0 commit comments

Comments
 (0)