Compiler update (basic sc ready) (#31)
* refactored structs, the scope is not needed anymore + fix passing struct in func arguments. * implemented byte arrays and added runtime tests * Added sc examples in compiler README + added quick nested if test. * Updated README
This commit is contained in:
parent
de3395fb51
commit
2345858238
19 changed files with 464 additions and 215 deletions
|
@ -6,15 +6,12 @@ import (
|
|||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/importer"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
|
@ -73,40 +70,6 @@ type archive struct {
|
|||
typeInfo *types.Info
|
||||
}
|
||||
|
||||
func resolveImports(f *ast.File) (map[string]*archive, error) {
|
||||
packages := map[string]*archive{}
|
||||
for _, imp := range f.Imports {
|
||||
path := strings.Replace(imp.Path.Value, `"`, "", 2)
|
||||
path = filepath.Join(gopath(), "src", path)
|
||||
fset := token.NewFileSet()
|
||||
pkgs, err := parser.ParseDir(fset, path, nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for name, pkg := range pkgs {
|
||||
file := ast.MergePackageFiles(pkg, 0)
|
||||
conf := types.Config{Importer: importer.Default()}
|
||||
typeInfo := &types.Info{
|
||||
Types: make(map[ast.Expr]types.TypeAndValue),
|
||||
Defs: make(map[*ast.Ident]types.Object),
|
||||
Uses: make(map[*ast.Ident]types.Object),
|
||||
Implicits: make(map[ast.Node]types.Object),
|
||||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
Scopes: make(map[ast.Node]*types.Scope),
|
||||
}
|
||||
|
||||
// Typechecker
|
||||
_, err = conf.Check("", fset, []*ast.File{file}, typeInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
packages[name] = &archive{file, typeInfo}
|
||||
}
|
||||
}
|
||||
return packages, nil
|
||||
}
|
||||
|
||||
// CompileAndSave will compile and save the file to disk.
|
||||
func CompileAndSave(src string, o *Options) error {
|
||||
if !strings.HasSuffix(src, ".go") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue