Code Monkey home page Code Monkey logo

peregrine's Introduction


A Blazing-Fast Language for the Blazing-Fast world.




The Peregrine Programming Language

NOTE:-It has been discontinued. Please use mojo

Peregrine is a Compiled, Systems Programming Language, currently under development.

Purpose and intent

Why am I creating this language?

I am creating it to have the simplicity of Python with the efficiency of C.

Goals

  • Ease of use
  • Fast
  • Highly modular
  • Occupies less memory
  • Compiled

How does it work?

You can consider it to be a dialect of python which compiles to clean C++. It will have no garbage collector because it is a system programming language.

Building/compiling Peregrine

Requirements to build from source

Compilation instructions

1) Clone the main branch of https://github.com/peregrine-lang/Peregrine.git

git clone https://github.com/peregrine-lang/Peregrine.git

2) Cd into the directory

cd Peregrine

3) Build it

meson builddir
cd builddir
ninja

This will create the binary of the compiler named ./peregrine.elf in the builddir folder

C++ backend To compile it using the c++ backing just run ./peregrine.elf compile path_to_file.pe .It will create the executable named ./path_to_file. Run it to see the result. Check the can_comp.pe file in the root directory to know what you can do with the c++ backend at this point

JS Backend To use the javascript backend use the following command ./peregrine.elf compile path_to_file.js.pe -js. It will create the javascript file named path_to_file.js. Run the generated javascript using node path_to_file.js. Check the can_comp.js.pe file in the root directory to know what you can do with the js backend at this point

Progress

Currently we are working on the codegen and some Peregrine programs are working

Example

Here is a small example for you to understand:

def fib(n:int) -> int :
    if n <= 0:
        return 1
    return fib(n-1) + fib(n-2)

def main():
    count:int = 0
    res:int = 0

    while count < 40:
        res = fib(count)
        count++

The main function is the entry point for the program.

Have questions?

Cool, you can contact me via mail.
Email: [email protected]
Discord : https://discord.gg/CAMgzwDJDM

Want to contribute?

Great, go ahead and make the changes you want, then submit a new pull request

Take a look at the open issues to find a mission that resonates with you.

Please check CONTRIBUTING.md to learn how you can contribute.

License

The Peregrine compiler is licensed under the Mozilla Public License, which is attached in this repository

peregrine's People

Contributors

1moita avatar aayushsinghrathore avatar ccode-lang avatar clientcrash avatar code-xed avatar cyberflamego avatar dheck17 avatar dv8081 avatar ethanolchik avatar g0g05arui avatar gabriel-milan avatar heremanuel avatar insaneminer avatar jammincoder avatar krishyadav007 avatar lainq avatar mdgaziur avatar mmvanheusden avatar mosacode avatar muthulakshimi avatar nachiket18 avatar rechiekho avatar robotboyfriend avatar saptakbhoumik avatar sesam avatar shashankx86 avatar shravanasati avatar tcoyvwac avatar tembocs avatar vanshitaverma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

peregrine's Issues

asm test failing

Describe the bug
Asm test gives an error.

To Reproduce
Steps to reproduce the behavior:

  1. Run test_runner.py

Expected behavior
No error.

Screenshots

If applicable, add screenshots to help explain your problem.

temp.c: In function ‘main’:
temp.c:279:1: error: impossible constraint in ‘asm’
 __asm__ ( "addl %%ebx, %%eax;" : "=a" ( add ) : "a" ( arg1 ) , "b" ( arg2 ) ) ;
 ^~~~~~~

Desktop (please complete the following information):

  • OS: [Raspi os]
  • Version [Buster(10)]

Error when compiling Peregrine on Linux

Describe the bug
When compiling Peregrine source on Linux with V compiler, I get the following error:

builder error: 'libtcc.h' not found

Desktop (please complete the following information):

  • OS: Debian Linux

C++ compiler giving errors instead of peregrine handling function arguments correctly.

when i do not give a function all the arguments needed, the c++ compiler will give me errors. Peregrine should check this and give an error not the c++ compiler.
code

