A 32bit compiled programming language that runs on Linux
-
"Simple but complex"
- Automatic operations like dynamic typing, typeless arrays, and automatic re-allocation
- Optional manual features like typed variables, pointers, and malloc
-
Combines the function-based ideology of C, and classes from Java
- Revolves around the "format", a perfect mixture of structures and classes
-
Fully compiled language
- HAM` compiler generates 32-bit x86 assembly, which can then be assembled using the gnu assembler
-
Integration with C functions like printf and scanf
-
Very easy to include your own assembly functions / libraries (see documentation for calling convention)
-
Built in debugger
-
Speed of C
I am currently developing a new compiler for this language which has a lot more optimizations and works better than this compiler. However, the new compiler is still lacking many features as I just started its development. It can be viewed here
- In
main.js
under the functionstart
, there is a variable calledINPUTFILE
. Set that to the directory of the file that you want compiled - Copy all foldres into a directory (called
proglan2
here) - In a shell:
cd proglan2/compiler
node main
(must have node.js installed)cd /compiled
./run.sh
(must be in linux. For windows users google WSL and for mac use limaVM, which is what I use)
- In case of a segfault, you can run the debugger
cd proglan2/compiler
node debugger
- Variables
- Implicit typing
- Formats as structs
- Formats as classes
- Functions
- Nested If/elif statements
- Math
- Printing
- While loops
- Arrays
- Lists (similar to Java ArrayLists)
- File access
- Floating point
- Pointers
- Stdio
- Stack variables
- Garbage collection
- Debugger
- Fix command line args
- HAM` include (currently only assembly)
- Multi-dimensional arrays
- Register as parameter or return in register
- Forward declaration
- Static and private properties
- Much more... (see in
main.js
)
All of the following code are simple examples that will compile and run. See examples
for more complex ones.
formats
Price format
{
imported <- f32;
domestic <- f32;
}
Car format
{
price <- Price;
company <- p8;
}
inflation function<Price original, f32 percent> -> u32
{
original.domestic <- #f original.domestic * percent + original.domestic;
original.imported <- #f original.domestic * percent + original.domestic;
return 0;
}
entry function<> -> u32
{
create myCar <- Car<price:Price<imported:5000,domestic:3000.0f>,company:"kia">;
myCar.price.domestic <- 1000.0f;
inflation(myCar.price, 0.1f);
put_float(myCar.price.domestic);
}
math
sum function<f32 a, f32 b> -> f32
{
return #f a + b;
}
entry function<> -> u32
{
put_float(sum(3.5f,6.5f));
}
if statements
entry function<> -> u32
{
if(111 :> 222)
{
put_int(333);
}
elif(444 <: 555)
{
put_int(777);
if(222 :> 444)
{
put_int(789);
}
elif(123 <: 456)
{
put_int(432);
}
put_int(987);
}
elif(333 == 888)
{
put_int(321);
}
}
classes
Square format
{
length <- u32;
color <- p8;
}
Square initializer<u32 len, p8 col>
{
this.length <- len;
this.color <- col;
}
Square volume method<u32 height> -> u32
{
return # this.length * this.length * height;
}
Square area method<> -> u32
{
return # this.length * this.length;
}
entry function<> -> u32
{
create myRoom <- Square<length:10,color:"blue">;
create dadsRoom <- Square<20, "red">;
printf_mini(myRoom.volume(10), "My room cubic feet: %i\n");
printf_mini(dadsRoom.length, "Dads room square feet: %i\n");
}
lists
lists required;
create myArr <- {8,9,10};
entry function<> -> u32
{
create myList <- inf{1,2,3,4,5,6};
myList <[new]- 7;
myList <[new]- 8;
printf_mini(myList[6], "%i\n");
printf_mini(myList[7], "%i\n");
}
pointers
create myArr <- {1,2,3,4};
entry function<> -> u32
{
put_int(@u32 # myArr + 4);
}
stdio
entry function<> -> u32
{
create bob <- 0;
puts("Write in any number: ");
scanf_mini($bob, "%i");
printf_mini(bob, "You typed: %i\n");
}
First uploaded on Nov 4 with working variables, functions, formats, printing 2023
- Nov 4 - Added if/elif
- Nov 5 - Added else and while
- Nov 6 - Added class initializers
- Nov 23 - Finally fixed malloc issue, fixed "return" keyword
- Nov 24 - Added methods
- Nov 25 - Fixed methods and their locals, indefinitley changed math to be prefixed with "#" 2024
- Jan 15 - Added arrays
- Feb 9 - Added fopen, fread, fwrite, and fclose
- Feb 10 - Added floats and fixed functions taking parameters in wrong order
- March 8? - Added pointers and dereferencing
- March 9 - Added lists
- March 10 - Fixed nested formats
- March 13 - Fixed format nesting, added stack vars
- March 15 - Made the transition of params are now stack vars