Archive: NSIS assembler


NSIS assembler
Hi all. It's my birthday today so I thought it would be a good time to post a project that I am working on for my University degree. It's an assembler for NSIS which takes a language that borrows syntax from all the popular high level languages such as Java, C and PHP and translates it into pure NSIS instructions.

For example,

function myFunc($arg1)
{
$myVar = $arg1 * 10;
$var2 = 99 % (87 + $myVar);
return ($var2 + 6, $var2 * 6);
}

section blah()
{
($retA, $retB) = myFunc(12);
if ($retA < $retB || $retB == 55)
detailPrint("hi!");
}
I still need to implement a lot of the NSIS functions such as MessageBox which require special treatment. For example, I plan to allow:

$result = MessageBox(MB_OK, "lolzzzzz");
if ($result == IDOK)
{
...
}
Still to be done:
* The preprocessor stuff but for my degree I will likely have the most basic form of #include, #define, #ifdef etc with perhaps macros via #macro akin to the C #define preprocessor directive. Extras can be added after.
* Plugin calls
* Variables optimisation (i.e. replace variable names with $0-$9, $R0-$R9 where possible (these are already used by the assembler for mathematical ops etc)).
* Properties

I have not yet decided on the properties such as Name, OutFile etc. Kichik had the idea to have a a separate file for properties in XML or some other format. However I am just thinking of keeping it simple so outFile("blah.exe"); and Name("Blah!"); for example which would be used outside a section/function just like in NSIS.

I'm not sure whether this project will become the new face of NSIS or not because it may need a lot of existing stuff to be rewritten (I will be adding an __asm like instruction for inline NSIS script though). However it is an interesting exercise, especially for myself. Either way if anyone has any nice ideas I would love to hear it.

Thanks

Stu

Ufff, this seems like a tough nut...
But I keep my fingers crossed for you, GL in University


Sounds interesting. Good luck!

Ps: Happy birthday, Stu :D


Very cool idea! I'm wondering how/whether you'll handle global vs local variables?


Originally posted by MSG
Very cool idea! I'm wondering how/whether you'll handle global vs local variables?
Yes I have provisions for that. The assembler will just throw an error.

Stu

Great thing, but will it generate NSIS scripts as output ?
Why not have it generate directly NSIS bytecode so it could be integrated as an alternative script format into makeNSIS ?


Using round brackets is more convenient.
I want that NSIS would be more easy to use that now, such as:
(1)Command support more operations on one line. e.g.:
IntOp $R0 $R1 * $R2 * $R3
or like: IntOp $R2 $R0*$R0 - $R1*$R1, etc.
(2)With built-in command if, endif, for, switch, case and more supported as you said.
if (hwnd)
;code
endif
if (GetDlgItem(hwnd, 1))
;code
endif
or use braces as well.
(2)Define a macro like C++:
#define MYMINUS(a,b) (a-b)
(3)Define a fuction with parameters as you said:
(4)Use a result of an equation as input, like in c++. e.g.:
SetWindowPos(hwnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.top - rc.bottom, NULL)
or usage like:
SetWindowPos(hwnd, NULL, rc.left, rc.top, MYMINUS(rc.right,rc.left),...)
(5)Use the return value of a function as input to save more variables, like c++. e.g.:
SendMessage(GetDlgItem(hwnd, 1), BM_CLICK, 0, 0)
(6)For each variable in NSIS needs NSIS_MAX_STRLEN bytes, I thought it would declare an int, int64 or a string with specified size so that use less memory.
(7)Merge the Function of System plugin to NSIS compiler or build-in a function for calling a third-part dll easily as System plugin.

Certainly, I means it would be better that NSIS support script like these styles but not written like these command in C++. I hope NSIS 2.5 or NSIS 3.0 will be stronger that before as well as the progress of AutoIt.