def function(arg)->int:
	printf("arg: %d\n", arg)
	return 1


def main()->int:
	function()
	return 0

error

temp.cc: In function ‘int main()’:
temp.cc:19:92: error: no matching function for call to ‘____P____P________home____dev____projects____Peregrine____builddir____main___pefunction(____P____exception_handler*&)’
   19 |     ____P____P________home____dev____projects____Peregrine____builddir____main___pefunction(____Pexception_handlers);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
temp.cc:13:9: note: candidate: ‘template<class auto:3> int64_t ____P____P________home____dev____projects____Peregrine____builddir____main___pefunction(auto:3, ____P____exception_handler*)’
   13 | int64_t ____P____P________home____dev____projects____Peregrine____builddir____main___pefunction(auto ____P____P____arg,____P____exception_handler* ____Pexception_handlers)  noexcept {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
temp.cc:13:9: note:   template argument deduction/substitution failed:
temp.cc:19:92: note:   candidate expects 2 arguments, 1 provided
   19 |     ____P____P________home____dev____projects____Peregrine____builddir____main___pefunction(____Pexception_handlers);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

Swallow File

Add the best practice of using swallow files (project.sw).
These files would be placed in the main directory of a Peregrine project and specify:

  • Name
  • Version of the Project
  • supported versions of Peregrine or *
  • Description
  • Dependencies

(Very similar to project.json in node or Cargo.toml)

I recommend the Toml format as it's is easy to write and read or parse.

This is very helpful and necessary for adding a package manager later.

An compilation error

error: unexpected name 'main'
1 | def main():
| ~~~~
2 | print("Hello, World!")

Call for contributers

Hi, I am Saptak Bhoumik and I would like to say that we need more contributors to complete this project as fast as possible, if you are interested please fork this repo and contribute. If you have any question please contact me [email protected]

warnings on mac

Describe the bug
It gives this error when compiling:

temp.c:307:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
}
^
temp.c:353:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main (){
^
temp.c:353:1: note: change return type to 'int'
void main (){
^~~~
int
2 warnings generated.

To Reproduce
Steps to reproduce the behavior:

  1. Build a file.

Expected behavior
No error

Desktop (please complete the following information):

  • OS: [mac os m1]
  • Version [11.6]

The parser cant detect "(" after the methods like "append"

Describe the bug
A clear and concise description of what the bug is.

The parser cant detect "(" after the methods like "append"

To Reproduce
Steps to reproduce the behaviour:

  1. Parse the following program
def main():
    a.append(a,b)
  1. See the at generated ast. it is missing the "(" after append

Add GH action to run the tests automaticaly.

Add all steps necessary to run the tests automatically.

An action that compiles the language already exists.

In the action file, you will find some lines that were commented out. You can either fix the bugs and use this code or delete it and rewrite that part of the action file.

Error when compiling peregrine on Windows

Describe the bug

When compiling the Peregrine source with the v compiler:

  v peregrine.v

I get the following error:

c:\Peregrine\Peregrine>v peregrine.v
builder error: 'libtcc.h' not found

To Reproduce

  1. Install v and peregrine exactly as described
  2. v peregrine.v
  3. See error

Expected behavior
Successfull compilation of peregrine

Desktop (please complete the following information):

  • OS: Windows 10/11
  • V 0.2.4 43931be

Additional info
The file libtcc.h lives in C:\v\thirdparty\tcc\libtcc

Remove the images from the root directory

It's uncommon to keep the images in the root directory. They could be moved to a page like assets or be stored out of the Git history. It could be, for example, a link to a image in a issue (the issue don't needs to be published).

Error when run Peregrine file

The compile command works well, but the run not. I'm getting these errors:

<string>:4: error: include file 'stdarg.h' not found
tcc: error: file '/usr/lib/x86_64-linux-gnu/tcc/libtcc1.a' not found

OS is Linux Mint. V version: 0.2.4.

including external c libraries

Is your feature request related to a problem? Please describe.
I wanted to use Peregrine instead of C to write sdl2 code, but I could not find a way to include libraries I tried to when compiling to add the -lSDL2 and the -lSDL2_image flag but that didn't work, so I thought that would be a nice feature to include.

Describe the solution you'd like
I would like to have in the peregrine compiler to have the option to include external libraries like SDL2 and SDL2_image and SDL2_ttf

Describe alternatives you've considered
I honestly don't know of any other alternative methods outside of allowing -l flags

Additional context
Add any other context or screenshots about the feature request here.
afbeelding
This was what I wanted to compile which I compiled using:
~/Peregrine/Peregrine/peregrine compile test.pe -lSDL2 -lSDL2_image -o test

Lot's of questions (future, memory mgmt, metaprogramming, etc.)

Please refer to aardappel/lobster#136 , read the thread to understand why I'm asking these questions and please answer them here 😉.

Additionally I'd like to ask:

a) Why don't you want to join Lobster or Cython or even RPython devs instead of starting from scratch?
b) How do you want to support parallel computation on multiple CPU/GPU/FPGA cores?
This is by far the most important point utterly needed as explained in vlang/v#11608 because it affects nearly all design decisions made when designing a language.
This ranges from "each statement & expression is run in parallel" (Kind, ParaSail, BMDFM, DawnCC - actually not a new language but a smart compiler supporting even non-uniform platforms like big.LITTLE, ... ) through channel/pipe-based parallelism (Dao, Go, V, POSIX sh, Til, ...) to non-builtin support (i.e. pthreads, actors, structured concurrency or nurseries, etc.).

