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

Ast semantic analysis #1

Merged
merged 11 commits into from
Sep 12, 2023
Merged

Ast semantic analysis #1

merged 11 commits into from
Sep 12, 2023

Conversation

Daniel-Boll
Copy link
Member

No description provided.

Daniel-Boll and others added 11 commits March 1, 2023 22:54
feat: add hexadecimal number to test.pile
feat: add codegen module to lib.rs
feat: add wasm code generator to codegen module
feat: add parse_ast function to parse.rs
feat: add AstNode struct to parse.rs
feat: print abstract syntax tree in main.rs
refactor: change parse function in parse.rs to return an Option<AstNode> instead of ()
refactor: change root node symbol in parse_ast function to "R" instead of "Program"
This commit adds support for a stack data structure in LLVM. It includes a new module `globals/stack.rs` that defines the `Stack` struct and its methods. The `Stack` struct has a `stack` field that represents the global array that stores the elements of the stack, a `top` field that represents a pointer to the top of the stack, and a `size` field that represents the maximum size of the stack.

The `Stack` struct has methods to check if the stack is full, store an element in the stack, and get the `Stack` instance. The `Stack` instance is created using the `create` method.

This commit also adds a new module `codegen/llvm/builtins/abort.rs` that defines the `AbortBuiltinFunction` struct and its methods. The `AbortBuiltinFunction` struct has methods to declare and get the `abort` function.

feat: add LLVM code generator

Add LLVM code generator to generate LLVM IR from the AST. The LLVM code generator
is added as a new module in the `codegen` module. The `LLVMCodeGenerator` struct
is defined in the `llvm` module. The `LLVMManager` struct is defined in the
`llvm/manager.rs` file. The `LLVMManager` struct is used to manage the LLVM
context, module, and builder. The `LLVMCodeGenerator` struct implements the
`CodeGenerator` trait. The `generate` method of the `LLVMCodeGenerator` struct
takes an AST as input and generates LLVM IR from it.

