Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native, checker: builtin module for vlang #17782

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Spydr06
Copy link
Member

@Spydr06 Spydr06 commented Mar 26, 2023

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:

  • enable the builtin module for native
  • library linking support for Linux
  • library linking support for MacOS
  • 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
Copy link
Member Author

Spydr06 commented Mar 26, 2023

Expressions to implement:

  • ast.CastExpr
  • ast.Array (and others) support for ast.Ident
  • flags field on arrays
  • support for sizes > 8 in mov_deref()
  • 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
  • ast.CharLiteral
  • ast.Nil
  • expand expression support for ast.InfixExpr
  • 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
  • support for C.xxxx C identifiers -> checker error
  • support for interlaced strings (ast.StringInterLiteral)
  • expand expression support for ast.StructInit in ast.AssignStmt
  • ast.HashStmt with other format than xx xx xx xx
  • ...

@Spydr06
Copy link
Member Author

Spydr06 commented Mar 26, 2023

Statements to implement:

  • for-in
  • multi-return for structs

@Spydr06
Copy link
Member Author

Spydr06 commented Mar 26, 2023

Other bugs found

  • ast.Alias type support
  • cannot find variable if defined in unsafe block
  • allocate_var() for sizes > 8
  • allocate_var() for sizes < 4
  • mov_reg_to_var() for all data types
  • implement ast.ConstField
  • rdx support in mul_reg; add this:
  • same for mul_div
  • support more expression of infix_expr.right in for_stmt()
  • support le ge and ne in for_stmt infix_expr.left; add this:
  • support more expressions in gen_amd64_exit()

@medvednikov
Copy link
Member

A huge and important project.

Good luck!

@Spydr06
Copy link
Member Author

Spydr06 commented Mar 26, 2023

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

@Spydr06
Copy link
Member Author

Spydr06 commented Mar 31, 2023

#17839 implements rune literals/printing, pointer comparison support and general helper function improvements

@Spydr06
Copy link
Member Author

Spydr06 commented Apr 23, 2023

#18036 should make debugging much easier

@Spydr06
Copy link
Member Author

Spydr06 commented Apr 25, 2023

Currently refactoring the codegen process: #18057

@Spydr06
Copy link
Member Author

Spydr06 commented Jun 24, 2023

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

@Spydr06
Copy link
Member Author

Spydr06 commented Jun 28, 2023

#18703 implements support for ast.Alias types

@spytheman spytheman added Needs Rebase The code of the PR must be rebased over current master before it can be approved. Breaking Change This PR introduces changes that break backward compatibility. Requires manual review. labels Aug 21, 2023
@JalonSolov JalonSolov removed the Needs Rebase The code of the PR must be rebased over current master before it can be approved. label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change This PR introduces changes that break backward compatibility. Requires manual review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants