Closed mertyildiran closed 3 years ago
I've started to implement this feature in feature/ptr
branch.
@naltun I've realized that num
data type can be used to achieve pointer functionality. Therefore there is no need to introduce a new data type into the language.
These are the commits that introducing fs.open()
and fs.close()
into the fs
library and they are returning the file descriptors in the form of num
data type:
The development of
fs
core library showed that we need a primitive data type to store C pointers. The keyword for this data type will beptr
. It will be a generic pointer such that every pointer can be assigned to it. That probably means it will be avoid* ptr
. Right now we are not sure if it encompasses function pointers too. Support of more pointer types can be added to the language's source according to the need later on.We will add
void* ptr
to this union such that it will look like this:We know that void pointers encompasses file pointers because the two examples below produce the same output:
ptr
data type will be used by thefs
library like this:ptr
data type should be able to assignable to hexadecimal values like0x7fffb1d7ec80
(memory address) because if you print the pointer, you will see a similar value:So the Chaos code for the pointer assignment will look like this:
print
andecho
statements should be able to print it. Type casting tonum
andstr
data types should be implemented in thetypes
library.ptr
data type should support bitwise operators. It can be implemented using type casting touintptr_t
in C:Roadmap to Implement the
ptr
data type:ptr
token tolexer.l
parser.y
enum ASTNodeType
inast.h
andchar *ast_node_type_names[]
inast.c
void* ptr
) tounion Value
insymbol.h
ast.c
and use them inparser.y
symbol.c
function.c
case
statements intointerpreter.c
for the AST node types that you've introduced.case
statements intocompiler.c
for the AST node types that you've introduced.Chaos.c
to provide an API to Chaos C extensions for the new data type.