jinko icon indicating copy to clipboard operation
jinko copied to clipboard

Add Vector/Array type

Open CohenArthur opened this issue 4 years ago • 2 comments

CohenArthur avatar Oct 15 '21 14:10 CohenArthur

So we have to consider a few things here, for example instanciation. How do we instanciate a vector with any number of elements without entirely changing the language? Should we start implementing macros? Should it be a JkInst? Should we add a specifier to the function declaration to mark it as variadic?

CohenArthur avatar Nov 30 '21 09:11 CohenArthur

The Vector type could be responsible for the low level plumbing and allocate memory itself. We could have the following allocating API:

type pointer; // builtin
// or
type Pointer(raw_addr: int);

ext func allocate(size: int) -> pointer;
ext func reallocate(ptr: pointer) -> pointer;
ext func deallocate(ptr: pointer);
ext func unsafe_write[T](ptr: pointer, value: T);
ext func unsafe_read[T](ptr: pointer) -> T;

We could then, upon dropping a pointer, free it in the garbage collector

CohenArthur avatar Nov 30 '21 11:11 CohenArthur