v icon indicating copy to clipboard operation
v copied to clipboard

native, checker: builtin module for vlang

Open Spydr06 opened this issue 1 year ago • 10 comments

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 for native
  • [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 their builtin 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.

Spydr06 avatar Mar 26 '23 10:03 Spydr06

Expressions to implement:

  • [ ] ast.CastExpr
  • [ ] ast.Array (and others) support for ast.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 for ast.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 in ast.IndexExpr.right.left in ast.AssignStmt
  • [x] support for C.xxxx C identifiers -> checker error
  • [ ] support for interlaced strings (ast.StringInterLiteral)
  • [ ] expand expression support for ast.StructInit in ast.AssignStmt
  • [x] ast.HashStmt with other format than xx xx xx xx
  • [ ] ...

Spydr06 avatar Mar 26 '23 10:03 Spydr06

Statements to implement:

  • [ ] for-in
  • [ ] multi-return for structs

Spydr06 avatar Mar 26 '23 10:03 Spydr06

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 in for_stmt()
  • [x] support le ge and ne in for_stmt infix_expr.left; add this:
  • [x] support more expressions in gen_amd64_exit()

Spydr06 avatar Mar 26 '23 11:03 Spydr06

A huge and important project.

Good luck!

medvednikov avatar Mar 26 '23 11:03 medvednikov

thanks! I think this could be the most significant change to make native usable, it'll take a lot of time though.

Spydr06 avatar Mar 26 '23 12:03 Spydr06

https://github.com/vlang/v/pull/17839 implements rune literals/printing, pointer comparison support and general helper function improvements

Spydr06 avatar Mar 31 '23 18:03 Spydr06

#18036 should make debugging much easier

Spydr06 avatar Apr 23 '23 09:04 Spydr06

Currently refactoring the codegen process: https://github.com/vlang/v/pull/18057

Spydr06 avatar Apr 25 '23 20:04 Spydr06

#18546 splits up the code generator into multiple files and refactors the AssignStmt codegen

Spydr06 avatar Jun 24 '23 18:06 Spydr06

https://github.com/vlang/v/pull/18703 implements support for ast.Alias types

Spydr06 avatar Jun 28 '23 17:06 Spydr06