LJ/Lang universal compiler

Developed or developing a new product in PureBasic? Tell the world about it.
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

LJ/Lang universal compiler

Post by kinglestat »

The idea behind this project is the possibility of writing code which will run on any device. With the flexibility of the amazing PureBasic and SpiderBasic it is possible.

What is available?

At the moment, just a unified compiler and virtual machine running on windows and a bunch of example programs (written in LJ) which illustrate the capabilities of the language. But it is growing.

LJ Syntax

It is a C Like langauge with extra Basic connotations. I am heavily influenced by the two languages I am enamoured of..C and PureBasic of course.

How it works

LJ/Lang compiles the source into a custom ASM language (which can be seen under source), and the inbuilt Virtual Machine runs it.
The language already can use some inline ASM commands for optimization purposes. When it comes to math or operations, LJ/Lang VM will try to work out best way how to deal with the variables and convert them automatically based on what needs to be done with them. Apat from this, a runtime evaluator can process string for more complex (and faster) math computations.

LJ/Lang capabilities

Pointers
Linked Lists
Records (still unsure about this..but its a place holder for databases)
Forgiving variable manipulations (automatic type conversions)
Inline assembly for optimzations
Macros
Functions (parameters can be passed by value or by reference)

What needs to be added

A proper GUI editor
Integrated database operations with the record object
GUI commands
Sound commands
Integrated indexing for linked lists, records and arrays
PB/SB module addon support

Interested parties

If anyone wishes to help in the project, please contact me. The understaking of the task is quite taxing, but I also understand that is not for everyone.

Download link

http://www.sen3.net/files/ljlang.zip
The link provided has the integrated Compiler+VM for windows, and several test examples

2nd-March-2021

EDITED: - 6th-March-2021 Updated and added an example
EDITED: - 9th-March-2021 3 new string commands added
- Edtor can now load & save
- Load+compile as one command
- Unicode bug (possibly) fixed

Examples

Code: Select all

/*
 Simple prime number generator
 */
count = 1;
n = 1;
limit = 100;
while (n < limit) {
    k=3;
    p=1;
    n=n+2;
    while ((k*k<=n) && (p)) {
        p=n/k*k!=n;
        k=k+2;
    }
    if (p) {
        print(n, " is prime");
        count = count + 1;
    }
}
print("Total primes found: ", count ); 

Code: Select all

a.f = 22 / 7;
b.f = 23 / 7.1;
c = 22/7;
d = 22/7.1;

print( a, " , ", b, " , ", c, " , ", d );

//macro
#mypi (22.01/7.01 - 0.001)#

print((22.01/7.01 - 0.001));
print(#mypi,"++");

f1.f = #pi;
f2.f = #mypi;

print("pi=", f1, " , ", #pi, " , ", f2 );

if( (f1>0.0) == #True ) {
	print("True works.");
}

Code: Select all

/*
 * Linked Lists objects
 */

//Macro
#ObjPrint		i = 0; ForEach(obj) { i = i + 1; print("[",i,"] --> ", obj.get);	}#
 
declare listtest(0);

pub.o NEW object;

ret = listtest();

print("--main--");

i = 0; ForEach(pub) 
{ 
	i = i + 1; 
	print("[",i,"] --> ", pub.get);	
}

func	listtest()
{
	obj.o NEW list;
	dim str$(1);
	
	obj.add("Kilo", "Lima", "Mike", "November");
	#ObjPrint
	obj.add("Alfa", "Bravo", 16, "Charlie", "Delta", "Echo", #pi, "Foxtrot","Juliet","Hotel");
	#ObjPrint
	pos = obj.pos(#CurrentPosition);
	print( "Pos=", pos );
	pos = obj.pos(4);
	print( "Pos(4)=", pos );
	pos = obj.pos();
	print( "Pos(4)=", pos );

	pos = obj.delete();
	pos = obj.delete(6);
	#ObjPrint
	obj.replace(1,15.1);
	obj.replace(2,"Inserted");
	#ObjPrint
	
	obj.convert(STR$());
	count = SizeOf(str$());
	i = 0;

	while( i < count){
		print("[",i+1,"] -- ",str$(i));
		i = i + 1;
	}
	
	obj2.o NEW obj;
	i = 0; ForEach(obj2) 
	{ 
		i = i + 1; 
		print("[",i,"] --> ", obj2.get);	
	}
	
	pub NEW obj;
}

Last edited by kinglestat on Tue Mar 09, 2021 3:39 pm, edited 2 times in total.
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: LJ/Lang...compiler/VM for PB and SB

Post by Tenaja »

That's really neat! I'll have to check it out when I'm back at my computer!
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: LJ/Lang universal compiler

Post by kinglestat »

New example with the latest capabilies
-Inline evaluator
-function parameters by reference
-Timer function

Code: Select all

/*
 * Parameters by reference
 */
 
 declare		Main(0);
 declare	 	@@Test1(3);
 
 InitTimer();
 
 print("====[Start]==================");
 r = Main();
 
 i = 0;
 while(i++ < 4000);
 
 InitTimer();
 i = 0;
 while(i++ < 4000);
 
 /*
  * Eval is a runtime math evaluator and has math functions not available in code
  * Eval has its own variables, and will keep track of them until the command CLEAR is issued
  * Unlike other commands Eval will return all types in a variable (STR, INT and FLT)
  */
 
 //f.f = eval("CLEAR");
 t = EndTimer();
 print("Elapsed = ",t);
 f.f = eval("a=$t$");
 t = EndTimer();
 print("Elapsed = ",t);
 f = eval("b=$t$");
 t = EndTimer();
 print("Elapsed = ",t);
 
 f.f = eval("c=$t$ : a+b+c :c=c*1.611");
 print("f=",f);
 print(eval("9*7+11-6"));
 print(eval("DEG(3.14159/4)"));
 print(eval("Log10(a)"));
 print(eval("Log10(b)"));
 print(eval("Log10(a+b)"));
 
 
 print("====[End]==================");
 //Logical code end
 
 func				Main()
 {
	rnd.f = #pi;
	temp.s = "A typical string";
	obj.o NEW list;
	obj.Add("Alfa","Bravo","Charlie");
	
	print(TypeOf(rnd));
	
	print( "Main: ",temp, " , ", rnd);
	r = Test1(rnd,temp,obj);
	print( "Main: ",temp, " , ", rnd);
	
	foreach(obj) {
		print(obj.get);
	}
	
 }
 
 func				Test1(ff.f,ss$,fobj.o)
 {
	print( "Test1: ",ss$, " , ", ff);
	ss$ = "Hello";
	ff = 100.0/7.11;
	fobj.Add("Delta");
	print( "Test1: ",ss$, " , ", ff);
	print("eval=",eval("$test1-ff$*2"));
 }
 
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
STARGÅTE
Addict
Addict
Posts: 2089
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: LJ/Lang universal compiler

Post by STARGÅTE »

I didn't get it, how can I use my code and get an output?
When I write something in the "- Source -" tab and push Compile and run, the output is something else.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: LJ/Lang universal compiler

Post by kinglestat »

@stargate
you write a text file with a text editor,save it, then load it with the file button....compile, then run
"source" is the assembly language generated; it is the source for the virtual machine
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
STARGÅTE
Addict
Addict
Posts: 2089
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: LJ/Lang universal compiler

Post by STARGÅTE »

kinglestat wrote:@stargate
you write a text file with a text editor,save it, then load it with the file button....compile, then run
Ah oke, but this is not very practicable while testing various of codes lines.
Could you add one tab for current source code, which can be edit and will be compiled?

If I run "demo20.lj" with this first code lines:

Code: Select all

a.f = 22 / 7;
b.f = 23 / 7.1;
c = 22/7;
d = 22/7.1;

print( a, " , ", b, " , ", c, " , ", d );
why is the output of a and d is 22 ?
22 , 3.2394366197, 3 , 22
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: LJ/Lang universal compiler

Post by kinglestat »

@stargate
yes, example20 illustrates an issue I have and need to fix; by how the code is written, it is not a bug per se, as making any of the integer numbers a float would fix the issue.
I just haven't found a way I can do it without losing the oprimization

I will also add your suggestion re source
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
STARGÅTE
Addict
Addict
Posts: 2089
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: LJ/Lang universal compiler

Post by STARGÅTE »

I can not compile "demo11.lj".
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
kinglestat
Enthusiast
Enthusiast
Posts: 732
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: LJ/Lang universal compiler

Post by kinglestat »

@stargate

The example is wrong as float has become a reserved keyword. Thanks for pointing it out

Code: Select all

dim  ar$(12);
ar$(3) = "10.77654";
print( ar$(3) );

dim fl.f(12);

fl.f(3) = 10.77654;
fl.f(6) = 91.023;

print( fl.f(3) );
print( fl.f(6) );

//Automatic conversion to float
print( fl(6) + ar$(3));

f1.f = 1.41;
m = 8;

fl.f(4) = f1.f;

fl.f(7) = 6.8741;
fl.f(4/m + m) = 21.6;
l = 4/m + m;

print( fl.f(4), " , ", fl.f(7) + fl.f(l) );
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Post Reply