I have now added the Big number functions to ScarletDME. This was relatively straightforward once I realized that I could simply use a library to do the math rather than write it myself. The original plan was that but luckily I learned before I started. I think it could have been fun but all I really care about is getting the functions not the implementation of the functions.
My current files that I have changed for this project are:
modified: GPL.BP/BCOMP
modified: GPL.BP/ICOMP
modified: Makefile
modified: gpl.src
new file: gplsrc/op_smath.c
modified: gplsrc/opcodes.h
I posted on the scarletdme google group and someone mentioned that I might be able to levarage the ssl library if it was already being used. I learned that SSL and cryptography functions basically require big number support for the same reasons that I needed it. The numbers quickly get very large and overflow past a regular number. Unfortunately scarletdme doesn't seem to have any ssl support so I was going to have to include an extra library.
I decided to use the crypto library instead of gmp as crypto is part of OpenSSL. My thinking is that it is likely that the openssl libraries are going to be future dependencies and so using it now is probably the best bet that I won't have to make changes in the future.
I created the op_smath.c file under gplsrc and got to work implementing op_sadd, op_ssub, op_smul and op_sdiv. These went pretty quickly as they are very simply functions. I get the strings from the stack, pass them to the bn library in openssl and then run the correct function to do addition, subtraction, multiplication or division. I then take the result and put it back on the stack at which point it will go back to BASIC.
Once the functions are written, the next step is to update the gpl.src file in the base directory. This file is what tells the Makefile what files need to be compiled.
The next step is to update the Makefile with lcrypto as a library flag. This way I can compile my new op_smath.c file. This did require me to install the 32bit version of openssl which was pretty straightforward.
The final step in the C side of things is to update the opcodes.h file in gplsrc. I added the 4 new functions to the last 16 opcodes. There are only 16 opcodes left to be used and I have now used up 4 of them. I'm not sure what the process is going to be update this so that we can add more than 16 new opcodes. That is going to be a problem for the future.
The next step was to run OPGEN in scarletdme as the internal system account. This program reads in the gplsrc/opcodes.h file and generates the BASIC header file that BCOMP uses. I'm not entire sure what the exact process is but I think you need to run and build BCOMP in the development environment rather than the already installed environment.
Once OPGEN is run, double check the GPL.BP OPCODES.H to make sure the new opcodes are there. If the file doesn't look right then check BP OPCODES.H. If this looks correct then you may need to copy this file to GPL.BP.
Now for the final step, we now have the BASIC header file built. I then updated the BCOMP program in GPL.BP and added my 4 opcodes. This involved updating the intrinsics, intrisinc.opcodes and the entry points. This is alphabetical so make sure your opcodes are put in the correct place.
I then compiled BCOMP and I had already done make and make install, at this point I had my new opcodes fully functional. I also updated ICOMP but I'm not sure if I had to. I'm guessing ICOMP is used to compile the dictionary I type programs.
After all this I had my hashmap functions working without any modifications and then worked on getting my templating language working. Once I had the big number functions, everything fell into place pretty quickly.