ark-lang / ark

A compiled systems programming language written in Go using the LLVM framework
https://ark-lang.github.io/
MIT License
677 stars 47 forks source link

implement attributes for calling convention, target/exclude_(os/arch), inline + export modifier #500

Closed felixangell closed 8 years ago

felixangell commented 9 years ago

Blocked by #577 ??

A modifier for exporting functions should be introduced, e.g:

export func add() {

}

Also, a way of specifying call convention via attributes, e.g:

[call_conv="fastcc"]
export func add() {

}

UPDATE: also the attributes from #513

[target_os="linux"] -> following declaration is only compiled on the given platform, should also be a way to invert this so for instance, it would never compile on the given platform.
[target_arch="x86_64"] -> following declaration is only compiled if the arch matches the given arch.
[inline="always"], [inline="never"], [inline] -> will inline always, never inline, or inline when the compiler thinks is necessary.
[exclude_os=""] -> not compiled for given os
[exclude_arch=""] -> not compiled for given arch

and the options:

inline options: always, never, maybe
os options: linux, windows, mac, ...?
arch options:
alpha   - Alpha [experimental]
arm     - ARM
bfin    - Analog Devices Blackfin [experimental]
c       - C backend
cellspu - STI CBEA Cell SPU [experimental]
cpp     - C++ backend
mblaze  - MBlaze
mips    - Mips
mipsel  - Mipsel
msp430  - MSP430 [experimental]
ppc32   - PowerPC 32
ppc64   - PowerPC 64
ptx32   - PTX (32-bit) [Experimental]
ptx64   - PTX (64-bit) [Experimental]
sparc   - Sparc
sparcv9 - Sparc V9
systemz - SystemZ
thumb   - Thumb
x86     - 32-bit X86: Pentium-Pro and above
x86-64  - 64-bit X86: EM64T and AMD64
xcore   - XCore
Acconut commented 8 years ago

I am not sure about the maybe value for the inline attribute. What about using hint since it describes its functionality better.

From LLVM's reference (http://llvm.org/docs/LangRef.html#function-attributes):

inlinehint: This attribute indicates that the source code contained a hint that inlining this function is desirable (such as the “inline” keyword in C/C++). It is just a hint; it imposes no requirements on the inliner.

(from https://github.com/ark-lang/ark/pull/644#issuecomment-174019805)

felixangell commented 8 years ago

@Acconut :+1: on hint over maybe :)

Acconut commented 8 years ago

The target* and exclude* attributes are a bit restrictive by design in my mind. For example, how would you include a function on linux and darwin?

It would be cool to have something like [include(os="linux" || os="darwin")] although that is quite though and somewhat an overkill for now. :)

felixangell commented 8 years ago

I could be wrong here, but depending how it's implemented you might be able to add multiple include_os attributes and it would work as expected. Though, I quite like the idea of having the ORs/ANDs (and other operations?) for some basic logic when it comes to the attributes.

raoulvdberge commented 8 years ago

IMO I don't believe logic belongs in attributes, multiple attributes should work fine.

Acconut commented 8 years ago

AFAIK mutliple attributes are not allowed ATM since they are stored in a simple map: https://github.com/ark-lang/ark/blob/master/src/parser/attr.go#L19

Acconut commented 8 years ago

Maybe the function etc. including and excluding should be implemented using macros, once they are shipped. I guess, this enables more flexibility while keeping attributes simple (as @raoulvdberge mentions) and does not require to implement the attributes for every possible declaration type.

kiljacken commented 8 years ago

We'll definitively want a better way than attributes to handle ex-/including code from certain archs/OSs

MovingtoMars commented 8 years ago

Closing this and making a separate issue for target-conditional compilation.