felixhao28 / JSCPP

A simple C++ interpreter written in JavaScript

Home Page:https://felixhao28.github.io/JSCPP/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

<stdint.h> not found

yl12053 opened this issue · comments

I've tried to use a source code with usage in stdint.h (or cstdint).
When I tried to run in JSCPP, it returns the following error:

Error: 2:1 cannot find library: stdint.h

I tried to use the following code also,

#include <stdint.h>
int main() {
    return 0;
}

It also return the following error:
Error: 1:1 cannot find library: stdint.h

As it is an standard library, and many code relys on it,
May I ask that if the support of cstdint is planned or there are ways to use stdint.h?
I'd be very apperciated for reply.

(p.s. please use Chinese to reply if possible, 'cause I am bad in English, I'd be very thankful on that)

目前项目只实现了一小部分标准头文件,其中确实没有包含 stdint.h。

如果你需要的话可以自己去实现,模仿上面那个链接里的其它头文件去写就行。一般来说倒也不难写,就是所有的值都会用{t: ..., v:...}的结构包装了一下,所以写起来有点啰嗦,特别是涉及指针的时候。具体的结构可用参考说明文档。还有问题的话问我就行。

默认可用的头文件在 src/launcher.ts 里,记得加上之后再用JSCPP.run。

如果你实现好了可以发个PR,这样以后别人也能用上stdint.h了。:yum:

好的 那我嘗試一下
希望能寫出來吧

有要typedef的时候可以做类似
rt.int8_t = rt.primitiveType("signed char");
rt.uint8_t = rt.primitiveType("unsigned char");
这样子吗

然后是...
我真的不知道怎么定义一个新type, 包括值, 内存内的实现和pointer 那些

我看了一下stdint.h,这个头文件在做typedef,这块目前还真有点不好弄。我得抽时间改改CRuntime,让它能支持类型的alias。具体来说,应该是增加一个CRuntime::addTypeAlias的接口,然后在CRuntime::simpleType里优先检查一下是否有alias。

或者复制char的定义到int8_t这样(一直找不到

应该是可以把default.ts改一改直接加上几个type

不是那么简单,基础类型相关的代码是写死的,这种情况下必须在定义的时候就用alias来替代,否则就得改和基础类型相关的代码,让它们可以被配置。

基础类型写死了...
那可能真的得alias出来才可以有了

我仔细看了一下,实际上之前实现了typedef,甚至还有测试。所以理论上直接这样就行:

rt.registerTypedef(rt.unsignedcharTypeLiteral, "uint8_t");