Browse Source

add in some base objects

master
Brett Langdon 10 years ago
parent
commit
0853486674
9 changed files with 66 additions and 56 deletions
  1. +0
    -54
      cmd/gython/main.go
  2. +1
    -1
      compiler/compiler.go
  3. +10
    -0
      gython/bytes.go
  4. +20
    -1
      gython/codeobject.go
  5. +5
    -0
      gython/float.go
  6. +5
    -0
      gython/long.go
  7. +5
    -0
      gython/object.go
  8. +10
    -0
      gython/tuple.go
  9. +10
    -0
      gython/unicode.go

+ 0
- 54
cmd/gython/main.go View File

@ -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()
}

+ 1
- 1
compiler/compiler.go View File

@ -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
}


+ 10
- 0
gython/bytes.go View File

@ -0,0 +1,10 @@
package gython
type Bytes struct {
}
func (bytes *Bytes) object() {}
func NewBytes() *Bytes {
return &Bytes{}
}

+ 20
- 1
gython/codeobject.go View File

@ -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() {}

+ 5
- 0
gython/float.go View File

@ -0,0 +1,5 @@
package gython
type Float struct {
Value float64
}

+ 5
- 0
gython/long.go View File

@ -0,0 +1,5 @@
package gython
type Long struct {
Value float64
}

+ 5
- 0
gython/object.go View File

@ -0,0 +1,5 @@
package gython
type Object interface {
object()
}

+ 10
- 0
gython/tuple.go View File

@ -0,0 +1,10 @@
package gython
type Tuple struct {
}
func (tuple *Tuple) object() {}
func NewTuple() *Tuple {
return &Tuple{}
}

+ 10
- 0
gython/unicode.go View File

@ -0,0 +1,10 @@
package gython
type Unicode struct {
}
func (unicode *Unicode) object() {}
func NewUnicode() *Unicode {
return &Unicode{}
}

Loading…
Cancel
Save