Skip to content
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

Add ability to declare C dependencies #10

Closed
TobiasWrigstad opened this issue Jul 18, 2014 · 19 comments
Closed

Add ability to declare C dependencies #10

TobiasWrigstad opened this issue Jul 18, 2014 · 19 comments

Comments

@TobiasWrigstad
Copy link
Contributor

Non-trivial use of embed ... end requires ability to include header files and also build dependencies. A possible mock syntax would be to enable lib and inc statements inside embed blocks, e.g.,

embed T 
  inc ./relative/path/to/bitset.h 
  lib ./relative/path/to/bitset.o
  ...
end

The goal is to be able to skip having to generate a C file and manually edit it and compile it.

@EliasC
Copy link
Contributor

EliasC commented Jul 19, 2014

Let's add this as top-level constructs, i.e. on the same level as class-declarations. We're going to need the same kind of machinery when we do imports and stuff anyway.

_c_inc ./relative/path/to/bitset.h
_c_lib ./relative/path/to/bitset.o

import EncLib

class Foo
    ...

@TobiasWrigstad
Copy link
Contributor Author

Sounds good.

@kaeluka
Copy link
Contributor

kaeluka commented Jul 19, 2014

I can take care of this tomorrow.

@kaeluka kaeluka self-assigned this Jul 19, 2014
@TobiasWrigstad
Copy link
Contributor Author

Great! Thanks!

@kaeluka
Copy link
Contributor

kaeluka commented Jul 20, 2014

Although prettier, @EliasC's approach lacks power. I'm going to implement a toplevel embed statement that let's you merge in C code, just as @TobiasWrigstad suggested originally.

Example use case: some libs require you to use a preprocessor #define before you include them.

@EliasC
Copy link
Contributor

EliasC commented Jul 20, 2014

Agreed! This will also allow you to define C-functions in your program, which could be useful!

kaeluka pushed a commit that referenced this issue Jul 20, 2014
You can now have one embed block at the beginning of each file:

    embed
      int foo(int x) {
        return 2*x;
      }
    end

    class Main
      def main() : void
        print embed int foo(2); end

This program should output:

    4

when run.
@kaeluka
Copy link
Contributor

kaeluka commented Jul 20, 2014

@kaeluka kaeluka closed this as completed Jul 20, 2014
@TobiasWrigstad
Copy link
Contributor Author

I am not sure it was correct to close this one. I believe what you have done is very useful (THANKS!), but it is not all what this ticket was about. This allows me to do includes at the top-level which is great, but it does not take care of the lib part, which was more about telling the encore compiler what compilation string to generate with libraries, etc. Granted, the most urgent part is done, but let's make sure the other part is at least discussed and not lost.

@supercooldave
Copy link

Looks like we are after an FFI between Encore and C. Adriaan has expertise in this area.

Sent from my iPhone

On 20/07/2014, at 19:03, TobiasWrigstad notifications@github.com wrote:

I am not sure it was correct to close this one. I believe what you have done is very useful (THANKS!)l, but it is not all what this ticket was about. This allows me to do includes at the top-level which is great, but it does not take care of the lib part, which was more about telling the encore compiler what compilation string to generate with libraries, etc. Granted, the most urgent part is done, but let's make sure the other part is at least discussed and not lost.


Reply to this email directly or view it on GitHub.

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

@albertnetymk
Copy link
Contributor

The lib dependency shouldn't be addressed on per file based. The included
header ensures the current unit to compile, and the lib only comes into
account in linking.

It's possible that one lib is shared by multiple units in one project, and
there should be one place to list the external lib dependency for the final
executable, instead of each object file.
On Jul 20, 2014 7:03 PM, "TobiasWrigstad" notifications@github.com wrote:

I am not sure it was correct to close this one. I believe what you have
done is very useful (THANKS!)l, but it is not all what this ticket was
about. This allows me to do includes at the top-level which is great, but
it does not take care of the lib part, which was more about telling the
encore compiler what compilation string to generate with libraries, etc.
Granted, the most urgent part is done, but let's make sure the other part
is at least discussed and not lost.


Reply to this email directly or view it on GitHub
#10 (comment)
.

@TobiasWrigstad
Copy link
Contributor Author

The embed is just a hacky way to get around stuff that we currently do not have. Your comments might be valid if we were talking about a more mature feature. Right now, we are just trying to get stuff to run.
Right now, as soon as we drop to C level, we can no longer use the encore compiler to compile our programs. A good way forward IMO is to enable the compiler to generate the right linking flags so that we can get programs to run with a minimum of hassle.

Once we are at the stage where there could even be one "project", we can revisit this. If we build a C FFI we do this good. Right now, we move forward. No external dependencies.

@kaeluka
Copy link
Contributor

kaeluka commented Jul 20, 2014

The embed is just a hacky way to get around stuff that we currently do not have.

But hacky features also need to be implemented in a specific way. What should the linker flags be if two equal-named .o files are requested by different files?

As we already have a lib directory, I suggest using that: the .o files you want to use have to be in the same directory as the .enc file or in the lib directory. Saves us wasting time on a hack and avoids the pitfall that @albertnetymk identified.

@TobiasWrigstad
Copy link
Contributor Author

I wasn't aware we could compile different files at the same time. Can we?

@EliasC
Copy link
Contributor

EliasC commented Jul 20, 2014

We can not.

@kaeluka
Copy link
Contributor

kaeluka commented Jul 20, 2014

No, but we're planning to do that soon, was my view.

Anyway, I just pushed a small temporary fix (41b00ee) that changes the compiler to use the *.o files in the current directory. The embed-tl test is an example of usage. This should allow you, @TobiasWrigstad, to continue. Next week, we can talk about how exactly this feature should look. Sounds good?

I'm reopening this ticket now.

@kaeluka kaeluka reopened this Jul 20, 2014
@TobiasWrigstad
Copy link
Contributor Author

Thanks @kaeluka! I'll look at the temp fix. I suggest we might not look at how to fix this the coming week, but put several tickets in the system for compiling multiple files, C FFI, the works. The most urgent thing, though is a very short language spec that documents how Encore works.

@kaeluka
Copy link
Contributor

kaeluka commented Jul 20, 2014

@TobiasWrigstad see #17

@TobiasWrigstad
Copy link
Contributor Author

@kaeluka What is the status of this? Can this be closed?

@kaeluka kaeluka closed this as completed Sep 15, 2015
@TobiasWrigstad
Copy link
Contributor Author

Thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants