m3_test fixes

extensions
Steven Massey 4 years ago
parent 99019b9613
commit ac7badfdc5

@ -1,6 +1,5 @@
//
// m3_test.c
// m3
//
// Created by Steven Massey on 2/27/20.
// Copyright © 2020 Steven Massey. All rights reserved.
@ -11,7 +10,7 @@
//#include "m3_ext.h"
#include "m3_bind.h"
#define Test(NAME) printf ("test: %s\n", #NAME);
#define Test(NAME) printf ("\n test: %s\n", #NAME);
#define expect(TEST) if (not (TEST)) { printf ("failed: (%s) on line: %d\n", #TEST, __LINE__); }
int main (int i_argc, const char * i_argv [])
@ -23,21 +22,29 @@ int main (int i_argc, const char * i_argv [])
M3FuncType ftype = { NULL, 666, 255 };
result = SignatureToFuncType (& ftype, ""); expect (result == m3Err_funcSignatureMissingReturnType)
FuncType_Free (& ftype);
result = SignatureToFuncType (& ftype, "()"); expect (result == m3Err_funcSignatureMissingReturnType)
FuncType_Free (& ftype);
result = SignatureToFuncType (& ftype, " v () "); expect (result == m3Err_none)
expect (ftype.returnType == c_m3Type_none)
expect (ftype.numArgs == 0)
FuncType_Free (& ftype);
result = SignatureToFuncType (& ftype, "f(IiF"); expect (result == m3Err_none)
expect (ftype.returnType == c_m3Type_f32)
expect (ftype.numArgs == 3)
M3FuncType ftype2;
result = SignatureToFuncType (& ftype2, "f(I i F)"); expect (result == m3Err_none);
expect (AreFuncTypesEqual (& ftype, &ftype2));
FuncType_Free (& ftype);
FuncType_Free (& ftype2);
}
return 0;

@ -1,6 +1,5 @@
//
// m3_bind.h
// m3
//
// Created by Steven Massey on 2/27/20.
// Copyright © 2020 Steven Massey. All rights reserved.
@ -9,7 +8,7 @@
#ifndef m3_bind_h
#define m3_bind_h
#include "m3_core.h"
#include "m3_env.h"
u8 ConvertTypeCharToTypeId (char i_code);
M3Result SignatureToFuncType (M3FuncType * o_functionType, ccstr_t i_signature);

@ -25,7 +25,10 @@ bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB)
{
if (i_typeA->numArgs == i_typeB->numArgs)
{
return (memcmp (i_typeA->argTypes, i_typeB->argTypes, i_typeA->numArgs) == 0);
if (i_typeA->argTypes and i_typeB->argTypes)
{
return (memcmp (i_typeA->argTypes, i_typeB->argTypes, i_typeA->numArgs) == 0);
}
}
}

Loading…
Cancel
Save