Comments (6)
@jclark instead of two function types would it be okay if we
- Update the
Function
output to handle the case where there is no body (just the function declaration) So it will correctly output withdeclare
keyword instead ofdefine
. If I understand this correctly this behavior is not specific to just intrinsic but to any function (ref:https://llvm.org/docs/LangRef.html#functions) without a body. - Add a getIntrinsicDecleration function with signature
public function getIntrinsicDecleration(IntrinsicID id, Type[] parameterTypes) returns Function
in to theModule
class (we need a reference to the module to add the function). Here IntrisicId will a type similar toBinaryInsn
. Here I am suggesting a single function instead of one to get the id and another to get the declaration using that id because I feel at least at our current level two functions may be redundant and we can directly pass the id. This function will create theFunction
object for us setting the return types (and attributes in the future).
from nballerina.
For case 1, we still should distinguish function declaration from function definition. I don't like modelling a function declaration as a function definition with an empty body. I think we want
public type Function FunctionDefn|FunctionDecl;
and then use whichever of Function/FunctionDefn/FunctionDecl makes sense in each context.
For case 2, in LLVMGetIntrinsicDeclaration the parameter types are only for the overloaded case. I think we can more straightforwardly handle overloading by including the type in the intrinsic name. I would therefore suggest:
// No point in including "llvm." prefix here
type IntrinsicFunctionName "sadd.with.overflow.i64"|"ssub.with.overflow.i64"|"smul.with.overflow.i64";
public function getIntrinsicDeclaration(IntrinsicFunctionName name) returns FunctionDecl;
from nballerina.
For case 1, we still should distinguish function declaration from function definition. I don't like modelling a function declaration as a function definition with an empty body. I think we want
public type Function FunctionDefn|FunctionDecl;
and then use whichever of Function/FunctionDefn/FunctionDecl makes sense in each context.
For case 2, in LLVMGetIntrinsicDeclaration the parameter types are only for the overloaded case. I think we can more straightforwardly handle overloading by including the type in the intrinsic name. I would therefore suggest:
// No point in including "llvm." prefix here type IntrinsicFunctionName "sadd.with.overflow.i64"|"ssub.with.overflow.i64"|"smul.with.overflow.i64"; public function getIntrinsicDeclaration(IntrinsicFunctionName name) returns FunctionDecl;
@jclark correct me if I am wrong but if we do like public type Function FunctionDefn|FunctionDecl;
every time we need to access a method like output
or genreg
we have to check the base type (FunctionDefn
or FunctionDecl
) before calling those methods even if we implement the same method in both classes. So this will add those check to pretty much every where we use a Function
. (We may also need to add two different methods in the module class for creating functions in the future if we are to allow users to add their own function definitions) Is that okay ?
from nballerina.
I'll write some code to show what I mean.
from nballerina.
I pushed some code: it's quite a nice demo of structural typing. I've intentionally made the code less object-oriented, and more Ballerina-ish.
I wanted to make isDefn be something whose value was "declare"|"define"
, but I couldn't think of a good name for the field.
from nballerina.
Thank you. I'll add the rest of the functionalities to that
from nballerina.
Related Issues (20)
- See if we can simply `listFormulaIsEmpty()` with introduction of `undef`
- `SyntaxNode` don't distinguish between exclusive record type without fields and map
- Distinguish `record {| T...; |}` vs `map<T>` in ST and AST HOT 1
- Implement backend support for optional record fields
- Assigning a vararg function to a function value whose type has a fixed number of args is failing
- `testBirCompile` test is failling with 2201.5.0 RC1 HOT 6
- Parsing binary type descriptors with function types is failing
- Invalid record subtype relation HOT 5
- Use property based testing to validate function subtyping and application
- Add support for `never` type
- Add support for object type HOT 1
- Make complement op for function type explicit
- Confusing behaviour around compliment for "sugared" types HOT 1
- Extend BIR to support closures HOT 3
- Implement closures for final values
- Make it possible for older jBallerina versions to use nBallerina for validation HOT 2
- Implement escape analysis for closures
- Type testing with `FunctionConstOperands` fail to compile
- Use exact bit to check function value exactness
- Calculating sub-element address using GEP fails on AArch64 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nballerina.