Comments (6)
Whew, that's a lot of good questions! Bear with me here.
Your general approach is great, and I think it should work.
The comment about "wide character and string literals" is still accurate but, in hindsight, confusing to read: neither wide characters, nor wide string literals, are implemented. String literals composed of not-wide characters work fine. π
From my experiments, passing -U__FILE__ -U__LINE__
also works, and seems nicer than defining them to expand to themselves. You can implement that in Main.md
; just add these names to the same list that has __BLOCKS__
in it.
Getting the name of the current function is going to be a little tricky. I promised you wouldn't have to think about monads and you're making a liar of me. π My suggestion: get __FILE__
and __LINE__
working in one patch, let me test and merge that, and then let's chat about how to plumb the function name into the right place.
I think once you fix the CType
values for those two symbols, you'll be pretty much there, right?
By the way, I think C99 spells the function name __func__
, and GCC also has a __PRETTY_FUNCTION__
that some things use. So when you tackle function names, let's make all three spellings work equivalently.
from corrode.
So, I got confused about dynamic generation (terminology?) of map entries and adding simple static entries:
builtinSymbols =
[ ("__builtin_bswap" ++ show w,
("u" ++ show w ++ "::swap_bytes",
Just (Rust.Immutable,
IsFunc (IsInt Unsigned (BitWidth w))
[(Nothing, IsInt Unsigned (BitWidth w))] False
)))
| w <- [16, 32, 64]
]
I wanted to put a map element delimiting comma after the | w <-
line, but that definitely didn't work. So I did what feels hacky, but works:
...
| w <- [16, 32, 64]
]
++
[ ("__FUNCTION__",
("pantalones",
Just (Rust.Immutable, charType
)))
]
The returned string is temporary, because I haven't done the function lookup yet, and the CType
is obviously bollocks. getSymbolIdent
requires that I return a CType
, but I can't figure out what to use for a string literal⦠probably because:
TODO: Translate wide character and string literals.
D'oh!
How am I doing here?
Meanwhile, I now realise that __FILE__
and __LINE__
are predefined macros in the C preprocessor, which seems nice, until you realise they're correct for C but not for Rust. Hmm. Seems like the easiest way around this is to add -D__FILE__=__FILE__ -D__LINE__=__LINE__
to the cc -E
flags.
from corrode.
Wait, I can use IsPtr
/ as_ptr()
, as per the C string literal conversion below that FIXME. (Perhaps that FIXME is out of date.)
from corrode.
Ignoring the CType
(and function name) for a moment, is this even remotely sensible?
...
| w <- [16, 32, 64]
]
++
[ ("__FILE__",
("file!().as_ptr()",
Just (Rust.Immutable,
IsFunc (IsInt Unsigned (BitWidth 32))
[(Nothing, IsInt Unsigned (BitWidth 32))] False
)))
,
("__LINE__",
("line!()",
Just (Rust.Immutable,
IsFunc (IsInt Unsigned (BitWidth 32))
[(Nothing, IsInt Unsigned (BitWidth 32))] False
)))
,
("__FUNCTION__",
("b\"function\\0\".as_ptr()",
Just (Rust.Immutable,
IsFunc (IsInt Unsigned (BitWidth 32))
[(Nothing, IsInt Unsigned (BitWidth 32))] False
)))
]
from corrode.
Hey @jdub, I said I'd help you implement this once I got your __FILE__
/__LINE__
patch merged.
Well: After I merged that patch I realized that (1) the way I suggested you do that was kind of a weird way, and really I needed to clean up symbol lookup; and (2) I wasn't prepared to teach enough about reader monads to explain how to implement __FUNCTION__
.
So I implemented this translation myself. I hope you'll forgive me for failing my pedagogical goals here! If you're interested, I'm hoping that the relevant two commits are pretty clear (a263511 and cefa0cf, respectively), and feel free to ask questions.
Note that the assert
macro still doesn't generate valid Rust, at least on glibc, because of issue #76. But at least Corrode is happy to generate something for it, now!
from corrode.
Oh, a263511 makes craploads more sense! I thought the stringy literalness of that was ooky compared to everything else.
I'll have to read cefa0cf in context to better understand how getFunctionName
interacts with everything else, but I'm glad it fits my assumptions of how it would fit in with getSymbolIdent
.
from corrode.
Related Issues (20)
- exit() not declared as noreturn
- Fails on global uninitialised structs HOT 2
- box, true and false are not renamed HOT 2
- Wrong code generation when using the zero variant of an enum in `if` clauses
- Use of possibly uninitialized reference(s)
- C volatile pointers do not translate to rust volatile accesses
- enums should derive Debug, PartialOrd & PartialEq?
- Arrays without explicit size
- Math on enums generates invalid Rust
- Using corrode with cmake HOT 2
- Support for C bitfields HOT 1
- Corrode has trouble with "implicit ints" in K&R style HOT 2
- Use the libc crate to provide external functions and c-like types
- Attempt to initialize static enums
- Loop transformations can bring variable references out of scope
- Ignore/support __builtin_ functions
- Add the ability to pass multiple files to corrode
- It is only a suggestion or lets say Idea
- FTBFS: fails to build on OpenSUSE/Tumbleweed
- Build failed HOT 2
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 corrode.