Documentation ¶
Overview ¶
Package driver is amediator to glue all packages for GoCaqml. provides a compiler function for GoCaml codes. It provides compiler functinalities for GoCaml.
Example ¶
// Compile testdata/from-mincaml/ack.ml file := filepath.FromSlash("../testdata/from-mincaml/ack.ml") src, err := locerr.NewSourceFromFile(file) if err != nil { // File not found panic(err) } d := Driver{} // Show list of tokens d.PrintTokens(src) // Show AST nodes d.PrintAST(src) // Parse file into AST parsed, err := d.Parse(src) if err != nil { panic(err) } fmt.Println(parsed) // Resolving symbols and type analysis env, inferred, err := d.SemanticAnalysis(src) if err != nil { panic(err) } // Show environment of type analysis env.Dump() // Show inferred types of all AST nodes for e, t := range inferred { fmt.Printf("Node '%s' at '%s' => Type '%s'", e.Name(), e.Pos(), t.String()) } // Show LLVM IR for the source ir, err := d.EmitLLVMIR(src) if err != nil { panic(err) } fmt.Println(ir) // Show native assembly code for the source asm, err := d.EmitAsm(src) if err != nil { panic(err) } fmt.Println(asm) // Compile the source into an executable if err := d.Compile(src); err != nil { panic(err) }
Output:
Index ¶
- type Driver
- func (d *Driver) Compile(source *locerr.Source) error
- func (d *Driver) EmitAsm(src *locerr.Source) (string, error)
- func (d *Driver) EmitLLVMIR(src *locerr.Source) (string, error)
- func (d *Driver) EmitMIR(src *locerr.Source) (*mir.Program, *types.Env, error)
- func (d *Driver) EmitObjFile(src *locerr.Source) error
- func (d *Driver) Lex(src *locerr.Source) chan token.Token
- func (d *Driver) Parse(src *locerr.Source) (*ast.AST, error)
- func (d *Driver) PrintAST(src *locerr.Source)
- func (d *Driver) PrintTokens(src *locerr.Source)
- func (d *Driver) SemanticAnalysis(src *locerr.Source) (*types.Env, sema.InferredTypes, error)
- type OptLevel
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
Driver instance to compile GoCaml code into other representations.
func (*Driver) PrintTokens ¶
PrintTokens show list of tokens lexed.
func (*Driver) SemanticAnalysis ¶
SemanticAnalysis checks symbol duplicates, infers types and so on. It returns analyzed type environment and inferred types of AST node.
Click to show internal directories.
Click to hide internal directories.