From fd7ce3a10142e1d8f31fcec30dd8122b56757b26 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 16 Nov 2023 12:17:53 +0200 Subject: [PATCH] Reduce diff size ast/node.go: reduce diff func.go: revert to master parser/lexer.go: revert to master vm.go: revert some parts --- ast/node.go | 90 +++++++++++++++++++++++++------------------------ func.go | 3 -- parser/lexer.go | 3 ++ vm.go | 17 ++++------ 4 files changed, 56 insertions(+), 57 deletions(-) diff --git a/ast/node.go b/ast/node.go index f6db4daf..29d4a10e 100644 --- a/ast/node.go +++ b/ast/node.go @@ -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() {} @@ -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 // ++ -- @@ -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 { diff --git a/func.go b/func.go index 32e207e3..c0469569 100644 --- a/func.go +++ b/func.go @@ -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 { @@ -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) { @@ -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 } diff --git a/parser/lexer.go b/parser/lexer.go index a866cf4c..68d56d20 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -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 { @@ -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 { @@ -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 diff --git a/vm.go b/vm.go index a5372821..00ef5a09 100644 --- a/vm.go +++ b/vm.go @@ -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) } @@ -3699,7 +3691,6 @@ func (e *enterFuncBody) exec(vm *vm) { } } sp := vm.sp - // // fmt.Println("sp", sp) if e.adjustStack { sp -= vm.args } @@ -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 { @@ -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 }