Code Monkey home page Code Monkey logo

Comments (7)

andrei-markeev avatar andrei-markeev commented on August 22, 2024 2

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.

andrei-markeev avatar andrei-markeev commented on August 22, 2024 1

@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.

andrei-markeev avatar andrei-markeev commented on August 22, 2024 1

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.

Templarian avatar Templarian commented on August 22, 2024

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.

Templarian avatar Templarian commented on August 22, 2024

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.

andrei-markeev avatar andrei-markeev commented on August 22, 2024

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.

Templarian avatar Templarian commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.