• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Go で書き直した Ikemen


Commit MetaInfo

Révision4218929c8ba477ebfe9da2ca8b595f33cd84e3ca (tree)
l'heure2016-12-23 11:28:24
AuteurSUEHIRO <supersuehiro@user...>
CommiterSUEHIRO

Message de Log

リダイレクトがちゃんとできていなかった

Change Summary

Modification

--- a/src/bytecode.go
+++ b/src/bytecode.go
@@ -67,6 +67,7 @@ const (
6767 OC_dup
6868 OC_swap
6969 OC_run
70+ OC_ocrun
7071 OC_jsf8
7172 OC_jmp8
7273 OC_jz8
@@ -188,7 +189,6 @@ const (
188189 OC_hitfall
189190 OC_hitvel_x
190191 OC_hitvel_y
191- OC_roundsexisted
192192 OC_parent
193193 OC_root
194194 OC_helper
@@ -362,6 +362,7 @@ const (
362362 OC_ex_matchover
363363 OC_ex_matchno
364364 OC_ex_roundno
365+ OC_ex_roundsexisted
365366 OC_ex_ishometeam
366367 OC_ex_tickspersecond
367368 OC_ex_timemod
@@ -375,7 +376,7 @@ type StringPool struct {
375376 func NewStringPool() *StringPool {
376377 return &StringPool{Map: make(map[string]int)}
377378 }
378-func (sp *StringPool) Clear(s string) {
379+func (sp *StringPool) Clear() {
379380 sp.List, sp.Map = nil, make(map[string]int)
380381 }
381382 func (sp *StringPool) Add(s string) int {
@@ -634,7 +635,7 @@ func (_ BytecodeExp) blor(v1 *BytecodeValue, v2 BytecodeValue) {
634635 v1.SetB(v1.ToB() || v2.ToB())
635636 }
636637 func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
637- orgc := c
638+ oc := c
638639 for i := 1; i <= len(be); i++ {
639640 switch be[i-1] {
640641 case OC_jsf8:
@@ -730,6 +731,15 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
730731 }
731732 sys.bcStack.Push(BytecodeSF())
732733 i += int(*(*int32)(unsafe.Pointer(&be[i]))) + 4
734+ case OC_run:
735+ l := int(*(*int32)(unsafe.Pointer(&be[i])))
736+ sys.bcStack.Push(be[i+4:i+4+l].run(c, scpn))
737+ i += 4 + l
738+ case OC_ocrun:
739+ l := int(*(*int32)(unsafe.Pointer(&be[i])))
740+ sys.bcStack.Push(be[i+4:i+4+l].run(oc, scpn))
741+ i += 4 + l
742+ continue
733743 case OC_int8:
734744 sys.bcStack.Push(BytecodeInt(int32(int8(be[i]))))
735745 i++
@@ -813,10 +823,6 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
813823 sys.bcStack.Dup()
814824 case OC_swap:
815825 sys.bcStack.Swap()
816- case OC_run:
817- l := int(*(*int32)(unsafe.Pointer(&be[i])))
818- sys.bcStack.Push(be[i+4:i+4+l].run(c, scpn))
819- i += 4 + l
820826 case OC_time:
821827 sys.bcStack.Push(BytecodeInt(c.time()))
822828 case OC_alive:
@@ -839,7 +845,7 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
839845 println(be[i-1])
840846 unimplemented()
841847 }
842- c = orgc
848+ c = oc
843849 }
844850 return sys.bcStack.Pop()
845851 }
--- a/src/compiler.go
+++ b/src/compiler.go
@@ -490,8 +490,32 @@ func (c *Compiler) kyuushikiSuperDX(out *BytecodeExp, in *string,
490490 c.usiroOp = true
491491 return nil
492492 }
493-func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
494- error) {
493+func (c *Compiler) oneArg(fun string, out *BytecodeExp, in *string,
494+ rd, appendVal bool) (BytecodeValue, error) {
495+ if c.tokenizer(in) != "(" {
496+ return BytecodeSF(), Error(fun + "の次に'('がありません")
497+ }
498+ c.token = c.tokenizer(in)
499+ var be BytecodeExp
500+ bv, err := c.expBoolOr(&be, in)
501+ if err != nil {
502+ return BytecodeSF(), err
503+ }
504+ if err := c.kakkotojiru(in); err != nil {
505+ return BytecodeSF(), err
506+ }
507+ if appendVal {
508+ be.appendValue(bv)
509+ bv = BytecodeSF()
510+ }
511+ if rd && len(be) > 0 {
512+ out.appendJmp(OC_ocrun, int32(len(be)))
513+ }
514+ out.append(be...)
515+ return bv, nil
516+}
517+func (c *Compiler) expValue(out *BytecodeExp, in *string,
518+ rd bool) (BytecodeValue, error) {
495519 c.usiroOp, c.norange = true, false
496520 bv := c.number(c.token)
497521 if !bv.IsSF() {
@@ -535,42 +559,52 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
535559 c.token = c.tokenizer(in)
536560 if c.token == "(" {
537561 c.token = c.tokenizer(in)
538- if bv1, err = c.expBoolOr(out, in); err != nil {
562+ if bv1, err = c.expBoolOr(&be1, in); err != nil {
539563 return BytecodeSF(), err
540564 }
541565 if err := c.kakkotojiru(in); err != nil {
542566 return BytecodeSF(), err
543567 }
544568 c.token = c.tokenizer(in)
545- out.appendValue(bv1)
569+ be1.appendValue(bv1)
546570 } else {
547571 switch opc {
548572 case OC_helper, OC_target:
549- out.appendValue(BytecodeInt(-1))
573+ be1.appendValue(BytecodeInt(-1))
550574 case OC_partner, OC_enemy, OC_enemynear:
551- out.appendValue(BytecodeInt(0))
575+ be1.appendValue(BytecodeInt(0))
552576 case OC_playerid:
553577 return BytecodeSF(), Error("playeridの次に'('がありません")
554578 }
555579 }
556580 }
581+ if rd {
582+ out.appendJmp(OC_ocrun, int32(len(be1)))
583+ }
584+ out.append(be1...)
557585 if c.token != "," {
558586 return BytecodeSF(), Error(",がありません")
559587 }
560588 c.token = c.tokenizer(in)
561- bv1, err = c.expValue(&be1, in)
589+ bv2, err = c.expValue(&be2, in, true)
562590 if err != nil {
563591 return BytecodeSF(), err
564592 }
565- be1.appendValue(bv1)
566- out.appendJmp(opc, int32(len(be1)))
567- out.append(be1...)
593+ be2.appendValue(bv2)
594+ out.appendJmp(opc, int32(len(be2)))
595+ out.append(be2...)
568596 return BytecodeSF(), nil
569597 case "(":
570598 c.token = c.tokenizer(in)
571599 if bv, err = c.expBoolOr(&be1, in); err != nil {
572600 return BytecodeSF(), err
573601 }
602+ if bv.IsSF() {
603+ if rd {
604+ out.appendJmp(OC_jmp, int32(0)) // NOPでリダイレクトをもどす
605+ }
606+ out.append(be1...)
607+ }
574608 if err := c.kakkotojiru(in); err != nil {
575609 return BytecodeSF(), err
576610 }
@@ -583,8 +617,12 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
583617 }
584618 } else {
585619 c.token = c.tokenizer(in)
586- bv, err = c.expValue(out, in)
620+ bv, err = c.expValue(&be1, in, false)
587621 if bv.IsSF() {
622+ if rd {
623+ out.appendJmp(OC_jmp, int32(0)) // NOPでリダイレクトをもどす
624+ }
625+ out.append(be1...)
588626 out.append(OC_neg)
589627 } else {
590628 out.neg(&bv)
@@ -592,25 +630,30 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
592630 }
593631 case "~":
594632 c.token = c.tokenizer(in)
595- bv, err = c.expValue(out, in)
633+ bv, err = c.expValue(&be1, in, false)
596634 if bv.IsSF() {
635+ if rd {
636+ out.appendJmp(OC_jmp, int32(0)) // NOPでリダイレクトをもどす
637+ }
638+ out.append(be1...)
597639 out.append(OC_not)
598640 } else {
599641 out.not(&bv)
600642 }
601643 case "!":
602644 c.token = c.tokenizer(in)
603- bv, err = c.expValue(out, in)
645+ bv, err = c.expValue(&be1, in, false)
604646 if bv.IsSF() {
647+ if rd {
648+ out.appendJmp(OC_jmp, int32(0)) // NOPでリダイレクトをもどす
649+ }
650+ out.append(be1...)
605651 out.append(OC_blnot)
606652 } else {
607653 out.blnot(&bv)
608654 }
609- case "time":
610- out.append(OC_time)
611- case "alive":
612- out.append(OC_alive)
613- case "ifelse":
655+ case "ifelse", "cond":
656+ cond := c.token == "cond"
614657 if c.tokenizer(in) != "(" {
615658 return BytecodeSF(), Error(c.token + "の次に'('がありません")
616659 }
@@ -636,13 +679,40 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
636679 return BytecodeSF(), err
637680 }
638681 if bv1.IsSF() || bv2.IsSF() || bv3.IsSF() {
639- out.append(be1...)
640- out.appendValue(bv1)
641- out.append(be2...)
642- out.appendValue(bv2)
643- out.append(be3...)
644- out.appendValue(bv3)
645- out.append(OC_ifelse)
682+ if cond {
683+ be3.appendValue(bv3)
684+ be2.appendValue(bv2)
685+ if len(be3) > int(math.MaxUint8-1) {
686+ be2.appendJmp(OC_jmp, int32(len(be3)+1))
687+ } else {
688+ be2.append(OC_jmp8, OpCode(len(be3)+1))
689+ }
690+ be1.appendValue(bv1)
691+ if len(be2) > int(math.MaxUint8-1) {
692+ be1.appendJmp(OC_jz, int32(len(be2)+1))
693+ } else {
694+ be1.append(OC_jz8, OpCode(len(be2)+1))
695+ }
696+ be1.append(OC_pop)
697+ be1.append(be2...)
698+ be1.append(OC_pop)
699+ be1.append(be3...)
700+ if rd {
701+ out.appendJmp(OC_run, int32(len(be1))) // NOPでリダイレクトをもどす
702+ }
703+ out.append(be1...)
704+ } else {
705+ if rd {
706+ out.appendJmp(OC_jmp, int32(0)) // NOPでリダイレクトをもどす
707+ }
708+ out.append(be1...)
709+ out.appendValue(bv1)
710+ out.append(be2...)
711+ out.appendValue(bv2)
712+ out.append(be3...)
713+ out.appendValue(bv3)
714+ out.append(OC_ifelse)
715+ }
646716 } else {
647717 if bv1.ToB() {
648718 bv = bv2
@@ -650,6 +720,10 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
650720 bv = bv3
651721 }
652722 }
723+ case "time":
724+ out.append(OC_time)
725+ case "alive":
726+ out.append(OC_alive)
653727 case "random":
654728 out.append(OC_random)
655729 case "roundstate":
@@ -673,7 +747,11 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
673747 if n <= 0 {
674748 return BytecodeSF(), Error("animelemのは0より大きくなければいけません")
675749 }
676- out.appendValue(BytecodeInt(n))
750+ be1.appendValue(BytecodeInt(n))
751+ if rd {
752+ out.appendJmp(OC_ocrun, int32(len(be1)))
753+ }
754+ out.append(be1...)
677755 out.append(OC_animelemtime)
678756 if err = c.kyuushikiSuperDX(&be, in, false); err != nil {
679757 return BytecodeSF(), err
@@ -681,17 +759,9 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
681759 out.append(OC_jsf8, OpCode(len(be)))
682760 out.append(be...)
683761 case "animelemtime":
684- if c.tokenizer(in) != "(" {
685- return BytecodeSF(), Error(c.token + "の次に'('がありません")
686- }
687- c.token = c.tokenizer(in)
688- if bv1, err = c.expBoolOr(out, in); err != nil {
689- return BytecodeSF(), err
690- }
691- if err := c.kakkotojiru(in); err != nil {
762+ if _, err := c.oneArg(c.token, out, in, rd, true); err != nil {
692763 return BytecodeSF(), err
693764 }
694- out.appendValue(bv1)
695765 out.append(OC_animelemtime)
696766 case "stateno":
697767 out.append(OC_stateno)
@@ -719,7 +789,7 @@ func (c *Compiler) renzokuEnzansihaError(in *string) error {
719789 }
720790 func (c *Compiler) expPostNot(out *BytecodeExp, in *string) (BytecodeValue,
721791 error) {
722- bv, err := c.expValue(out, in)
792+ bv, err := c.expValue(out, in, false)
723793 if err != nil {
724794 return BytecodeSF(), err
725795 }
@@ -740,7 +810,7 @@ func (c *Compiler) expPostNot(out *BytecodeExp, in *string) (BytecodeValue,
740810 }
741811 oldtoken, oldin := c.token, *in
742812 var dummyout BytecodeExp
743- if _, err := c.expValue(&dummyout, in); err != nil {
813+ if _, err := c.expValue(&dummyout, in, false); err != nil {
744814 return BytecodeSF(), err
745815 }
746816 if c.isOperator(c.token) <= 0 {
@@ -2324,11 +2394,10 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
23242394 if j < len(tr)-1 {
23252395 if len(te) > int(math.MaxUint8-1) {
23262396 tmp.appendJmp(OC_jz, int32(len(te)+1))
2327- tmp.append(OC_pop)
23282397 } else {
23292398 tmp.append(OC_jz8, OpCode(len(te)+1))
2330- tmp.append(OC_pop)
23312399 }
2400+ tmp.append(OC_pop)
23322401 }
23332402 te = append(tmp, te...)
23342403 }
@@ -2495,6 +2564,7 @@ func (c *Compiler) Compile(n int, def string) (*Bytecode, error) {
24952564 }
24962565 c.cmdl.Add(*cm)
24972566 }
2567+ sys.stringPool[n].Clear()
24982568 for _, s := range st {
24992569 if len(s) > 0 {
25002570 if err := c.stateCompile(bc, s, def); err != nil {