From dc8588f76644356c96e20304dea8bda3108a8799 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Sun, 23 Jun 2024 17:05:12 +0300 Subject: [PATCH] comptime: add the Str method to the comptimeTypeInfo --- std/comptime/type.jule | 7 ++++++- std/jule/sema/comptime.jule | 28 ++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/std/comptime/type.jule b/std/comptime/type.jule index 0c479de51..0b427a660 100644 --- a/std/comptime/type.jule +++ b/std/comptime/type.jule @@ -43,4 +43,9 @@ enum Kind { // struct comptimeTypeInfo // // Returns Kind of type. -// fn Kind(self): Kind \ No newline at end of file +// Returns as constant expression. +// fn Kind(self): Kind +// +// Returns string value of type. +// Returns as constant expression. +// fn Str(self): str \ No newline at end of file diff --git a/std/jule/sema/comptime.jule b/std/jule/sema/comptime.jule index 63aa973c7..93dd627a6 100644 --- a/std/jule/sema/comptime.jule +++ b/std/jule/sema/comptime.jule @@ -5,6 +5,8 @@ use ast for std::jule::ast use std::jule::constant::{Const} +// All comptime-structure methods starts with underscore (_). + // Comtpile-time type information data. struct comptimeType { Base: &TypeKind @@ -25,7 +27,18 @@ impl Kind for comptimeType { } impl comptimeType { - fn Kind(mut &self, mut &e: &Eval): &Data { + fn _Str(&self): &Data { + let mut constant = Const.NewStr(self.Base.Str()) + ret &Data{ + Kind: &TypeKind{ + Kind: buildPrimType(PrimKind.Str), + }, + Constant: constant, + Model: constant, + } + } + + fn _Kind(mut &self, mut &e: &Eval): &Data { let mut enm = findComptimePackage(e.s).FindEnum("Kind") let mut item: &EnumItem = nil match { @@ -99,10 +112,21 @@ impl comptimeType { fn subIdent(mut &self, ident: str): &Data { match ident { + | "Str": + let mut method = &FnIns{ + caller: fn(mut &e: &Eval, mut &fc: &ast::FnCallExpr, mut &_: &Data): &Data { + ret self._Str() + }, + } + ret &Data{ + Kind: &TypeKind{ + Kind: method, + }, + } | "Kind": let mut method = &FnIns{ caller: fn(mut &e: &Eval, mut &fc: &ast::FnCallExpr, mut &_: &Data): &Data { - ret self.Kind(e) + ret self._Kind(e) }, } ret &Data{