The `choose_code_generator` function is removed and replaced with the
`code_generator` function. The `code_generator` function takes a
`CodeGeneratorTarget` enum as input and returns a `Box<dyn CodeGenerator>`. The
`CodeGeneratorTarget` enum has
…CTION_NAME` constant

feat(abort.rs): Declare `declare` function in `AbortBuiltin` struct to declare `abort` function
feat(abort.rs): Implement `declare` function in `AbortBuiltin` struct to declare `abort` function
feat(abort.rs): Implement `call_from_values` function in `AbortBuiltin` struct to call `abort` function with values
feat(abort.rs): Implement `get` function in `AbortBuiltin` struct to get `abort` function
feat(pop.rs): Create `PopBuiltin` struct
feat(pop.rs): Implement `declare` function in `PopBuiltin` struct to declare `pop` function
feat(pop.rs): Implement `call` function in `PopBuiltin` struct to call `pop` function
feat(pop.rs): Implement `get` function in `PopBuiltin`

feat(llvm): add support for arithmetic operations

- Add support for arithmetic operations such as plus, minus, times, divide, and modulo.
- Implement code generation for each arithmetic operation.
- Use LLVM IR instructions to perform the arithmetic operations.
- Push the result of the operation onto the stack using the PushBuiltin function.
- Pop the operands from the stack using the PopBuiltin function.
- The generated code is saved to an LLVM module and printed to a file named "output.ll".
- The generated LLVM IR code is compiled using the clang command to produce an executable named "output".

feat(llvm): add support for generating LLVM IR code for arithmetic operations
feat(llvm): add support for generating LLVM IR code for stack operations
feat(llvm): add support for generating LLVM IR code for stack push operation
feat(llvm): add support for generating LLVM IR code for stack dump operation
fix(llvm): fix stack implementation to use Compiler instead of LLVMManager
fix(llvm): fix stack implementation to use Compiler's types and functions
fix(llvm): fix stack implementation to use Compiler's builder for code generation
fix(llvm): fix stack implementation to use Compiler's module for code generation
fix(llvm): fix stack implementation to use Compiler's context for code generation
fix(llvm): fix stack implementation to use Compiler's load and store functions
fix(llvm): fix stack implementation to use Compiler's basic value enum
fix(llvm): fix stack implementation to use Compiler's pointer value
fix(llvm): fix stack implementation to use Compiler's

chore(llvm): refactor LLVMCodeGenerator module structure
feat(llvm): add support for generating LLVM IR code from AST
fix(llvm): ensure stack is dropped before context
feat(llvm): declare external functions and builtins in LLVMCodeGenerator
feat(llvm): generate LLVM IR code from AST using Compiler
chore(llvm): remove unused modules and files in llvm/utils directory
feat(codegen/vm): implement virtual machine code generation

feat(codegen/wasm): implement WebAssembly code generation

feat(interpreter/vm): implement virtual machine interpreter

feat(interpreter/vm/arithmetic): implement arithmetic instructions for the virtual machine

feat(interpreter/vm/comparison): implement comparison instructions for the virtual machine

feat(interpreter/vm/stack): implement stack manipulation instructions for the virtual machine

feat(interpreter/vm/value): implement value types for the virtual machine

feat(interpreter): add support for running virtual machine bytecode

feat: add support for stack operations in the virtual machine

feat: add support for dump instruction in the virtual machine

feat: add support for dup instruction in the virtual machine

feat: add support for pop instruction in the virtual machine

feat: add support for push instruction in the virtual machine

feat: add support for value types in the virtual machine

feat: add support for integer literals in the lexer

feat: add support for float literals in the lexer

feat: add support for string literals in the lexer

feat: add support for arithmetic operators in the lexer

feat: add support for comparison operators in the lexer

feat: add support for stack operators in the lexer

feat: add support for def type in the lexer

feat: add support for identifiers in the lexer

feat: add support for end of input in the lexer

feat: add support for comments in the lexer

feat: add support for interpreter module

feat: add support for virtual machine

chore(parse.rs): remove println statement
feat(parse.rs): add token field to AstNode struct
feat(parse.rs): add AstNodeIter struct and implement Iterator for AstNodeIter
feat(parse.rs): add AstNodeDetailedIter struct and implement Iterator for AstNodeDetailedIter
feat(parse.rs): implement Display trait for AstNode
feat(parse.rs): modify parse_ast function to populate token field in AstNode struct
feat(Cargo.toml): add serde and bincode dependencies
feat(Cargo.toml): add once_cell dependency
feat(assets/glc/lang.glc): add support for string literals in <statement>
feat(assets/lang/arithmetic.pile): add arithmetic operations in Pile
feat(assets/lang/conditional_and_branching.pile): add conditional and branching operations in Pile
feat(assets/lang/test.pile): add test code in Pile
feat(assets/lang/write.pile): add write code in Pile
feat(justfile): add run and clean aliases
feat(conditional_and_branching.pile): add if-else-end block
fix(mod.rs): fix generate_byte_code function to use self instead of Self
feat(mod.rs): add support for JumpIfNotTrue, Jump, and Ignore bytecodes
fix(parse.rs): fix parse_ast function to return MietteResult
feat(cli/compile.rs): implement compile subcommand
feat(cli/run.rs): implement run subcommand
feat(codegen/mod.rs): add filename parameter to generate method
feat(codegen/vm/mod.rs): add filename parameter to encode_byte_code method
fix(main.rs): use Cli struct to parse command line arguments and execute appropriate subcommand
Signed-off-by: Felipi Lima Matozinho <[email protected]>
…ile into ast-semantic-analysis

Signed-off-by: Felipi Lima Matozinho <[email protected]>
@Daniel-Boll Daniel-Boll merged commit cf6e893 into main Sep 12, 2023
1 check passed
@ghost
Copy link

ghost commented Sep 12, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants