YHI Loader ...generated bytecode as C but some errors.

Hi Tom, Thanks for your detailed instructions about splitting YHI into two parts and then loading bytecode from the heap. I followed them, and was able to generate a file to be loaded into yhi. However, upon compiling I get some nasty errors that I'm unable to figure out. Below is a snippet from a factorial function: fac 0 = 1 fac n = n * fac (n-1) main = print (fac 42) -------------------------------------- //this generates....among other things -------------------------------------- . . .snip... UInt8 bytecode_Main_2Emain[] = { 0X1, 0X25, 0X26, 0X8, 0X31, 0X42, 0X1, 0X8, 0X32, 0XC, 0X33, 0X34, 0X5B, 0 }; UByte ctypes_Main_2Emain[] = { C_NODE, C_NODE, C_INFO, C_INFO, C_INFO, C_INFO }; PInfo pinfo_Main_2Emain[] ={ }; FInfo finfo_Main_2Emain = (FInfo){ {I_FINFO}, pinfo_Main_2Emain, NULL, 0, 3, 0x00, NULL, NULL, 14, &bytecode_Main_2Emain, 6, &ctypes_Main_2Emain, &ctable_Main_2Emain }; ConstItem ctable_Main_2Emain[] = { (ConstItem) &node_0x18720028, (ConstItem) &node_0x18720480, (ConstItem) &finfo_Main_2Emain, (ConstItem) &finfo_Main_2Emain, (ConstItem) &finfo_Main_2Emain, (ConstItem) &finfo_Main_2Emain }; Word node_0x18720024[] = { (Word) &pinfo_Main_2Emain[0] }; UInt8 bytecode_Main_2Efac[] = { 0X1, 0X25, 0X12, 0X30, 0X42, 0X1, 0XB, 0X13, 0X12, 0X31, 0X32, 0X5A, 0X1, 0X41, 0X2, 0X1, 0X5A, 0X1, 0X4D, 0X5F, 0XB, 0, 0X1, 0X29, 0X17, 0X30, 0X5A, 0X1, 0X42, 0X1, 0X5B, 0X1, 0X29, 0X12, 0X30, 0X42, 0X1, 0X13, 0X12, 0X34, 0X41, 0X2, 0X1, 0X12, 0X35, 0XB, 0X18, 0X17, 0X36, 0X5A, 0X1, 0X41, 0X2, 0X1, 0X5B, 0 }; UByte ctypes_Main_2Efac[] = { C_NODE, C_INFO, C_INFO, C_INFO, C_NODE, C_INFO, C_INFO, C_INFO }; PInfo pinfo_Main_2Efac[] ={ (PInfo){ { I_PINFO }, 0, 2 }, (PInfo){ { I_PINFO }, 1, 1 } }; FInfo finfo_Main_2Efac = (FInfo){ {I_FINFO}, pinfo_Main_2Efac, NULL, 2, 4, 0x00, NULL, NULL, 56, &bytecode_Main_2Efac, 8, &ctypes_Main_2Efac, &ctable_Main_2Efac }; ConstItem ctable_Main_2Efac[] = { (ConstItem) &node_0x18720494, (ConstItem) &finfo_Main_2Efac, (ConstItem) &finfo_Main_2Efac, (ConstItem) &finfo_Main_2Efac, (ConstItem) &node_0x187204a4, (ConstItem) &finfo_Main_2Efac, (ConstItem) &finfo_Main_2Efac, (ConstItem) &finfo_Main_2Efac }; Word node_0x18720490[] = { (Word) &pinfo_Main_2Efac[0] }; ----------------------------------------------------------------------- When I compile I get these errors for this section of code ../yhi/loaderCode.c:15520: error: 'ctable_Main_2Emain' undeclared here (not in a function) ../yhi/loaderCode.c:15520: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15520: error: initializer element is not constant ../yhi/loaderCode.c:15520: error: (near initialization for 'finfo_Main_2Emain') ../yhi/loaderCode.c:15520: error: initializer element is not constant ../yhi/loaderCode.c:15524: error: 'node_0x18720480' undeclared here (not in a function) ../yhi/loaderCode.c:15524: error: initializer element is not constant ../yhi/loaderCode.c:15524: error: (near initialization for 'ctable_Main_2Emain[1]') ../yhi/loaderCode.c:15556: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15558: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15560: error: 'ctable_Main_2Efac' undeclared here (not in a function) ../yhi/loaderCode.c:15560: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15560: error: initializer element is not constant ../yhi/loaderCode.c:15560: error: (near initialization for 'finfo_Main_2Efac') ../yhi/loaderCode.c:15560: error: initializer element is not constant ../yhi/loaderCode.c:15563: error: 'node_0x18720494' undeclared here (not in a function) ../yhi/loaderCode.c:15563: error: initializer element is not constant ../yhi/loaderCode.c:15563: error: (near initialization for 'ctable_Main_2Efac[0]') ../yhi/loaderCode.c:15567: error: 'node_0x187204a4' undeclared here (not in a function) ../yhi/loaderCode.c:15567: error: initializer element is not constant ../yhi/loaderCode.c:15567: error: (near initialization for 'ctable_Main_2Efac[4]') ../yhi/loaderCode.c:15597: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15599: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15601: error: 'ctable_Data_2FChar_2ELAMBDA1036' undeclared here (not in a function) ../yhi/loaderCode.c:15601: warning: initialization from incompatible pointer type ../yhi/loaderCode.c:15601: error: initializer element is not constant ../yhi/loaderCode.c:15601: error: (near initialization for 'finfo_Data_2FChar_2ELAMBDA1036') ../yhi/loaderCode.c:15601: error: initializer element is not constant ../yhi/loaderCode.c:15605: error: 'node_0x1872038c' undeclared here (not in a function) ------------------------------------------------------------ Any ideas about why that blows up? In particular I'm curious about this error, "error: initializer element is not constant" not sure what it means. Thanks for the help, -- </Alexis>

Hi Alexis, Sorry for the slow reply but I've been on holiday for the last week and a half I'll try to answer all your questions ;-) Most of these errors I suspect are lack of forward declarations. As well as generating a .c file you also need to generate a .h file declaring all the things you are going to define. This is so they can all link to each other properly. For example // -------------------------------------------------------------- // program.h // -------------------------------------------------------------- extern UInt8 bytecode_Main_2Emain[]; extern UByte ctypes_Main_2Emain[]; extern PInfo pinfo_Main_2Emain[]; extern FInfo finfo_Main_2Emain; extern ConstItem ctable_Main_2Emain[]; extern Word node_0x18720024[]; extern UInt8 bytecode_Main_2Efac[]; extern UByte ctypes_Main_2Efac[]; extern PInfo pinfo_Main_2Efac[]; extern FInfo finfo_Main_2Efac; extern ConstItem ctable_Main_2Efac[]; extern Word node_0x18720490[]; //------------------------------------------------------------- now at the top of your generate .c file you would have #include "program.h" You should easily be able to generate the .h file at the same time as you generate the .c file. That should hopefully fix a lot of the problems. Thanks Tom
participants (2)
-
Alexis Morris
-
Tom Shackell