Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

For example, Objective-C, Swift and Ruby (i.e. RubyMotion) integrate with the Cocoa framework.

Is this done via linked libraries? I assume they call functions in existing binaries instead of simply recreating some common interface.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

By many different methods, not easily reduced to just a few paras. Here are some, in roughly ascending order of abstraction.

  1. The OS implements one or more privileged instructions (trap, syscall, etc). The compiler emits code to translate certain language constructs into those instructions. [ASM]
  2. The OS provides an API in a form compatible with the external interfaces of a specific target language (one that ordinarily provides a mechanism for calling separately compiled translation units). Calls to the OS are indistinguishable from calls to user code. [C]
  3. The OS provides binding layers in a form intended to be compatible with the external interfaces of a specific various target languages. Calls to the OS are similar to calls to user code. [C++, many]
  4. The OS implements an API in a form designed to be callable from various languages but native to none, along with binding layers. This mechanism may also be used for calls to user code. [VB, COM]
  5. The OS provides a 'framework' with an extensive range of capabilities, in lieu of direct access to its services. The compiler usually provides privileged access to the framework, as well as allowing calls that are indistinguishable from user code. [C#, Java, Objective-C*]

These mechanisms are often layered. The calls at a higher layer are translated into calls at a lower layer behind the scenes. Objective-C is an odd one, in providing two different API mechanisms.

At a physical deployment level, the services can be provided by:

  1. Generated code 'traps' directly into the OS, often provided as macros.
  2. OS library code is statically linked (LIB), often provided as 'header' files.
  3. OS library code is dynamically linked using low level mechanisms similar to those used by the OS itself, often via headers and an intervening static lib (DLL, SO).
  4. OS library code is dynamically linked using a mechanism that is part of the API specification, using mechanisms specific to the spec (COM, .NET)

Wherever two disparate technologies (such as Ruby and Cocoa) are able to interact, there is usually a binding layer created by a tool, or manually. Eventually it will use one of the mechanisms above (unless I've missed something).

share|improve this answer
    
Short question, over 24 hours, one edit, 127 views and no comments or answers. Odd, but worth a go. –  david.pfx Jul 3 at 15:00
    
What's odd about it? BTW, I ran into programming language bindings in my search which seems very relevant and you seem to have confirmed that concept of bindings. I found that most languages can interface with C object format; so it's kind of a de facto method of binding one language to a binary interface. +1 for mention of lower level syscalls which I interpret as interrupts (is that accurate?). –  Brenden Jul 3 at 16:07
    
I tried to fix your ordered list formatting, but I couldn't meet the 6 character minimum edit. Can you add a new line before your 2nd list? Thanks. –  Brenden Jul 3 at 16:10
    
Odd for no-one to even comment. Yes, C API is very common (#2 above), but lacks type info. COM and higher levels provide type info. Syscalls can be interrupts, but can also be ring gates or just an arbitrary illegal instruction; interrupts are more specific to device handling. –  david.pfx Jul 4 at 3:26
    
@Brenden: Thanks for the pointer. Fixed, and added a few words. –  david.pfx Jul 4 at 3:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.