Proposal of a new language shield language framework

New language proposal

We propose shield language as a new language.

  1. Features of shield language It has a very complete GUI, 3DCG and image processing framework. Statically typed language that can be dynamically typed (Jit compiler type (with interpreter) and precompiled / bytecode type (.jcp (abbreviation of Jit Compiled Program) file generation (format that can be started by VM) GC is above (Exists), native code compilation type (scopes such as pointers and Rust, and macros (structure can be reformed) exist, so the learning cost is very high, but it can be as fast as C ++ (dynamic type creation is not possible)) There are three. The former has a lower learning cost, but when it comes to native code compilation, it is comparable to Java. The grammar is a strong statically typed language similar to C #, Python, and Kotlin (type conversion is not possible without casting).
  2. Shield language grammar

ex.shie


#This is a comment.
(*This is also a comment.*)
#Compiler included from~ using *You can omit the namespace with
from system using * #exit(The end of the program),TapKey(Key input),type(Mold),Rtype(制限Mold)Such
using os #id(Address output),exit(End) ptr(Pointer operation)Such
using rapt #Standard convenience function
from console using * #print,read,error,linef(End function)Such
using err # comment,debug etc.
from collection using * #Array<>,List<>,Dict<>,range()etc
#File operation is using file

 #External file import This time, OpenCV is imported.
import cv

rect = rapt.rect #namespace rapt class rect is set to rect
using texisnone as rapt.texture.isnone #def rapt.textureisnone(bool)()Is given an alias.
var n1 = 5
var s1 = "string1"
any d = 5 #Dynamic type
d = "Ah"
#Substitution is"=",Comparison is"=="
var str s2 = "string2"
opt var str s3 = None #Reference type is None
opt var float n2 = Null #Value type is Null
var lst = new [1,"ABC",3.141592] #list is a reference type and obj derived type Once the type is decided, it does not change.
lst[1] = 3 #Compile error
lst += 4 #Add 3 to the end of the list
print(lst[3]) #output 4
nlst = lst + 8.3 #lst and then 8.Create nlst with 3 added
# var lsta = new List<int>[3]{1,2,3}<-List that can only contain specific types
# var lsta = new List<new List<int>>[3,3]{{1,2,3}{4,5,6}{7,8,9}}
var arr = Array<str>[3]{"1","ABC","3.141592"} #Array is value type
var tupple = new (1,"ABC",3.14159265358979)
#var tupple := new {1,"ABC",3.14159265358979}But can be declared
var dic = new Dict<Tupple<str,int>>[2]{("Ah",1),("Ueo",2)}
#Constant declaration is possible with const. Bind when const(:=)use
const Anum := 5 
var Aiu[Anum] = Array<int>{1,2,3,4,5}
tupple[2] =3.14 #Compile error
var str Moji = '1' + '3' 
print(Moji) #output "13"
var errs1 = '1' + 3 #Compile error:Mold is not safe(str + int)
var MRC_OK = int('1') + int('3')
print(str(MRC_OK)) #output '4'

#Main type bool,str,int,var,byte,float,obj,ref~,enum derived type,struct derived type,class derived type,Generics type

if(type(n1) is int or opt int):#true
	print(f"{n1}")

s1 = switch(s1) case "2" case "3" as "s1 is"+s1+"is" break case "string1" case "string2" default as "s1 is2ではありません" break
print(f"{s1}") #output "s1 is not 2"

enum VakKey:#Just a part
	LEFT = 0x25
	RIGHT
	UP 
	DOWN
	a = 0x41
	b
	c
	d

var vk[] = new VakKey()<-Create a box that knows all the states

using val as vk,using VakKey: #If you want to know if the value in parentheses of switch is true instead of the return value with val as~Use syntax. At this time, use continue.
	switch(system.TapKey(int(val))):
		case .RIGHT as #The following is executed:
		print("Right")
		continue
		case .LEFT as
		print("Left")
		continue
		case .UP as
		print("Up")
		continue
		case .DOWN as
		print("Down")
		continue

#The constructor of the structure is the var structure tag name=Structure name(Constructor argument) 
struct tanf: #The structure is a value type(self,Empty object:Null)

	pub unsafe def _init(var int m,var str w,var x) without self: #Constructor does not need a return value
		.m = m #Within without.~Can be written in.
		.w = w
		.x = global s1 #Use unsafe when using global variables, variables outside the class, and pointers.
		return self

	pub def show()():#()Can be omitted if the return type is void return None
		read (f"{self.m}")
		for(i in range(self.m)):
			print(str(i)+"Time")
			print(f"{self.w}But{self.x}is")
			pass

	pub set(val) pub get var int m #Range setting
	pub var str w 
	pub set(val) pub get del var x

dat class Mycdat(obj)(opt var str mydat1,opt var int mydat2)#(Inheritance/aspect)(data)
dat struct Mysdat(opt var str mydat1,opt var int mydat2)

#class constructor is var object name=new class name(Constructor argument)
class Myclass(obj):#(Inheritance/aspect)Class is a reference type object(this,Empty object:None)If it is base, you can connect to the parent method

	pub def _init(int m,ref rect rc,var h,var y,var t[931]):
		this.m = m
		this.rc = rc
		this.h = h
		this.y = y
		this.t = [if(t[i] is Null) 5 else t[i];for i in range(931)]

	pub def show()(int m = 3):
		this.m = m
		var n = 0
		for(not n is this.m and rc is not None):# 
			print(rc.left,rc.right,rc.top,rc.bottom)
		var rect_is_live = if(m < 3) true elif(6 < m and m < 10) false else true
		this.rc = if(not rect_is_live) None else pass

	pub def show()(var h):
		var n = 0
		for(not n is this.m and rc is not None):# 
			print(rc.left,rc.right,rc.top,rc.bottom)
		var rect_is_live = if(m < 3) true elif(6 < m and m < 10) false else true
		this.rc = if(not rect_is_live) None else pass

	pub operator==(bool)(Myclass T): #Operator overload+,-,==,is,and,or,not,xor,*,/,++,--,**,//,%,^,<<,>>,<=,>=,<,>,|,&,!(The last 7 are bit operators)However,,as,=, :=,., ?:, ->, new,type cannot be overloaded
		#+=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=,!=Is possible by overloading the binary operator
		return (if(not this.m is not T.m) false elif(this.rc is not T.rc) false elif(this.h is not T.h) false elif(this.y is not T.y) false elif(this.t is not T.t) false else true)
		
	set(val) get int m
	del opt ref rect rc
	var h
	var y
	ref var t

#Conditional generics(Simple generics can be created with var)
def Tshow<T>()(T t) when T is Rtype(opt ref in(int or str or float)) : #You can use type instead of Rtype, but we do not recommend it because it is redundant.
	opt int s = if(T)
default when:
	err.comment("vakerror0001:No generics made with this type")

def sum(var)(var t1,var t2):
	return t1 + t2 #I get a compile-time error when I read that the types of t1 and t2 are wrong at compile time.

#Namespace(基本はNamespaceに書く今回は特別に外)namespaceとimport名を分けることにより日本語文字列のNamespaceをできるだけ排除しやすいようにする。

namespace ex:
	main(opt int)():
		return Null 
		#Ex in namespace.main()Can be accessed with.(After reading to the bottom, the main function starts(If it is outside, it will be inlined to the main function at compile time and will be inside main.)。)

#aspect(共通aspect)
diversity MyLogging(asp):
	def log(int i):
		print(f"{i}is")
	

About shield language

There is Boo language as a similar language, but I think that it was not popular because it is not more similar to C language than Python, so I made it as Python that is easy to compile with static typing that can be written like C, C ++, C # even a little. Saw. Therefore, I also referred to C # and Kotlin. The following is the version with pointers (macro can also be written here). .shie is fine, but I chose .shiex because the grammar is a little different.

ex.shiex


using system;
using os;
using rapt;
using console;
using err;
using collection;
@pragma out_console #out console,only_window,out_window(The default is out_console)
@pragma out_native #out_native out_compile(.jcp) use_jit(jit compilation/Default)Can be combined
@pragma style Signal_Colon#It is possible to write in C language style.
#Main pointer
#thisptr->this is a reference type. thisptr is a pointer.(Included with namespace os)
#ptr,o_ptr->*If so, it may be mistaken for multiplication and readability will decrease.(Included with namespace os)
#os.id(name)
#macro
@def MyMacro{
	@operator when(tex as when rapt.Texture)#Argument type conditional#Macro operator can be used for most(A powerful macro that allows you to change the structure yourself)。
}@as if(tex is not None) true else false;
	
@def PI = 3.14159265358979 #constant(String)Replace
@def TEXT = "ABC"
@def BEGIN @as { 
@def END @as }

def unsafe main(opt int)(){
	var A[4] = collection.Array<int>{1,2,3,4};
	opt int os.ptr s_p = os.id(A);
	print(os.o_ptr s_p);#output 1
	s_p++;
	int s = os.o_ptr s_p;
	s_p = os.nullptr;
	ref int AA = new {4,5,3,2};
	rapt.Texture tx = None;
	bool A = MyMacro{when(tx)} 
	print(A); #output false
	if(true) BEGIN ref int BB = AA; END
	print(AA[2]); #Compile error
	print(BB[2]); #Compile error
	print(A[1]); #2
	print(s); #output 2
	return Null;#Successful completion
}

If anyone has the technology to make it, please make it. What I thought about writing is difficult to write without an IDE.

Version 0.1

This reform point Enabled to declare variables in the constructor with struct (class). Enabled to change the number of variables in the class (reference type) method. Methods (defs inside the class) and procedures (defs outside the class) written outside the namespace belong to the namespace of your filename. Addition of ifdef () / eldef () / undef keywords (var type, existence of variables), etc. Option type (Null, None) can omit opt keyword if it is clear at the time of assignment. If nothing is written, var (numerical value is mutable / type is immutable), const (both type and numerical value are immutable), dynamic (type declaration is completely unnecessary / type can be changed) (= is basically var) (),: = is basically const,; = is basically dynamic (var in function calls and if statements)) Comes with a compiler using,using ~ as ~,from~ using *,from~ using~ as ~ Third party (program created by myself) import, import ~ as ~, from ~ import *, from ~ import ~ as ~, from ~ (filename) with ~ (namespace) as * (disable a specific namespace in the file), from ~ with ~ as ~ (~ Rename a specific namespace in the file) From hogehoge with hugahuga as huga hogehoge. Shie changes the namespace hugahuga to huga (hugahuga.Huga-> huga.Huga, hogehoge hugahuga cannot be used). Organized standard input / output (console class)

console.shie


print(str) = return None #Character string can be output(No \ n)Fast and secure!
scan() = return (type)str #Character string can be output(No \ n)Fast and secure!
white(type<genelic>) = return None #String,Numerical value can be output(No \ n)CLI calendar, etc.!
read(type<genelic>) = return (type)str #String,Numerical value can be entered(No \ n)When line breaks get in the way
whiteline(type<genelic>) = return None #String,Numerical value can be output(¥ n Yes)I usually use this
readline(type<genelic>) = return (type)str #String,Numerical value can be entered(¥ n Yes)I usually use this
input(type<genelic> or f"",~) = return None #F character string can be used(¥ n Yes)When you want the convenience of using f character strings
output(type<genelic> or f"",~) = return (type)str #F character string can be used(¥ n Yes)When you want the convenience of using f character strings
linef() return '¥n'
(type)str->format()

exp.shie


from system using *
from console using *
from collection using *

#Out-of-namespace procedure
def sum(var)(var i,var j):
	return i+j

#Non-namespace class
class Main:

	pub def main(var int)():		
		abc = new nan.ABC("Ah",10)
		output(for(i in range(abc.get_n())) abc.get_is_Nothing())#output "false" * 10
		abc.show(3.14159265358979)#output "3.14159265358979"*10
		abc.show(3,4,true) #output true*3 false*4
		return Null

namespace nan:
	class ABC(obj):

		pub def _init(str m,int n) without this:
			pub set(val) pub get del var .is_Nothing = if(m is None) true elif(m.isEmpty()) true else false
			pub set(val) pub get var .n = n
		
		pub def show()(var K)without this:
			pub set(val) get var .K = K
			output(for(i in range(.n)) .Is K)

		pub def operetor== (bool)(ABC abc)without this:
			ifdef(.K):
				return .isNothig == abc.get_isNothig() and .n == abc.get_n() and .K == abc.k() 
			undef:
				return .isNothig == abc.get_isNothig() and .n == abc.get_n()

		#Overload
		pub def show()(int A,int B,bool C):
			var bcd = exp.BCD(A,B,C)
			bcd.show()

#Out-namespace structure
struct BCD:
	
	pub def _init(int A,int B,bool C) without self:
		pub set(val) pub get del var .A = A
		.B = B
		.C = C

	pub def show()()without self:
		print(for(a in range(.A))C,for(b in range(.B))not C)


Recommended Posts

Proposal of a new language shield language framework
Shield language var0.1
A proposal for versioning of features in Kedro
A verification of AWS SDK performance by language
Proposal of Kuwahara filter as a photographic expression
Tasks at the start of a new python project
Features of Go language