Skip to content

Commit

Permalink
comptime: add the Str method to the comptimeTypeInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jun 23, 2024
1 parent 7539415 commit dc8588f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion std/comptime/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ enum Kind {
// struct comptimeTypeInfo
//
// Returns Kind of type.
// fn Kind(self): Kind
// Returns as constant expression.
// fn Kind(self): Kind
//
// Returns string value of type.
// Returns as constant expression.
// fn Str(self): str
28 changes: 26 additions & 2 deletions std/jule/sema/comptime.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit dc8588f

Please sign in to comment.