Skip to content

Implement str and bool runtime functions #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 24, 2022

Conversation

namannimmo10
Copy link
Collaborator

Inspiration: #1 (comment)

@namannimmo10
Copy link
Collaborator Author

We should do something about this line:

throw CodeGenError("Unsupported len value in ASR");

Nonetheless, the ASR looks good to me.

@certik
Copy link
Contributor

certik commented Feb 21, 2022

Is this an intrinsic function? I don't see it here: https://docs.python.org/3/library/functions.html

Also it's time to refactor this whole function into LFortran's style. Let's not put anymore functions here until we refactor, as it is unmaintainable longterm. Let me know if you know how to do the refactor.

@namannimmo10
Copy link
Collaborator Author

Is this an intrinsic function?

No. We will add a generic function, str() down the road, but right now I'm trying to make str_int and str_float work.

I have two ideas for doing that:

  1. Using decorators...
  2. Using type guard:
>>> def str(val: i32 | f64):
...   # "isinstance" type guard
...   if isinstance(val, i32):
...     # type of `val` is narrowed to `i32`
...     return str_int(val)
...   elif isinstance(val, f64):
...     # else, type of `val` is narrowed to `f64`
...     return str_float(val)
...
>>>

You are talking about this file, right?

@certik certik mentioned this pull request Feb 21, 2022
@namannimmo10 namannimmo10 changed the title Implement str_int function Implement str runtime function Feb 24, 2022
@namannimmo10
Copy link
Collaborator Author

Once we merge this, I will add the rest.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this looks great!

@certik certik changed the title Implement str runtime function Implement bool runtime function Feb 24, 2022
@namannimmo10 namannimmo10 changed the title Implement bool runtime function Implement str and bool runtime functions Feb 24, 2022
@namannimmo10 namannimmo10 merged commit 7fea711 into lcompilers:main Feb 24, 2022
@namannimmo10 namannimmo10 deleted the builtin2 branch February 24, 2022 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants