Author Topic: [N64 APP] GeneScript scripting language with demo and libraries  (Read 13271 times)

0 Members and 1 Guest are viewing this topic.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
This is going to be my NEO Comp retro submission.
Excuse me for the very large post but there are a few things i will have to cover.


...Lets start :)



About GeneScript

GeneScript or "Genesis Script" or "GS" is an interpreted scripting language like LUA/Python with compiler and virtual machine but has C-Like syntax and does not require entry point function.

The language supports almost all C operators( + , - , / , * ,% , & , ^ , ! , != , == , = ,|| ,| ,&& , >> , <<, > , < , >= , <= )
and also the expression parser does precedence and supports parentheses(a + b * c , is different than (a+b)*c
just like in C).

The expression parser supports constants , native constants ,hex constants ,float consts, variables ,constant native types , script functions,
native function , native types
just like in C.

The language comes with 4 base types : string , pointer ,integer(unsigned instruction set to be compatible with pointer), float(Exclusive opcodes are generated for floats)
and the SDK allows to register custom types and native functions(one of the most powerful features of this scripting language).

One note about the pointer , is that it uses the unsigned 32bit math instructions
and then just grabs the result off of it.

Arrays are supported , but only for int/float types and since there is no garbage collector yet(There is , just disabled)
you have to statically set their size with a constant. A good thing is , that arrays are very fast.Each access
is just 2 operations(Virtually!!)
.

Objects(Classes) are not yet implemented.

Regarding strings , you can't use them in arrays yet or in overloaded expressions since i will have to finish the garbage collector
first and then write a special library that will do the job.For now they're just constant objects.

To control the flow you can use if statements and while loops.Returns from functions are also allowed
but you can't use yet continue/break statements due to a small bug in the scope handling that i haven't fixed yet
so i just disabled them.

The language does support functions and can have as many arguments you like , but they can only be base types.
In the feature i will make a native library that will be using the pointer type for allocations and referencing.

This was one of the features i implemented recently , so in functions that register variables on the stack
there might be a few bugs but functions that don't take arguments and don't return anything are fine.

The scope management is not yet that great so you might see the compiler complain for stuff that shouldn't.
So for this reason always put your while/ifs in a unique scope { } and force-protect your code ,
also in expressions it is suggested to use parentheses since this enables the parentheses-balance code
and always knows where to stop.

One of the most powerful characteristics of this scripting language , is the native function support.
Not only they are very fast since they're referenced by an index value instead hashmaps+loops but they make your life easier.

Take a look at the script code i've written to display the neo logo , and then the script asks you
to press a few buttons and you can see all the action on the screen.All this code executes directly
the native functions and the logic is as usual handled by the virtual machine.


The compiler
The compiler is the "heart" of the scripting language.
Currently it is a pc application(linux 64bit,linux32bit,windows 32bit) but at some point
when the C++ support on n64 reach a descent level i will combine the compiler with the SDK + VM(On pc the vm goes with
the compiler as a set already and even allows realtime access to exported symbols)
.

The compiler's job:
It translates all the code into instructions(opcodes) and then does some possible optimizations.

For example , it can detect cases like "int/float/pointer n = 0;" and can generate single instructions
instead 2.

The compiler also reports at the end of the compilation the memory usage of the virtual machine
and allows you to specify stack optimizations.

In total there are 3 stack optimizations : Level0 : Sets the relocation info to defaults , Level1 :
Sets the relocation info to the average predicted , Level2:Forces the Virtual machine to fully reserve
all the relocation info needed at once
(This is a huge performance boost!!).

It also handles the stack nearly perfect and makes sure that the program will never leave any of the stacks
with unwanted data.

The instructions are long-aligned and the format is so easy to interpret that makes dynamic recompilation
piece of cake!


The virtual machine

Another important thing is the virtual machine.Without it the object code is useless.

The virtual machine reads the bytecode , handles the flow , controls all registers and does all the logic.

There are about 110opcodes that the VM can handle , and about 15main registers that are used.
For everything else a stack is used and handled in the way that the compiler specifies.

