v
v copied to clipboard
native, checker: builtin module for vlang
This PR is the beginning of making the builtin module work with the native backend.
As discussed on the Discord, native
will utilize the already existing implementation of builtin used by the C backend, since libc
is the official and most consistent API on many OSs apart from Linux.
Here is a list of things that still need to be implemented to get builtin
working:
- [x] enable the
builtin
module fornative
- [x] library linking support for Linux
- [ ] library linking support for MacOS
- [x] library linking support for Windows
- [ ] global variables
- [ ] rebuild codegen of
ast.AssignStmt
to accept all expressions - [ ] missing expressions, like
ast.CastExpr
(and many more) - [ ] replace current inline implementations
println()
,assert()
,exit()
,C.syscall()
, etc. by theirbuiltin
counterparts - [ ] ...
(I will extend this list as needed)
For debugging purposes, it may be helpful if we could add a flag to toggle the inclusion of builtin
in compile_native()
, so that testing is still possible.
Please note: Of course, this PR is far from being finished and still has a lot of errors. I'll be implementing all the missing stuff over time.
Expressions to implement:
- [ ]
ast.CastExpr
- [ ]
ast.Array
(and others) support forast.Ident
- [ ]
flags
field on arrays - [x] support for sizes > 8 in
mov_deref()
- [x] support for
ast.UnsafeExpr
,ast.CallExpr
,ast.IfExpr
,ast.MapInit
,ast.InfixExpr
,ast.ParExpr
,ast.SelectorExpr
,ast.PrefixExpr
,ast.StringInterLiteral
forast.AssignStmt
- [ ]
array
support for<<
- [ ]
ast.IndexExpr
- [x]
ast.CharLiteral
- [x]
ast.Nil
- [x] expand expression support for
ast.InfixExpr
- [x] pointer support for
!=
and==
- [ ] support for pointer arithmetic
- [ ]
ast.StringInterLiteral
- [ ] support more data types in
ast.ArrayInit
, also follow aliases! - [ ]
ast.ArrayInit
outside of assignments - [ ]
in
ast.InfixExpr
support - [ ]
ast.ArrayDecompose
- [ ] support for exprs other than
ast.Ident
inast.IndexExpr.right.left
inast.AssignStmt
- [x] support for
C.xxxx
C identifiers -> checker error - [ ] support for interlaced strings (
ast.StringInterLiteral
) - [ ] expand expression support for
ast.StructInit
inast.AssignStmt
- [x]
ast.HashStmt
with other format thanxx xx xx xx
- [ ] ...
Statements to implement:
- [ ] for-in
- [ ] multi-return for structs
Other bugs found
- [x]
ast.Alias
type support - [x] cannot find variable if defined in
unsafe
block - [x]
allocate_var()
for sizes > 8 - [x]
allocate_var()
for sizes < 4 - [x]
mov_reg_to_var()
for all data types - [ ] implement
ast.ConstField
- [x] rdx support in
mul_reg
; add this: - [x] same for
mul_div
- [ ] support more expression of
infix_expr.right
infor_stmt()
- [x] support
le
ge
andne
infor_stmt
infix_expr.left
; add this: - [x] support more expressions in
gen_amd64_exit()
A huge and important project.
Good luck!
thanks! I think this could be the most significant change to make native usable, it'll take a lot of time though.
https://github.com/vlang/v/pull/17839 implements rune literals/printing, pointer comparison support and general helper function improvements
#18036 should make debugging much easier
Currently refactoring the codegen process: https://github.com/vlang/v/pull/18057
#18546 splits up the code generator into multiple files and refactors the AssignStmt codegen
https://github.com/vlang/v/pull/18703 implements support for ast.Alias
types