diff --git a/cmd/gython/main.go b/cmd/gython/main.go deleted file mode 100644 index e1b5689..0000000 --- a/cmd/gython/main.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/brettlangdon/gython/ast" - "github.com/brettlangdon/gython/compiler" - "github.com/brettlangdon/gython/grammar" - "github.com/brettlangdon/gython/scanner" - "github.com/brettlangdon/gython/token" -) - -func tokenize() { - tokenizer := scanner.NewScanner(os.Stdin) - for { - tok := tokenizer.NextToken() - tokenRange := fmt.Sprintf("%d,%d-%d,%d:", tok.LineStart, tok.ColumnStart, tok.LineEnd, tok.ColumnEnd) - literalRep := fmt.Sprintf("%#v", tok.Literal) - fmt.Printf("%-20s%-15s%-15s\n", tokenRange, tok.String(), literalRep) - if tok.ID == token.ENDMARKER || tok.ID == token.ERRORTOKEN { - break - } - } -} - -func parseGrammar() *grammar.FileInput { - tokenizer := scanner.NewScanner(os.Stdin) - gp := grammar.NewGrammarParser(tokenizer) - return gp.Parse() -} - -func parseAST() ast.Mod { - start := parseGrammar() - mod, err := ast.ASTFromGrammar(start) - if err != nil { - panic(err) - } - return mod -} - -func compile() { - root := parseAST() - codeobject := compiler.CompileAST(root) - fmt.Println(codeobject) -} - -func main() { - // start := parseGrammar() - // fmt.Println(start.Repr()) - // root := parseAST() - // fmt.Println(root) - compile() -} diff --git a/compiler/compiler.go b/compiler/compiler.go index 405b16d..70f71d6 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -49,7 +49,7 @@ func (compiler *Compiler) assemble(addNone bool) *gython.CodeObject { compiler.addOp(bytecode.RETURN_VALUE) } - codeobject := gython.NewCodeObject() + codeobject := gython.NewCodeObject([]byte{}, []byte{}, 0) return codeobject } diff --git a/gython/bytes.go b/gython/bytes.go new file mode 100644 index 0000000..2090d1d --- /dev/null +++ b/gython/bytes.go @@ -0,0 +1,10 @@ +package gython + +type Bytes struct { +} + +func (bytes *Bytes) object() {} + +func NewBytes() *Bytes { + return &Bytes{} +} diff --git a/gython/codeobject.go b/gython/codeobject.go index d883980..07f0457 100644 --- a/gython/codeobject.go +++ b/gython/codeobject.go @@ -1,8 +1,27 @@ package gython type CodeObject struct { + ArgCount int64 + KeywordOnlyArgCount int64 + LocalsCount int64 + StackSize int64 + Flags int64 + + Code *Bytes + Constants *Tuple + Names *Tuple + VariableNames *Tuple + FreeVariableNames *Tuple + CellVariableNames *Tuple + + Filename *Unicode + Name *Unicode + FirstLineNumber int64 + LineNumberTable *Bytes } -func NewCodeObject() *CodeObject { +func NewCodeObject(filename []byte, name []byte, firstLineNumber int64) *CodeObject { return &CodeObject{} } + +func (codeobject *CodeObject) object() {} diff --git a/gython/float.go b/gython/float.go new file mode 100644 index 0000000..cffbdf7 --- /dev/null +++ b/gython/float.go @@ -0,0 +1,5 @@ +package gython + +type Float struct { + Value float64 +} diff --git a/gython/long.go b/gython/long.go new file mode 100644 index 0000000..3cee8ea --- /dev/null +++ b/gython/long.go @@ -0,0 +1,5 @@ +package gython + +type Long struct { + Value float64 +} diff --git a/gython/object.go b/gython/object.go new file mode 100644 index 0000000..b1d648b --- /dev/null +++ b/gython/object.go @@ -0,0 +1,5 @@ +package gython + +type Object interface { + object() +} diff --git a/gython/tuple.go b/gython/tuple.go new file mode 100644 index 0000000..b1f7ce0 --- /dev/null +++ b/gython/tuple.go @@ -0,0 +1,10 @@ +package gython + +type Tuple struct { +} + +func (tuple *Tuple) object() {} + +func NewTuple() *Tuple { + return &Tuple{} +} diff --git a/gython/unicode.go b/gython/unicode.go new file mode 100644 index 0000000..26a15fd --- /dev/null +++ b/gython/unicode.go @@ -0,0 +1,10 @@ +package gython + +type Unicode struct { +} + +func (unicode *Unicode) object() {} + +func NewUnicode() *Unicode { + return &Unicode{} +}