Comments (7)
I will close this: for now I am concentrating on implementing the ES3 spec, so supporting type aliases and other TS features it is very very far away anyways, no point keeping the issue here. let's do it one by one, ES3 -> ES5 -> ES6 -> ... -> TS 😉
from ts2c.
@Templarian hey, well if you want to define some types explicitly, there is an existing mechanism for that via jsdoc annotation ctype, used e.g. here: https://github.com/andrei-markeev/ts2c-target-esp-idf/blob/master/headers/esp_system.h/index.d.ts#L8
But numbers in general, they are quite hard, unfortunately. They need different storage, and they need conversions between number types. As soon as we detect that a number doesn't fit into int16_t
, we need to expand the variable type into bigger number type (but first check that current platform even supports that). For this, we need detection in compile time, we need a new type, and then we need a lot of conversion/casting most likely. Very similar to how js_var
is handled currently as I see it.
See also: #31 (comment)
from ts2c.
Can that be used to set a number to int32_t?
currently not, I checked, it is implemented only for structures, but I think something like this is a good way to implement what you want.
from ts2c.
To go off of this thread this might tie into how to handle number
long term.
type short = number; // Wanting to be explicit
type int32_t = number; // Use this association to set the type
type integer = int32_t;
type int64_t = number; // Use this association to set the type
type long = int64_t;
// Unsigned
type uint8_t= number; // Use this association to set the type
type char = uint8_t;
type uint16_t = number; // Use this association to set the type
type ushort = uint16_t;
type uint64_t = number; // Use this association to set the type
type ulong = uint64_t;
// Also I guess?
type float = number;
type double = number;
Just thinking out loud, haven't looked into the code far enough to see what this requires. Hit an instance where I need int32 due to some memory related stuff. Going to try and setup my local and look into this a little (not sure how deep this number is always int16_t
is built in).
This project is already amazing by the way!
from ts2c.
Can that be used to set a number to int32_t
? Not sure I follow.
/** @ctype uint32_t * */
var foos: number = 10;
Started looking through the code trying to figure out how everything was wired up. Very much a stop gap to add type alias map, but would allow one to explicitly define the size if they know it. Would still have to wait for conversion to be handled, but easier to get around if one is explicitly setting the types.
Unfortunately it does go against the goal of number
type magically expanding/contracting as needed like in JS, which is what one would expect. Not a bad stop gap as it can be removed later once all the conversions are in proper until then it works just to explicitly define the type.
from ts2c.
I am not sure TS type alias maps well to C type alias. I think TS allows much more, C type aliases are quite restricted.
Also what you're now trying to do, it's not exactly TS anymore, but some custom language with TS syntax I guess, which should be aware of C types.
from ts2c.
Would solve the issue. Do find the below to be more readable for those wanting to be explicit.
type int64_t = number; // treat int64_t special
type integer = int32_t; // simply for readability
// ^ Throw that somewhere above
const foo: integer = 0x04000000;
vs
/**
* @ctype uint32_t
*/
var foo: number = 0x04000000;
Might look into the code a bit to see if both are possible... somehow.
from ts2c.
Related Issues (20)
- Calling C Functions
- Feature: Classes (for TS at least) HOT 8
- Finishing ES3 features once and for all HOT 6
- Compiling TypeScript to C via WebAssembly HOT 2
- Please include the original code as a comment in the transpiled code HOT 12
- Memory allocation bug HOT 6
- Function.prototype.toString HOT 1
- C functions HOT 2
- Syntax errors are handled incorrectly
- Playground autocomplete keeps repeating
- Order in which properties are added is not honored
- Incorrect generation of 'free' call
- Using C++ instead of C? HOT 4
- npm - Unexpected end of JSON
- Error when combining "for in" and "for of"
- labelled statements don't work
- Ain't work HOT 1
- arguments array ain;t work
- problem with functions called main
- error with functions returning functions 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 ts2c.