Skip to content

DjoCoding/PACKL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PACKL

a very small programming language built on top of the PACKL Virtual Machine, it uses PASM for the code generation

Play with PACKL

Once you have a PACKL program, follow the steps below to compile the program

./bin/packlc <filepath> -code -out <output>.pasm
./bin/pasm <output>.pasm

to run the program type the command below

./bin/pvmr <output>.pvm

PACKL Features

Hello World

proc main() {
    write(0, "Hello World\n");
    exit(0);
}

Variables Declaration and Re-Assignement

proc main() {
    var foo: int = 10;
    foo = foo - 10;
    exit(foo);
}

Functions

func sub(a: int, b: int): int {
    sub = a - b;
}

func add(a: int, b: int): int {
    add = a + b;
}

proc main() {
    var i: int = add(1, 2) - sub(8, 5);
    exit(i);
}

If Statements

proc main() {
    var i: int = 10;

    if (i < 10) { foo(); }
    else if (i < 20) { bar(); }
    else { write("none\n"); }
    
    exit(0);
}

While Loops

proc main() {
    var i: int = 10;
    while (i) {
        foo();
        i = i - 1;
    }
    exit(0);
}

For Loops

proc main() {
    for i: int in (1, 10) {
        foo();
    }
    exit(0);
}

External Files Importing

use "std/io.packl" as io

proc main() {
    io:println("PACKL");
    exit(0);
}

Arrays

proc main() {
    var nums: array(int, 2) = {1, 2};
    nums[0] = 0;
    exit(nums[0]);
}

Strings

use "std/string.packl" as string
use "std/io.packl" as io

proc main() {
    var s: str = "djaoued";
    io:println(string:toupper(s));
    exit(0);
}

Comments

# this is a comment

Operators

proc main() {
    var n: int = 20;
    var a: int = 10;
    var b: int = a++;          # b = 10 and a = 11
    var c: int = a--;          # c = 11 and a = 10
    var d: int = a <= 10       # d = 1
    var e: int = a >= 10       # e = 1
    var f: int = a < 10        # f = 0
    var g: int = a > 10        # g = 0
    var h: int = a == 10       # h = 1
    var i: int = a != 10       # i = 0
    var j: int = a and n       # j = 1
    var k: int = a or n        # k = 1
    var l: int = a xor n       # l = 30
}

Classes

class Point {
    x: int;
    y: int;
};

class Rectangle {
    a: Point; # the starting point
    w: int;
    h: int;
};

proc main() {
    var r: Rectangle = new Rectangle;
    r.init(...);                    # initializing the rectangle
    r.render(...);                  # rendering the rectangle
    write(0, "r: ", r, "\n");       # writing the rectangle object value
}

Note

The PACKL programming language is still not a stable language, don't expect much from it!

About

The PACKL Programming Language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages