From d7308d29346b2459d03c4688ce8ff430873dac49 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Tue, 30 Jan 2024 15:56:12 +0300 Subject: [PATCH] sema: add the Kind trait and implement to known Jule types --- std/jule/sema/enum.jule | 4 ++-- std/jule/sema/fn.jule | 4 ++-- std/jule/sema/struct.jule | 4 ++-- std/jule/sema/trait.jule | 4 ++-- std/jule/sema/type.jule | 41 ++++++++++++++++++++------------------- std/jule/sema/type2.jule | 2 -- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/std/jule/sema/enum.jule b/std/jule/sema/enum.jule index 40fa3da66..0a0522eaa 100644 --- a/std/jule/sema/enum.jule +++ b/std/jule/sema/enum.jule @@ -29,10 +29,10 @@ pub struct Enum { impl Kind for Enum { // Implement: Kind // Returns Enum's identifier. - fn to_str(self): str { ret self.ident } + pub fn to_str(self): str { ret self.ident } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let enm = unsafe { (*(&other)).enm() } ret self == enm } diff --git a/std/jule/sema/fn.jule b/std/jule/sema/fn.jule index 10f0732b1..47232fb08 100644 --- a/std/jule/sema/fn.jule +++ b/std/jule/sema/fn.jule @@ -227,13 +227,13 @@ pub struct FnIns { impl Kind for FnIns { // Implement: Kind // Returns Fn's type kind as string. - fn to_str(self): str { + pub fn to_str(self): str { const IDENT = false ret self.get_kind_str(IDENT) } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let f = unsafe { (*(&other)).fnc() } if f == nil { ret false diff --git a/std/jule/sema/struct.jule b/std/jule/sema/struct.jule index 9de4374f3..26a97c64e 100644 --- a/std/jule/sema/struct.jule +++ b/std/jule/sema/struct.jule @@ -220,7 +220,7 @@ pub struct StructIns { impl Kind for StructIns { // Implement: Kind // Returns Struct's type kind as string. - fn to_str(self): str { + pub fn to_str(self): str { let mut kind = "" kind += self.decl.ident if self.generics.len > 0 { @@ -236,7 +236,7 @@ impl Kind for StructIns { } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let s = unsafe { (*(&other)).strct() } if s == nil { ret false diff --git a/std/jule/sema/trait.jule b/std/jule/sema/trait.jule index b2d958662..57352c528 100644 --- a/std/jule/sema/trait.jule +++ b/std/jule/sema/trait.jule @@ -19,10 +19,10 @@ pub struct Trait { impl Kind for Trait { // Implement: Kind // Returns Trait's identifier. - fn to_str(self): str { ret self.ident } + pub fn to_str(self): str { ret self.ident } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let trt = unsafe { (*(&other)).trt() } ret self == trt } diff --git a/std/jule/sema/type.jule b/std/jule/sema/type.jule index 4585bc140..e53d15b2e 100644 --- a/std/jule/sema/type.jule +++ b/std/jule/sema/type.jule @@ -54,12 +54,13 @@ pub struct TypeAlias { pub generics: []&TypeAlias // See developer reference (1). } -trait Kind { - fn to_str(self): str - fn equals(&self, other: &TypeKind): bool +// Kind of type declaration. +pub trait Kind { + pub fn to_str(self): str + pub fn equals(&self, other: &TypeKind): bool } -// Type's kind's type. +// Evaluated type declaration. pub struct TypeKind { pub cpp_ident: str pub generic: bool @@ -69,7 +70,7 @@ pub struct TypeKind { impl Kind for TypeKind { // Returns kind as string. - fn to_str(self): str { + pub fn to_str(self): str { if self.is_nil() { ret "nil" } @@ -90,7 +91,7 @@ impl Kind for TypeKind { } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { if self.is_nil() { ret other.is_nil() } @@ -332,10 +333,10 @@ pub struct Prim { impl Kind for Prim { // Returns kind. - fn to_str(self): str { ret self.kind } + pub fn to_str(self): str { ret self.kind } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let prim = unsafe { (*(&other)).prim() } if prim == nil { ret false @@ -401,10 +402,10 @@ pub struct Sptr { impl Kind for Sptr { // Returns smart pointer kind as string. - fn to_str(self): str { ret "&" + self.elem.to_str() } + pub fn to_str(self): str { ret "&" + self.elem.to_str() } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let sptr = unsafe { (*(&other)).sptr() } if sptr == nil { ret false @@ -420,10 +421,10 @@ pub struct Slc { impl Kind for Slc { // Returns slice kind as string. - fn to_str(self): str { ret "[]" + self.elem.to_str() } + pub fn to_str(self): str { ret "[]" + self.elem.to_str() } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let slc = unsafe { (*(&other)).slc() } if slc == nil { ret false @@ -439,7 +440,7 @@ pub struct Tuple { impl Kind for Tuple { // Returns tuple kind as string. - fn to_str(self): str { + pub fn to_str(self): str { let mut s = "(" s += self.types[0].to_str() for _, t in self.types[1:] { @@ -451,7 +452,7 @@ impl Kind for Tuple { } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let tup = unsafe { (*(&other)).tup() } if tup == nil { ret false @@ -480,7 +481,7 @@ pub struct Map { impl Kind for Map { // Returns map kind as string. - fn to_str(self): str { + pub fn to_str(self): str { let mut s = "[" s += self.key.to_str() s += ":" @@ -490,7 +491,7 @@ impl Kind for Map { } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let map = unsafe { (*(&other)).map() } if map == nil { ret false @@ -508,7 +509,7 @@ pub struct Arr { impl Kind for Arr { // Returns array kind as string. - fn to_str(self): str { + pub fn to_str(self): str { let mut s = "[" s += itoa(self.n) s += "]" @@ -517,7 +518,7 @@ impl Kind for Arr { } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let arr = unsafe { (*(&other)).arr() } if arr == nil { ret false @@ -533,7 +534,7 @@ pub struct Ptr { impl Kind for Ptr { // Returns pointer kind as string. - fn to_str(self): str { + pub fn to_str(self): str { if self.is_unsafe() { ret "*unsafe" } @@ -541,7 +542,7 @@ impl Kind for Ptr { } // Reports whether types are same. - fn equals(&self, other: &TypeKind): bool { + pub fn equals(&self, other: &TypeKind): bool { let ptr = unsafe { (*(&other)).ptr() } if ptr == nil { ret false diff --git a/std/jule/sema/type2.jule b/std/jule/sema/type2.jule index f370bf833..30cc5d444 100644 --- a/std/jule/sema/type2.jule +++ b/std/jule/sema/type2.jule @@ -4,8 +4,6 @@ // This file reserved for type compatibility checking. -use integ for std::jule::integrated - use std::conv::{fmt_float} use std::math::{modf} use std::jule::ast::{