Skip to content

Commit

Permalink
Reduce diff size
Browse files Browse the repository at this point in the history
ast/node.go: reduce diff
func.go: revert to master
parser/lexer.go: revert to master
vm.go: revert some parts
runtime.go: revert print stuff
tc39_test.go: comment on dumpcode
builtin_promise.go: formatting changes
  • Loading branch information
mstoykov committed Nov 16, 2023
1 parent 7aaf816 commit 178b2c3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 76 deletions.
90 changes: 46 additions & 44 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,38 +307,39 @@ type (

// _expressionNode

func (*ArrayLiteral) _expressionNode() {}
func (*AssignExpression) _expressionNode() {}
func (*YieldExpression) _expressionNode() {}
func (*AwaitExpression) _expressionNode() {}
func (*BadExpression) _expressionNode() {}
func (*BinaryExpression) _expressionNode() {}
func (*BooleanLiteral) _expressionNode() {}
func (*BracketExpression) _expressionNode() {}
func (*CallExpression) _expressionNode() {}
func (*ConditionalExpression) _expressionNode() {}
func (*DotExpression) _expressionNode() {}
func (*PrivateDotExpression) _expressionNode() {}
func (*FunctionLiteral) _expressionNode() {}
func (*ClassLiteral) _expressionNode() {}
func (*ArrowFunctionLiteral) _expressionNode() {}
func (*Identifier) _expressionNode() {}
func (*NewExpression) _expressionNode() {}
func (*NullLiteral) _expressionNode() {}
func (*NumberLiteral) _expressionNode() {}
func (*ObjectLiteral) _expressionNode() {}
func (*RegExpLiteral) _expressionNode() {}
func (*SequenceExpression) _expressionNode() {}
func (*StringLiteral) _expressionNode() {}
func (*TemplateLiteral) _expressionNode() {}
func (*ThisExpression) _expressionNode() {}
func (*SuperExpression) _expressionNode() {}
func (*ArrayLiteral) _expressionNode() {}
func (*AssignExpression) _expressionNode() {}
func (*YieldExpression) _expressionNode() {}
func (*AwaitExpression) _expressionNode() {}
func (*BadExpression) _expressionNode() {}
func (*BinaryExpression) _expressionNode() {}
func (*BooleanLiteral) _expressionNode() {}
func (*BracketExpression) _expressionNode() {}
func (*CallExpression) _expressionNode() {}
func (*ConditionalExpression) _expressionNode() {}
func (*DotExpression) _expressionNode() {}
func (*PrivateDotExpression) _expressionNode() {}
func (*FunctionLiteral) _expressionNode() {}
func (*ClassLiteral) _expressionNode() {}
func (*ArrowFunctionLiteral) _expressionNode() {}
func (*Identifier) _expressionNode() {}
func (*NewExpression) _expressionNode() {}
func (*NullLiteral) _expressionNode() {}
func (*NumberLiteral) _expressionNode() {}
func (*ObjectLiteral) _expressionNode() {}
func (*RegExpLiteral) _expressionNode() {}
func (*SequenceExpression) _expressionNode() {}
func (*StringLiteral) _expressionNode() {}
func (*TemplateLiteral) _expressionNode() {}
func (*ThisExpression) _expressionNode() {}
func (*SuperExpression) _expressionNode() {}
func (*UnaryExpression) _expressionNode() {}
func (*MetaProperty) _expressionNode() {}
func (*ObjectPattern) _expressionNode() {}
func (*ArrayPattern) _expressionNode() {}
func (*Binding) _expressionNode() {}

func (*DynamicImportExpression) _expressionNode() {}
func (*UnaryExpression) _expressionNode() {}
func (*MetaProperty) _expressionNode() {}
func (*ObjectPattern) _expressionNode() {}
func (*ArrayPattern) _expressionNode() {}
func (*Binding) _expressionNode() {}

func (*PropertyShort) _expressionNode() {}
func (*PropertyKeyed) _expressionNode() {}
Expand Down Expand Up @@ -829,19 +830,18 @@ func (self *NewExpression) Idx1() file.Idx {
return self.Callee.Idx1()
}
}
func (self *NullLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + 4) } // "null"
func (self *NumberLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *ObjectLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
func (self *ObjectPattern) Idx1() file.Idx { return self.RightBrace + 1 }
func (self *ParameterList) Idx1() file.Idx { return self.Closing + 1 }
func (self *RegExpLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *SequenceExpression) Idx1() file.Idx { return self.Sequence[len(self.Sequence)-1].Idx1() }
func (self *StringLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *TemplateElement) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *TemplateLiteral) Idx1() file.Idx { return self.CloseQuote + 1 }
func (self *ThisExpression) Idx1() file.Idx { return self.Idx + 4 }
func (self *SuperExpression) Idx1() file.Idx { return self.Idx + 5 }
func (self *DynamicImportExpression) Idx1() file.Idx { return self.Idx + 6 }
func (self *NullLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + 4) } // "null"
func (self *NumberLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *ObjectLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
func (self *ObjectPattern) Idx1() file.Idx { return self.RightBrace + 1 }
func (self *ParameterList) Idx1() file.Idx { return self.Closing + 1 }
func (self *RegExpLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *SequenceExpression) Idx1() file.Idx { return self.Sequence[len(self.Sequence)-1].Idx1() }
func (self *StringLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *TemplateElement) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
func (self *TemplateLiteral) Idx1() file.Idx { return self.CloseQuote + 1 }
func (self *ThisExpression) Idx1() file.Idx { return self.Idx + 4 }
func (self *SuperExpression) Idx1() file.Idx { return self.Idx + 5 }
func (self *UnaryExpression) Idx1() file.Idx {
if self.Postfix {
return self.Operand.Idx1() + 2 // ++ --
Expand All @@ -853,6 +853,8 @@ func (self *MetaProperty) Idx1() file.Idx {
return self.Property.Idx1()
}

func (self *DynamicImportExpression) Idx1() file.Idx { return self.Idx + 6 }

func (self *BadStatement) Idx1() file.Idx { return self.To }
func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
func (self *BranchStatement) Idx1() file.Idx {
Expand Down
9 changes: 3 additions & 6 deletions builtin_promise.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package goja

import (
"reflect"

"github.com/dop251/goja/unistring"
"reflect"
)

type (
PromiseState int
PromiseRejectionOperation int
)
type PromiseState int
type PromiseRejectionOperation int

type promiseReactionType int

Expand Down
3 changes: 0 additions & 3 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@ func (ar *asyncRunner) onRejected(call FunctionCall) Value {
}

func (ar *asyncRunner) step(res Value, done bool, ex *Exception) {
// fmt.Printf("(%v) -> step(%v, %v, %v)\n", ar.gen.ctx.prg.src.Name(), res, done, ex)
r := ar.f.runtime
if done || ex != nil {
if ex == nil {
Expand All @@ -722,7 +721,6 @@ func (ar *asyncRunner) step(res Value, done bool, ex *Exception) {
handler: &jobCallback{callback: ar.onRejected},
asyncRunner: ar,
})
// fmt.Printf("promise = %#v\n", promise.self)
}

func (ar *asyncRunner) start(nArgs int) {
Expand Down Expand Up @@ -783,7 +781,6 @@ func (g *generator) step() (res Value, resultType resultType, ex *Exception) {
g.vm.sp = g.vm.sb - 1
g.vm.callStack = g.vm.callStack[:len(g.vm.callStack)-1] // remove the frame with pc == -2, as ret would do
}
// fmt.Println(res)
return
}

Expand Down
3 changes: 3 additions & 0 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (self *_parser) peek() token.Token {
}

func (self *_parser) scan() (tkn token.Token, literal string, parsedLiteral unistring.String, idx file.Idx) {

self.implicitSemicolon = false

for {
Expand Down Expand Up @@ -638,6 +639,7 @@ func (self *_parser) scanMantissa(base int) {
}

func (self *_parser) scanEscape(quote rune) (int, bool) {

var length, base uint32
chr := self.chr
switch chr {
Expand Down Expand Up @@ -1114,6 +1116,7 @@ func parseStringLiteral(literal string, length int, unicode, strict bool) (unist
}

func (self *_parser) scanNumericLiteral(decimalPoint bool) (token.Token, string) {

offset := self.chrOffset
tkn := token.NUMBER

Expand Down
15 changes: 2 additions & 13 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ func (r *Runtime) newNativeFunc(call func(FunctionCall) Value, name unistring.St
}

func (r *Runtime) newWrappedFunc(value reflect.Value) *Object {

v := &Object{runtime: r}

f := &wrappedFuncObject{
Expand Down Expand Up @@ -1374,6 +1375,7 @@ func (r *Runtime) RunString(str string) (Value, error) {
// RunScript executes the given string in the global context.
func (r *Runtime) RunScript(name, src string) (Value, error) {
p, err := r.compile(name, src, false, true, nil)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1941,8 +1943,6 @@ func (r *Runtime) toValue(i interface{}, origValue reflect.Value) Value {

func (r *Runtime) wrapReflectFunc(value reflect.Value) func(FunctionCall) Value {
return func(call FunctionCall) Value {
// fmt.Println("call=", call)
// fmt.Println("call.Arguments=", call.Arguments)
typ := value.Type()
nargs := typ.NumIn()
var in []reflect.Value
Expand Down Expand Up @@ -2459,17 +2459,6 @@ func (r *Runtime) runWrapped(f func()) (err error) {
if len(r.vm.callStack) == 0 {
r.leave()
} else {
/*
fmt.Printf("code: ")
if r.vm.prg != nil {
for _, code := range r.vm.prg.code {
fmt.Printf("{%T: %#v},", code, code)
}
} else {
fmt.Print("no code")
}
fmt.Print("\n")
*/
r.vm.clearStack()
}
return
Expand Down
17 changes: 7 additions & 10 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,6 @@ func (vm *vm) run() {
if pc < 0 || pc >= len(vm.prg.code) {
break
}
/*
fmt.Printf("code: ")
for _, code := range vm.prg.code[vm.pc:] {
fmt.Printf("{%T: %#v},", code, code)
}
fmt.Println()
fmt.Printf("running: %T: %#v\n", vm.prg.code[pc], vm.prg.code[pc])
//*/
vm.prg.code[pc].exec(vm)
}

Expand Down Expand Up @@ -3699,7 +3691,6 @@ func (e *enterFuncBody) exec(vm *vm) {
}
}
sp := vm.sp
// // fmt.Println("sp", sp)
if e.adjustStack {
sp -= vm.args
}
Expand Down Expand Up @@ -5676,6 +5667,13 @@ func (vm *vm) exceptionFromValue(x interface{}) *Exception {
val: vm.r.newError(vm.r.getSyntaxError(), string(x1)),
}
default:
/*
if vm.prg != nil {
vm.prg.dumpCode(log.Printf)
}
log.Print("Stack: ", string(debug.Stack()))
panic(fmt.Errorf("Panic at %d: %v", vm.pc, x))
*/
return nil
}
if ex.stack == nil {
Expand Down Expand Up @@ -5782,7 +5780,6 @@ func (r *getPrivateRefId) exec(vm *vm) {
}

func (y *yieldMarker) exec(vm *vm) {
// // fmt.Println("values", vm.stash.values)
vm.pc = -vm.pc // this will terminate the run loop
vm.push(y) // marker so the caller knows it's a yield, not a return
}
Expand Down

0 comments on commit 178b2c3

Please sign in to comment.