Peregrine Update – The Python-like programming language that’s as fast as C++

“Blazing-Fast Language for the Blazing-Fast World” – Peregrine Motto

Introduction

Hey guys, it’s been a long time! If you don’t already know me, my name is Ethan and I’m one of a few Peregrine Programming Language developers. Over the past…


This content originally appeared on DEV Community and was authored by Ethan Olchik

"Blazing-Fast Language for the Blazing-Fast World" - Peregrine Motto

Introduction

Hey guys, it's been a long time! If you don't already know me, my name is Ethan and I'm one of a few Peregrine Programming Language developers. Over the past few months, we've managed to surpass the progress in the 1st write (code for the 1st write has been deleted) and add new features. This post will be discussing the progress that has been made.

About Peregrine

If you know Python, you know how easy it is. However, it also comes with a big downgrade. Python is slow, and I'm pretty sure every python developer knows this by now. This is kind of annoying. That's where Peregrine comes in. Me and 11 friends have been working on Peregrine for the past few months. Peregine's syntax is very similar to Python's, and it gets trans-compiled to C++, thus making it as fast as C++. Some of you may know Peregrine as the "Language that's as fast as C", however we've decided to trans-compile it to C++ instead of C.

New Language Features

Class

After a lot of work, classes have been added to Peregrine. They essentially act the same way you'd expect them to act in python. Here's a quick example:

class Vector3:
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

def main() -> int:
    v: Vector3 = Vector3(1, 2, 3)
    printf("x=%d, y=%d, z=%d", v.x, v.y, v.z)
    return 0

This is pretty self-explanatory. If you put this code into python, you'd just have to change printf to print and change the string formatting and then it works like a charm.

Enum

Enums have also been added to Peregrine. They work like any other enum in any other language.

enum RGB:
    RED = 144
    GREEN
    BLUE = 200
    OTHER = GREEN+9

Here, RGB.GREEN = 155, because the value is defaulted to the previous value + 1. RGB.OTHER = 164, because 155+9=164.

Union

Unions, like in C, C++ etc... are data types that allows the storage of different data types in the same memory location.

union abc:
    a: int
    b: int
    c: int

def main() -> int:
    _x: abc
    x: *abc = &abc
    x->a = 1
    x->b = 2
    x->c = 3
    return 0

NOTE: you don't have to create a pointer to a variable of type abc in order to assign and access it's fields.

custom decorators

Peregrine supports user-defined decorators, just like Python. Here's an example that's taken from can_comp.pe, but slightly modified to improve readability (that file is hardcoded):

type a = def(int)->int
type g = def(int)
def decorator(func: a) -> g:
    h: int = 9
    def value(c:int):
        h = 8
        printf("%d\n", h)
        printf("Answer is %d\n", func(c))
    return value

variable: int = 9

@decorator
def dec_test(x:int) -> int:
    return x*x

def main() -> int:
    dec_test(10)
    return 0

As you can see here, you must define a type for the function being decorated and a type for the return type of the decorator (should return a function).

The program would output Answer is 100.

More

You can find some more code examples in can_comp.pe

Planned features

Here are some features that are planned to be implemented into peregrine before the first release:

  • Structs
  • Python ecosystem in Peregrine
    • You will be able to use any python module in Peregrine
  • Imports
  • Standard Library

Conclusion

Peregrine is planned to release version 0.0.1 sometime between March and April, so make sure to show some support by starring the repo and make sure to press on the "Watch" button so you don't miss any updates.

We would greatly appreciate any contributions, so if you find something that you can improve, open a pull-request! You can also check out our open issues

Thanks so much for reading!


This content originally appeared on DEV Community and was authored by Ethan Olchik


Print Share Comment Cite Upload Translate Updates
APA

Ethan Olchik | Sciencx (2022-01-16T22:31:09+00:00) Peregrine Update – The Python-like programming language that’s as fast as C++. Retrieved from https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/

MLA
" » Peregrine Update – The Python-like programming language that’s as fast as C++." Ethan Olchik | Sciencx - Sunday January 16, 2022, https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/
HARVARD
Ethan Olchik | Sciencx Sunday January 16, 2022 » Peregrine Update – The Python-like programming language that’s as fast as C++., viewed ,<https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/>
VANCOUVER
Ethan Olchik | Sciencx - » Peregrine Update – The Python-like programming language that’s as fast as C++. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/
CHICAGO
" » Peregrine Update – The Python-like programming language that’s as fast as C++." Ethan Olchik | Sciencx - Accessed . https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/
IEEE
" » Peregrine Update – The Python-like programming language that’s as fast as C++." Ethan Olchik | Sciencx [Online]. Available: https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/. [Accessed: ]
rf:citation
» Peregrine Update – The Python-like programming language that’s as fast as C++ | Ethan Olchik | Sciencx | https://www.scien.cx/2022/01/16/peregrine-update-the-python-like-programming-language-thats-as-fast-as-c/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.