Regarding the n64 port of the virtual machine ...it is really fast and carefuly coded , so you get
all the performance you could get from an interpreted approach.


Native runtime libraries(Or Native functions of the N64 port)
Currently the RTL is at a descent level.

There are functions that allows you to render text , display and load images from the SD,
read the controllers , get the system ticks and render geometric shapes.

There are also functions to print integer and float types on screen.

At some point i will improve them , but you can do many things with it already.Even a mini game is very possible.


How to write code
Its simple , but i'll have to say that you must know how to program in order
to use this scripting language.


Also , as far as the N64 port goes , first try to learn the basics of C and libragon(The library
used by the native library set
) before you try anything.

After that  , the syntax is pretty much like C.

Look at the code of the demo that displays the NEOFLASH LOGO and asks for some input:
(This code is pure script and runs on n64 as instructions)
Code: [Select]
//Genescript scripting language demo.
//Demo : Native functions(libs) + Script functions test
//Filename : test1.gsc

//Some global variables
int previous = 0;
int running = 1;

void show_neo_logo()
{
int id;
int ctx;

id = gslgfx_gen_texture("/genescript/neologo.jpg");

if((id == 0))
{
gslconsole_printS("...");
gslconsole_printS("Unable to load : /genescript/neologo.jpg");

while(1){}
}

// ctx = gslgfx_lock(1);

//pass 0 to ctx and the vm will pick one
gslgfx_render_sprite(0,id,0,0);
// gslgfx_unlock(ctx);

gsltiming_delay(500);

ctx = gslgfx_lock(1);
gslgfx_fill_screen(ctx,0);
gslgfx_unlock(ctx);
}

//setup console
void init()
{
gslconsole_init();
gslconsole_set_render_mode(1);

gslconsole_printS("....\n\nGeneScript demo.");
gslconsole_printS("Press A,B,Z buttons to print the event.\nPress START to end the script\n");
}

void shutdown()
{
gslconsole_close();
}

void event_loop()
{
int btn;

btn = gslctrl_read_buttons(0);

if( (btn ^ previous))
{
previous = btn;

int a = gslctrl_button_pressed_A(btn);

if(a)
{
gslconsole_printS("A Pressed...\n");
return;
}

int b = gslctrl_button_pressed_B(btn);

if(b)
{
gslconsole_printS("B Pressed...\n");
return;
}

int z = gslctrl_button_pressed_Z(btn);

if(z)
{
gslconsole_printS("Z Pressed...\n");
return;
}

int s = gslctrl_button_pressed_START(btn);

if(s)
{
gslconsole_printS("END Pressed...\n");
running = 0;
}
}
}

//show neo logo
show_neo_logo();

init();

//main loop
while(running > 0)
{
event_loop();
}

shutdown();


How to compile and run scripts
Extract the package,then
Copy "n64_vm/GenescriptVM.v64" and the directory "genescript"(in "n64_vm/") on top of your SDC.

Compile the code using the compiler:
genecompX86 scriptfile optimization_level

For example to compile script.gsc with optimization level2 do this :
genecompX86 script.gsc 2

Now place the resulting "script.gsobj" in the directory "genescript"
and run "GenescriptVM.v64" from the menu.



NEOCompo demos
There's currently one demo in the "genescript" directory
so just follow "How to compile and run scripts" and run the vm.


Assembly
For those who wonder how the compiled code looks like here is something that will answer your questions.

Input file : playgound.gsc (Pure GeneScript script file)

Code: [Select]
//Genescript scripting language demo.
//Demo : Playground

int array[8];
float fArray[8];

void init()
{
gslconsole_init();
}

void shutdown()
{
gslconsole_close();
}

void say_hello()
{
gslconsole_printS("Hello...\n...World!\n");
}

void do_ifs()
{
int value = 0;

if(value > 10)
{
value = value * 10 /2;
value = value & 1;
}
}

void do_loop()
{
int i = 0;

while(i < 5)
{
array[i] = 0;

i = (i + 1);

if(i >= 2)
{
return;
}
}
}


//Call something
init();
say_hello();
do_loop();
do_ifs();
shutdown();

Once compiled , it will look like this(This is a Compiler + VM SDK cycle dump)


(Note : Those jumps on top actually jump the function section to protect them
from the vm since there is no entry point.
)

Code: [Select]
Genescript compiler
Copyright conleon , 2010 - 2011
Usage : scriptfile optlevel(0 ~ 2)
Program flow memory usage prediction [FULL CYCLE] : ISP 0x6 FSP 0x0  PSP 0x1 RSP 0x0
Program flow memory usage prediction [AVERAGE] : ISP 0x0 FSP 0x0  PSP 0x0 RSP 0x0
Level '2' optimization in progress...
0x0:NOP (A 0,B 0,C -780713992,FA -66370764800.000000,FB 0.000000,FC 0.000000,PA 0x7f28526ec7d1,PB 0x7f2800000001,MEM 0x1b4e190,MBA (nil),MBB 0x7f28526c1420,RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x4:ZEROREGS (A 0,B 0,C -780713992,FA -66370764800.000000,FB 0.000000,FC 0.000000,PA 0x7f28526ec7d1,PB 0x7f2800000001,MEM 0x1b4e190,MBA (nil),MBB 0x7f28526c1420,RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x8:JMP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x1c:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x20:JMP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x34:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x38:JMP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x6c:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x70:JMP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x108:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x10c:JMP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x1d0:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x1d4:CALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x10:NATCALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 0,RLC 72)
0x18:RET (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 0,RLC 72)
0x1dc:CALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 0,RLC 72)
0x40:PLDOBJ (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA (nil),PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 0,RLC 72)
0x5c:PARGPUSH (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 0,RLC 72)
0x60:NATCALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x68:RET (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x1e4:CALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 0,FSP 0,ISP 0,PSP 1,RLC 72)
0x114:ZERO (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x118:ST (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x120:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x124:LD (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x12c:PUSH (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x130:LDIMM (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x138:POP (A 5,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x13c:LT (A 5,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x140:JMP_IF_NOT (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x148:LD (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x150:MEMMOVE (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA (nil),MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x15c:STMEMA (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x160:ZERO (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x164:ST (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x16c:LD (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x174:PUSH (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x178:LDIMM (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x180:POP (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x184:ADD (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x188:ST (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x190:LD (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x198:PUSH (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x19c:LDIMM (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x1a4:POP (A 2,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x1a8:GTE (A 2,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x1ac:JMP_IF_NOT (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x1b4:RET (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x1ec:CALL (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 0,FSP 0,ISP 0,PSP 1,RLC 72)
0x78:ZERO (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x7c:ST (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x84:LD (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x8c:PUSH (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x90:LDIMM (A 0,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x98:POP (A 10,B 1,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0x9c:GT (A 10,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xa0:JMP_IF_NOT (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xa8:LD (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xb0:PUSH (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xb4:LDIMM (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0xbc:LDIMM (A 10,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0xc4:POP (A 2,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0xc8:DIV (A 2,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xcc:POP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xd0:MUL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xd4:ST (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xdc:LD (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xe4:PUSH (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xe8:LDIMM (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0xf0:POP (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 1,PSP 1,RLC 72)
0xf4:LAND (A 1,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0xf8:ST (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x100:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x104:RET (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x1f4:CALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 0,FSP 0,ISP 0,PSP 1,RLC 72)
0x28:NATCALL (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x30:RET (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 1,FSP 0,ISP 0,PSP 1,RLC 72)
0x1fc:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 0,FSP 0,ISP 0,PSP 1,RLC 72)
0x200:NOP (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 0,FSP 0,ISP 0,PSP 1,RLC 72)
0x204:QUIT (A 0,B 0,C 0,FA 0.000000,FB 0.000000,FC 0.000000,PA 0x1b51118,PB (nil),MEM 0x1b4e190,MBA 0x1b4e190,MBB (nil),RSP 0,FSP 0,ISP 0,PSP 1,RLC 72)


Source code
The project is not yet opensource but will when the language gets more mature so please don't ask for SDK, though
a few people will have access to the code and i will also send a copy to Dr.Neo right now.


Special thanks
I would like to thank the following people since they deserve some credits:

Jack Crenshaw - For the book "Let's Build a Compiler".Its *very* outdated but was an interesting read.
ChillyWilly - N64Myth init code , SD access , Libdragon updates
Shaun Taylor - The main author of libdragon which is used by the runtime libs : http://www.dragonminded.com/?loc=n64dev/libdragon


Where to download

Directly from the attachment list of this post!

« Last Edit: August 23, 2010, 01:46:04 AM by Dr.neo »

Offline LaPatateInc

  • Full Member
  • ***
  • Posts: 108
Re: <N64 App>GeneScript scripting language with demo and libraries
« Reply #1 on: August 20, 2010, 03:48:51 AM »
This is.... HUGE ! ~sm-66.gif~.gif

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: <N64 App>GeneScript scripting language with demo and libraries
« Reply #2 on: August 20, 2010, 03:51:37 AM »
This is.... HUGE ! ~sm-66.gif~.gif

 :-\

By the way , i forgot something.A bit later or tomorrow i'll post here all the interfaces of the native libs  ~sm-50.gif~.gif

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: <N64 App>GeneScript scripting language with demo and libraries
« Reply #3 on: August 20, 2010, 04:09:15 AM »
Quote
For the book "Let's Build a Compiler".Its *very* outdated but was an interesting read.

The "dragon book" is sort of the classic educational book on compiler construction. There's also a 2nd edition which is a bit more modern (though I've only read the 1st edition).

Anyway, cool project  ::sm-18.gif::

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: <N64 App>GeneScript scripting language with demo and libraries
« Reply #4 on: August 20, 2010, 04:35:24 AM »
The "dragon book" is sort of the classic educational book on compiler construction. There's also a 2nd edition which is a bit more modern (though I've only read the 1st edition).

Thanks for the book recommendation.I'll pick it up when i get the chance  :)

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: <N64 App>GeneScript scripting language with demo and libraries
« Reply #5 on: August 20, 2010, 07:03:31 PM »
Just fixed a few typos i spotted in main post...



Here are the N64 native library functions that are registered in the compiler.
Code: [Select]
/*************************** NINTENDO64 PLATFORM NATIVE LIB *********************/
/******************************RENDERING(2D)************************************/

//Args r , g , b , a . Returns : u32
cmp.registerNativeFunction("gslgfx_make_color",BASE_INTEGER,"iiii",AUTOFUNC_OBJ);

//Args int ctx, int x, int y, u32 color
cmp.registerNativeFunction("gslgfx_render_pixel",BASE_VOID,"iiii",AUTOFUNC_OBJ);

//Args int ctx, int x, int y, int width, int height, u32 color );
cmp.registerNativeFunction("gslgfx_render_box",BASE_VOID,"iiiiii",AUTOFUNC_OBJ);

//Args int ctx , u32 color
cmp.registerNativeFunction("gslgfx_fill_screen",BASE_VOID,"ii",AUTOFUNC_OBJ);

//Args int fgColor , int bgColor
cmp.registerNativeFunction("gslgfx_set_color",BASE_VOID,"ii",AUTOFUNC_OBJ);

//Args int ctx , int x , int y ,string text
cmp.registerNativeFunction("gslgfx_render_text",BASE_VOID,"iiis",AUTOFUNC_OBJ);

//Args int ctx , int x , int y , int value
cmp.registerNativeFunction("gslgfx_render_itext",BASE_VOID,"iiii",AUTOFUNC_OBJ);

//Args int ctx , int x , int y , float value
cmp.registerNativeFunction("gslgfx_render_ftext",BASE_VOID,"iiif",AUTOFUNC_OBJ);

//Args int wait. Returns : Display context
cmp.registerNativeFunction("gslgfx_lock",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int display context.
cmp.registerNativeFunction("gslgfx_unlock",BASE_VOID,"i",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_sync_full",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_sync_pipe",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_sync_load",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_sync_tile",BASE_VOID,"",AUTOFUNC_OBJ);

//Args filename string. Returns : Texture ID
cmp.registerNativeFunction("gslgfx_gen_texture",BASE_INTEGER,"s",AUTOFUNC_OBJ);

//Args int tx, int ty, int bx, int by
cmp.registerNativeFunction("gslgfx_render_filled_rect",BASE_VOID,"iiii",AUTOFUNC_OBJ);

//Args int ctx, int x0, int y0, int x1, int y1, u32 c
cmp.registerNativeFunction("gslgfx_render_line",BASE_VOID,"iiiiii",AUTOFUNC_OBJ);

//Args int ctx, int id, int x, int y
cmp.registerNativeFunction("gslgfx_render_sprite",BASE_VOID,"iiii",AUTOFUNC_OBJ);

//Args int ctx, int id, int x, int y
cmp.registerNativeFunction("gslgfx_render_sprite_trans",BASE_VOID,"iiii",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_enable_sprite_copy",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_disable_sprite_copy",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_set_default_clipping",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslgfx_detach_display",BASE_VOID,"",AUTOFUNC_OBJ);

//Args int ctx
cmp.registerNativeFunction("gslgfx_attach_display",BASE_VOID,"i",AUTOFUNC_OBJ);

/**********************************INPUT*************************************/

//Args int pad. Returns : Buttons
cmp.registerNativeFunction("gslctrl_read_buttons",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : Analog X
cmp.registerNativeFunction("gslctrl_button_get_analogX",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : Analog Y
cmp.registerNativeFunction("gslctrl_button_get_analogY",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_A",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_B",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_Z",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_START",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_DU",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_DD",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_DL",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_TL",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_CU",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_CD",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_CL",BASE_INTEGER,"i",AUTOFUNC_OBJ);

//Args int pad. Returns : 1 or 0
cmp.registerNativeFunction("gslctrl_button_pressed_CR",BASE_INTEGER,"i",AUTOFUNC_OBJ);

/**********************************TIMING*************************************/

//Args int count
cmp.registerNativeFunction("gsltiming_delay",BASE_VOID,"i",AUTOFUNC_OBJ);

//Args NONE. Returns : Ticks
cmp.registerNativeFunction("gsltiming_get_ticks",BASE_INTEGER,"",AUTOFUNC_OBJ);

/**********************************CONSOLE*************************************/

//Args NONE
cmp.registerNativeFunction("gslconsole_init",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslconsole_close",BASE_VOID,"",AUTOFUNC_OBJ);

//Args int mode(0 = Manual rendering , 1 = Auto rendering)
cmp.registerNativeFunction("gslconsole_set_render_mode",BASE_VOID,"i",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslconsole_clear",BASE_VOID,"",AUTOFUNC_OBJ);

//Args NONE
cmp.registerNativeFunction("gslconsole_render",BASE_VOID,"",AUTOFUNC_OBJ);

//Args constant string value
cmp.registerNativeFunction("gslconsole_printS",BASE_VOID,"s",AUTOFUNC_OBJ);

//Args int value
cmp.registerNativeFunction("gslconsole_printI",BASE_VOID,"i",AUTOFUNC_OBJ);

//Args float value
cmp.registerNativeFunction("gslconsole_printF",BASE_VOID,"f",AUTOFUNC_OBJ);

The next lib will definitely going to handle the SD(read & write).

Offline grisomm

  • Newbie
  • *
  • Posts: 15
Re: [N64 APP] GeneScript scripting language with demo and libraries
« Reply #6 on: February 25, 2011, 11:33:41 AM »
Dear Conle, Thank you.  From the bottom of one nerds heart to another, thank you.  Im currently studying C++ and having this as an application to practice C is a great beginning tool to really understand the language and how it works.  I made a few simple programs, had them all work, but I ran into one small problem.  I couldn't get files larger than 1.5 KB, after the compile, to load.  Is this inherent in the N64 hardware or Myth hardware? Is there any planned update to increase the file size availability?   Your a legend my friend, bravo on all this work  ~sm-76.gif~.gif ~sm-76.gif~.gif ~sm-76.gif~.gif

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: [N64 APP] GeneScript scripting language with demo and libraries
« Reply #7 on: February 25, 2011, 05:51:30 PM »
Dear Conle, Thank you.  From the bottom of one nerds heart to another, thank you.  Im currently studying C++ and having this as an application to practice C is a great beginning tool to really understand the language and how it works.  I made a few simple programs, had them all work, but I ran into one small problem.  I couldn't get files larger than 1.5 KB, after the compile, to load.  Is this inherent in the N64 hardware or Myth hardware? Is there any planned update to increase the file size availability?   Your a legend my friend, bravo on all this work  ~sm-76.gif~.gif ~sm-76.gif~.gif ~sm-76.gif~.gif

There isn't some kind of size limitation , probably your app reaches some of the limitations of the current code.
For example , the base type is unsigned int , even if the compiler/vm support signed/unsigned and floats , so
guess what happens if you have in your code something like this:

Code: [Select]
void inv(int offset) //offset is unsigned
{
offset = offset * -1; //exploded...
}

Or:
Code: [Select]
int sub(int a,int b,int c,int d,int e) //all unsigned
{
a = (a - b - c - d - e);
return a;//'a' now is 0x00000000FFFFFFDF and not -32
}

sub(256,128,64,64,32);

So , as you can see you really have to be careful with expressions that require signed values.
Why i did this ?Simply because it was an easy way to add support for objects using handles without making even more complex the expression parser.

For example , you can use the base type for things like this:
Code: [Select]
int array[128];
int handle = vfs_open("SD:/file","rb");

if(handle != 0)
{
gslconsole_printS("Can't open SD:/file");
return error;
}

vfs_read(handle,array,128*4);
handle = vfs_close(handle);

Or:
Code: [Select]
int handle = vmem_alloc(1 * 1024 * 1024); // handle is an 64bit pointer

if(handle == 0)
{
gslconsole_printS("Can't allocate 1MB");
return error;
}

handle = vmem_free(handle);

And regarding updates , i've already posted a small fix for the native library.Look in n64 development boards   8)

Edit-> Forgot to say ,if you wish to force the compiler to generate the most optimal code , make sure to turn on optimizations by simply passing the optimization level argument  right after the source file, like this:
Code: [Select]
./genecomp source.code 2
« Last Edit: February 25, 2011, 05:56:55 PM by Conle »

Offline grisomm

  • Newbie
  • *
  • Posts: 15
Re: [N64 APP] GeneScript scripting language with demo and libraries
« Reply #8 on: February 26, 2011, 06:14:55 AM »
I hadn't made any useful int variables yet, I was simply using the gsl_consoleout() with your  button press programs (provided in the demo) to print messages. 

   if( (btn ^ previous))
   {
      previous = btn;

      int a = gslctrl_button_pressed_A(btn);

      if(a)
      {         
         gslconsole_printS("A Pressed...\n"); /*<<<Add message here, instead of "A Pressed...\n"./*
         return;
      }


Other than that, I left the demo file alone.  I may have overloaded the Genescript Virtual Machine with this.  I basically copy and pasted "text images"  into the gsl_console(), so when you pressed A, an image made of text would cover the entire screen.  It woked, but when I added more text to the next button, I found the file size became limited to under 1.5KB. 

I havent even started with ints or variables yet with your compiler. ~sm-86.gif~.gif But thanks for the heads up about their limitations. 
**Note, and a big note that I should have mentioned at the begining...I have yet to update my Firmware on my Myth Cart.  So this may be the problem.  I will try the compiler force.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: [N64 APP] GeneScript scripting language with demo and libraries
« Reply #9 on: February 26, 2011, 10:33:12 PM »
Quote
I basically copy and pasted "text images"  into the gsl_console()

You're talking about multiline strings here i suppose.Well make sure to put the 'end of line' character for large strings since the console will wrap big strings to next line automatically.
So , do something like this:
"12345123412312312312312415313613641252315\n
12345123412312312312312415313613641252315\n
12345123412312312312312415313613641252315\n"

Anyway,the runtime library uses libdragon for graphics/input , so you can simply download libragon and see how those functions work before trying them.