#Note:-This file is ment for tests so it is a bit verbose and hard to read "Multiline comment Hello" "Another Multiline comment Hello" def peregrine1()->int,int: static def peregrine2()->int,int: return 2,2 return 1,1 #error() type a_type=def()->int,int class decorate: def __init__(self):... def dec(self,x:a_type)->a_type: static a:int=9 return x ooo:decorate=decorate() ooo_ptr:*decorate=&ooo @ooo_ptr->dec() @ooo_ptr->dec @ooo.dec() @ooo.dec def some_random_name()->int,int: return 4,4 def dec(x:a_type,i:int=5)->a_type:return x @dec(8) def peregrine3()->int,int: def peregrine2()->int,int: return 3,3 return 4,4 "class x.x class x.x: xx:f128 union x.y union x.y: xx:int def x.b(int,...)->int" def unknown_type(var): var.__add__(1) for x in var: printf("Item is %lld\n",x) for x in var: printf("Item is %lld\n",x) with var as y: printf("Y is %lld\n",y) with var: ... with var as y,var as x: printf("Y is %lld\n",y) printf("X is %lld\n",x) printf("5 in var = %lld\n",5 in var) printf("55 in var = %lld\n",55 in var) printf("5 not in var = %lld\n",5 not in var) printf("55 not in var = %lld\n",55 not in var) printf("var[6] = %lld\n",var[6]) printf("var.__getitem__(7,8) = %lld\n",var.__getitem__(7,index2=8)) def peregrine4():printf("Global function\n") self:int=7 class inherit: def __init__(self):... virtual def __type__(self):printf("\e[1m\e[91mInherit\n\e[0m\e[0m") class iterate_test(inherit): i:int=0 x:int i_ref:&int=i class nested_class: def __init__(self):... enum nested_enum:x,y,z enum nested_enum2:x,y,z=nested_enum.z xyz:nested_enum=nested_enum.x union nested_union: x:int y:int def __init__(self):... def __type__(self):printf("\e[1m\e[91mIterate_test\n\e[0m\e[0m") def __init__(self,c): self.i=c self.x=self.i printf("i_ref is %lld\n",self.i_ref) def peregrine4(self)->int,int: printf("Local func\n") return 6,6 def __add__(self,item)->int: peregrine4() self.peregrine4() return 0 def __neg__(self)->int: return 0 def __iter__(self)->int: return self.x-1 def __iterate__(self)->int: self.i=self.i-1 return self.i def __enter__(self)->int: return 6 def __contains__(self,y:int)->bool: if yint: return index1+index2 def __getitem__(self,index1:int)->int: return index1 def __del__(self): printf("Deleted\n") switch:iterate_test=iterate_test(5) switch2:int=switch.__add__(2) enum colours: RED = 144, GREEN, BLUE = 59,Another=GREEN+9 type a = def(int)->int type g = def(int) static var_static:int = 8 static def staticfunc(): printf("Hello from static function\n") printf("Static var is %lld\n",var_static) item1:int=0 union name: item1:int item2:float def divide(num1:int ,num2:int )->int: match num2: case 0: raise error.ZeroDivisionError case _: return num1/num2 def decorator(func:a )->g: h:int =9 def value(c:int): h=8 printf("%lld\n",h) printf("Answer is %lld\n",func(c)) return value ggggggg:int=9 @decorator def dec_test(x:int)->int: ggggggg=7#mutability test printf("%lld\n",ggggggg) @decorator def nested_test(x:int)->int: ggggggg=7#mutability test printf("%lld\n",ggggggg) def nested_test2(x:int)->int: ggggggg=7#mutability test printf("%lld\n",ggggggg) return x*x nested_test2(7) return x*x nested_test(7) return x*x @decorator static def static_dec_test(x:int)->int: printf("Static decorator\n") ggggggg=7#mutability test printf("%lld\n",ggggggg) @decorator def nested_test(x:int)->int: ggggggg=7#mutability test printf("%lld\n",ggggggg) def nested_test2(x:int)->int: ggggggg=7#mutability test printf("%lld\n",ggggggg) return x*x nested_test2(7) return x*x nested_test(7) return x*x def test(x:int)->int:#this is comment return x def lambda_test(x:a): printf("The value is %lld\n",x(5)) def func(g:int)->int: return g static inline def static_inline_func(): printf("Hello from static inline function\n") inline def inline_func(): printf("Hello from inline function\n") export def exported_func(): printf("Hello from peregrine\n") union union_name: f:float i:int def (y:int)multiply(x:int)->int: return x*y def (const y:int)multiply2(const x:int)->int: return x*y private def private_func(): printf("Hello from private function\n") #platform dependent stuff ' def inline_asm(): arg1:int=45 arg2:int=50 add:int=0 __asm__: add="addl %%ebx,%%eax" "a"=arg1 "b"=arg2 printf("%lld + %lld = %lld\n",arg1,arg2,add) ' type lambda_type=def(int)->int def main(): " inline_asm() " private_func() square:lambda_type=def(x:int):x*x printf("Square of 4 is %lld\n",square(4)) printf("Square of 4 is %lld\n",4|>square) switch:iterate_test=iterate_test(5) virtual_test:*inherit=&switch virtual_test->__type__() _in:inherit=inherit() virtual_test=&_in virtual_test->__type__() switch2:int=switch.__add__(test(5)) switch3:*iterate_test=&switch switch2=switch3->__add__(test(5)) peregrine1() cc1:union_name arrow_test:*union_name=&cc1 arrow_test->i=7 printf("arrow_test->i=%lld\n",arrow_test->i) exported_func() unknown_type(iterate_test(6)) for x in iterate_test(6): printf("Item is %lld\n",x) enum_test:colours=colours.RED static_inline_func() inline_func() staticfunc() dec_test(4) static_dec_test(4) test_var:int=9 test_pointer:*int=&test_var test_ref:int=test_var printf("Value of test_pointer is %lld is at location %p\n",*test_pointer,test_pointer) printf("Value of test_ref is %lld is at location %p\n",test_ref,&test_ref) def z()->int: printf("hello\n") return 5 printf("value of z() is %lld\n",z()) scope: printf("Hello from new scope\n") x:bool =False const cc:bool=False x=True y:bool y=True if x==y: ... printf("%lld\n",test(0)) a:int =0 b:int =7 c:int =7 match a,b,c: case 5,7,8: printf("a is 5,b is 7 and c is 8") case 4,7,_:#c can be anything printf("a is 4 but b is 7") break #we dont want default to execute case 4,_,7:#b can be anything printf("a is 4 but c is 7") break #we dont want default to execute case 8,_:#b and c can be anything printf("a is 8") case _: printf("idk") #optional default:#will be executed at the end if no break printf("\nHello\n") lambda_test(func) assert 8==8 var1:name var1.item1=8 printf("item1 of var1 is %lld\n",var1.item1) var1.item2=6.8 printf("item2 of var1 is %lf\n",var1.item2) #should throw an error #assert 8==6 cast_test:int =9 printf("Value is %lf\n",cast(cast_test)) printf("%lld\n",divide(6,2)) TernaryIf:int=5 if True else 6 assert TernaryIf==5 TernaryIf=5 if False else 6 assert TernaryIf==6 r:int=3 r-- assert r==2 r++ try: assert r==0 except error.AssertionError: printf("Assertion error\n") try: printf("%lld",divide(6,0)) except error.AssertionError,error.ZeroDivisionError:... except: printf("Exception caught\n") try:assert False except error.AssertionError,error.ZeroDivisionError as e: printf("Exception caught %lld\n",e) #TODO: Make it work with iterable and multiple function return variable_a:int=5 variable_b:int=1 printf("variable_a is %lld and variable_b is %lld\n",variable_a,variable_b) variable_b,variable_a=variable_a,variable_b printf("variable_a is %lld and variable_b is %lld\n",variable_a,variable_b) assert variable_a==1 assert variable_b==5 variable_b += variable_a assert variable_b==6 printf("variable_b is %lld\n",variable_b) a=1&2 try: try:divide(1,0) except: printf("Nested try\n") divide(1,0) except: printf("Global try\n") def print_int(i:i32): printf("Square is %d\n",i) #long chained function call print_int(square(4)) #the above is same as folows 4|>square|>print_int