extensions
Steven Massey 3 years ago
parent df9aba5bcf
commit fa9248f70f

@ -513,7 +513,7 @@ M3Result UnwindBlockStack (IM3Compilation o)
i16 initStackIndex = o->block.initStackIndex;
u32 popCount = 0;
while (o->stackIndex > initStackIndex )
while (o->stackIndex > initStackIndex)
{
_ (Pop (o));
++popCount;
@ -1027,8 +1027,11 @@ M3Result Compile_End (IM3Compilation o, m3opcode_t i_opcode)
if (o->block.depth == 0)
{
u8 type = GetSingleRetType (o->block.type);
u32 numReturns = GetFuncTypeNumReturns (o->block.type);
if (type)
if (numReturns)
{
if (not o->block.isPolymorphic and type != GetStackTopType (o))
_throw (m3Err_typeMismatch);
@ -1378,7 +1381,7 @@ _ (Pop (o));
u32 numArgs = i_type->numArgs;
u32 slotsPerArg = sizeof (u64) / sizeof (m3slot_t);
u32 slotsPerArg = 2;
// args are 64-bit aligned
u16 argTop = topSlot + numArgs * slotsPerArg;
@ -1439,10 +1442,10 @@ _ (EmitOp (o, op));
}
else
{
result = ErrorCompile (m3Err_functionImportMissing, o, "'%s.%s'", GetFunctionImportModuleName (function), m3_GetFunctionName (function));
_throw (ErrorCompile (m3Err_functionImportMissing, o, "'%s.%s'", GetFunctionImportModuleName (function), m3_GetFunctionName (function)));
}
}
else result = m3Err_functionLookupFailed;
else _throw (m3Err_functionLookupFailed);
} _catch: return result;
}
@ -2222,7 +2225,7 @@ M3Result ValidateBlockEnd (IM3Compilation o, bool * o_copyStackTopToRegister)
* o_copyStackTopToRegister = false;
u8 valueType = GetSingleRetType (o->block.type);
if (valueType != c_m3Type_none)
{
if (IsStackPolymorphic (o))

@ -10,6 +10,7 @@
#include "m3_code.h"
#include "m3_exec_defs.h"
#include "m3_function.h"
d_m3BeginExternC
@ -29,17 +30,6 @@ enum
c_waOp_teeLocal = 0x22,
};
typedef struct M3FuncType
{
struct M3FuncType * next;
u32 numRets;
u32 numArgs;
u8 types[]; // returns, then args
}
M3FuncType;
typedef M3FuncType * IM3FuncType;
#define d_FuncRetType(ftype,i) ((ftype)->types[(i)])
#define d_FuncArgType(ftype,i) ((ftype)->types[(ftype)->numRets + (i)])

@ -14,25 +14,6 @@
#include "m3_exception.h"
#include "m3_info.h"
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes)
{
*o_functionType = (IM3FuncType) m3_Malloc (sizeof (M3FuncType) + i_numTypes);
return (*o_functionType) ? m3Err_none : m3Err_mallocFailed;
}
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB)
{
if (i_typeA->numRets == i_typeB->numRets && i_typeA->numArgs == i_typeB->numArgs)
{
return (memcmp (i_typeA->types, i_typeB->types, i_typeA->numRets + i_typeA->numArgs) == 0);
}
return false;
}
void Runtime_ReleaseCodePages (IM3Runtime i_runtime)
{

@ -14,10 +14,6 @@
d_m3BeginExternC
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes);
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB);
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3Function

@ -0,0 +1,33 @@
//
// m3_function.c
//
// Created by Steven Massey on 4/7/21.
// Copyright © 2021 Steven Massey. All rights reserved.
//
#include "m3_function.h"
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes)
{
*o_functionType = (IM3FuncType) m3_Malloc (sizeof (M3FuncType) + i_numTypes);
return (*o_functionType) ? m3Err_none : m3Err_mallocFailed;
}
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB)
{
if (i_typeA->numRets == i_typeB->numRets && i_typeA->numArgs == i_typeB->numArgs)
{
return (memcmp (i_typeA->types, i_typeB->types, i_typeA->numRets + i_typeA->numArgs) == 0);
}
return false;
}
u32 GetFuncTypeNumReturns (const IM3FuncType i_funcType)
{
return i_funcType ? i_funcType->numRets : 0;
}

@ -0,0 +1,35 @@
//
// m3_function.h
//
// Created by Steven Massey on 4/7/21.
// Copyright © 2021 Steven Massey. All rights reserved.
//
#ifndef m3_function_h
#define m3_function_h
#include "m3_core.h"
d_m3BeginExternC
typedef struct M3FuncType
{
struct M3FuncType * next;
u32 numRets;
u32 numArgs;
u8 types []; // returns, then args
}
M3FuncType;
typedef M3FuncType * IM3FuncType;
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes);
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB);
u32 GetFuncTypeNumReturns (const IM3FuncType i_funcType);
d_m3EndExternC
#endif /* m3_function_h */
Loading…
Cancel
Save