Swallow don't compile

I can't compile Swallow

C:\Users\AUE228\Desktop\swallow\swallow>v swallow.v
C:\Program Files\v\vlib\builtin\float.v:14:16: error: duplicate method str
12 | // str return a f64 as string in suitable notation.
13 | [inline]
|
15 | unsafe {
16 | f := strconv.Float64u{
C:\Users\AUE228\Desktop\swallow\swallow>

  • OS: Windows 7 SP1 x32
  • GCC: (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
  • V: 0.2.4 b4d1429

Why do I get exit codes different than zero?

Describe the bug
I'm developing automated tests for the language, but I'm getting exit codes that differ from zero, even when the script runs fine.

To Reproduce
Steps to reproduce the behavior:

  1. Compile peregrine
  2. Compile the test script ccode.pe
  3. Execute the compiled file
  4. Exit code is 8

Expected behavior
The exit code is supposed to be zero when a script runs fine

Screenshots
image

Desktop:

  • OS: Debian Linux 11
    • Output of uname -a: Linux Vostro-5481 5.10.0-8-amd64 #1 SMP Debian 5.10.46-5 (2021-09-23) x86_64 GNU/Linux

Documentation

Is there any documentation one can refer to in order to learn to use this language.
Oh and can we use external libs right now??

Document Peregrine's operators

Is your feature request related to a problem? Please describe.
To understand the language, it would be nice to document it. If the operators are fully implemented maybe that can serve as a first thing to start with?

Describe the solution you'd like
After agreeing on where to put documentation, the operators could be documented as a first step.

Describe alternatives you've considered
I mean, people can try to type as if it's all python, and maybe that just works? :)

Additional context
Starting from https://github.com/peregrine-lang/Peregrine/blob/main/Peregrine/tests/manual/operation.pe and then checking with the lexer code would likely be enough to discover all the operators that are implemented.

Error when compiling file

Describe the bug
when i compiled a simple file i got this error:

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
zsh: abort (core dumped)  ./peregrine.elf test.pe

the code was:

def test()->int:
	printf("hello")
	return 1;


def main():
	test();

Desktop:

  • OS: Manjaro Linux

G++ info

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (GCC)

meson info
version: 0.61.1

gdb info

#0  0x00007ffff7bded22 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7bc8862 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff7e22802 in __gnu_cxx::__verbose_terminate_handler () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00007ffff7e2ec8a in __cxxabiv1::__terminate (handler=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#4  0x00007ffff7e2ecf7 in std::terminate () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#5  0x00007ffff7e2ef8e in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x7ffff7f91208 <typeinfo for std::out_of_range>, 
    dest=0x7ffff7e45010 <std::out_of_range::~out_of_range()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6  0x00007ffff7e25514 in std::__throw_out_of_range_fmt (__fmt=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/src/c++11/functexcept.cc:100
#7  0x000055555557463b in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_range_check (this=0x7fffffffaa50, __n=0) at /usr/include/c++/11.1.0/bits/stl_vector.h:1073
#8  0x00005555555734fd in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::at (this=0x7fffffffaa50, __n=0) at /usr/include/c++/11.1.0/bits/stl_vector.h:1094
#9  0x00005555555666f6 in lexer (src="", filename="test.pe") at ../Peregrine/lexer/lexer.cpp:231
#10 0x0000555555560c28 in compile (s=...) at ../Peregrine/main.cpp:36
#11 0x00005555555618cb in main (argc=2, argv=0x7fffffffdde8) at ../Peregrine/main.cpp:70

Zig cc for cross-compilation

Is your feature request related to a problem? Please describe.
I believe Swallow currently uses whatever C compiler that is installed on the system by default.

Describe the solution you'd like
Swallow bundles a C compiler per platform. Zig is a language that has wrapped Clang so it can also compile C code. Zig cc is a powerful mechanism whereby the Zig compiler can cross-compile C code from any platform to any platform!

I'd like to see someone take advantage of this powerful mechanism so that Swallow can cross-compile from any platform to any target platform!

Describe alternatives you've considered
N/A

Additional context

./Peregrine/codegen/cpp/utils.cpp:180: void cpp::Codegen::magic_method(ast::AstNodePtr&, std::string): Assertion `function->parameters().size()>0' failed.

the error:

peregrine.elf: ../Peregrine/codegen/cpp/utils.cpp:180: void cpp::Codegen::magic_method(ast::AstNodePtr&, std::string): Assertion `function->parameters().size()>0' failed.
Aborted (core dumped)

the code

 # The Peregrine Programming Language 

class myclass:
	id: int 
	is_admin: bool
	
	def __init__(self, id, is_admin):
		self.id = id
		self.is_admin = is_admin
	def print_info():
		printf("id: %d; is_admin: %d\n", self.id, self.is_admin)



def function(arg1)->int:
	printf("arg1 = %d\n", arg1)
	return 1

def main()->int:
	function_return:int = function(1)

	myclass_var: myclass = myclass(10, True)

	myclass.print_info()
		
	printf("function returned: %d\n", function_return)

	return 0

the command

 ./peregrine.elf compile main.pe

v peregrine.v doesn't work

I installed it just like described on the Github site, along with the dependencies but it just won't work
whenever I type "v peregrine.v" it just does nothing
I'm using Ubuntu 20.04 and I have reinstalled Peregrine like 7 times already...
image

Could not install the lang ,

Describe the bug
i could not even install it
basically , i installed V in my wsl2

V version is 0.2.4

Screenshots
Capture3

Desktop (please complete the following information):

  • OS: windows 10 ,wsl2 ubuntu20,04

It might be a new feature of V lang that is causing it ?

btw : i want to help make this lag good , i think i can use it instead of nim to create some simple exe for the moment.

Comparison docs

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

No problems

Describe the solution you'd like
A clear and concise description of what you want to happen.

I would like to work towards learning swallow as primary language and assist in writing docs and implementing self hosting of the language and stay a consistent contributor to this amazing project I did read contribution.md and didn't see anything about my question which is why I ask here

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Whether I can or cannot help with the documentation maybe the documentation might have this but I'd be happy make a domain or go under a docs sub domain and write comparisons of swallow and python with examples and explanations

Additional context
Add any other context or screenshots about the feature request here.

If I could work towards these goals I would love to become a consistent contributor for swallow as I had my own similar ideas but my experience programming is nowhere near capable and I can see this being what I was looking for and taking a lead in tech a few years from now

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.