From ac7badfdc5d3936699162f1433fbd9fd4433b596 Mon Sep 17 00:00:00 2001 From: Steven Massey Date: Fri, 28 Feb 2020 18:01:06 -0800 Subject: [PATCH] m3_test fixes --- source/extra/m3_test.c | 13 ++++++++++--- source/m3_bind.h | 3 +-- source/m3_env.c | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/source/extra/m3_test.c b/source/extra/m3_test.c index a505304..b2f8bef 100644 --- a/source/extra/m3_test.c +++ b/source/extra/m3_test.c @@ -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; diff --git a/source/m3_bind.h b/source/m3_bind.h index bd4cb3e..a2bfa72 100644 --- a/source/m3_bind.h +++ b/source/m3_bind.h @@ -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); diff --git a/source/m3_env.c b/source/m3_env.c index f3058c2..30d3406 100644 --- a/source/m3_env.c +++ b/source/m3_env.c @@ -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); + } } }