Go で書き直した Ikemen
Revisão | 63386291b936472dacca9db89034d356fe7f7bc0 (tree) |
---|---|
Hora | 2016-12-14 00:34:23 |
Autor | SUEHIRO <supersuehiro@user...> |
Commiter | SUEHIRO |
mugenの仕様で勘違いしていた部分の修正や、バイトコード実行部分など
@@ -382,13 +382,40 @@ func (sp *StringPool) Add(s string) int { | ||
382 | 382 | return i |
383 | 383 | } |
384 | 384 | |
385 | +type BytecodeValue struct { | |
386 | + t ValueType | |
387 | + v float64 | |
388 | +} | |
389 | + | |
390 | +func (bv BytecodeValue) IsNaN() bool { return math.IsNaN(bv.v) } | |
391 | + | |
392 | +func BytecodeNaN() BytecodeValue { return BytecodeValue{v: math.NaN()} } | |
393 | + | |
394 | +type BytecodeStack []BytecodeValue | |
395 | + | |
396 | +func (bs *BytecodeStack) Clear() { *bs = (*bs)[:0] } | |
397 | +func (bs *BytecodeStack) Push(bv BytecodeValue) { *bs = append(*bs, bv) } | |
398 | +func (bs BytecodeStack) Top() *BytecodeValue { | |
399 | + return &bs[len(bs)-1] | |
400 | +} | |
401 | +func (bs *BytecodeStack) Pop() (bv BytecodeValue) { | |
402 | + bv, *bs = *bs.Top(), (*bs)[:len(*bs)-1] | |
403 | + return | |
404 | +} | |
405 | +func (bs *BytecodeStack) Dup() { | |
406 | + bs.Push(*bs.Top()) | |
407 | +} | |
408 | + | |
385 | 409 | type BytecodeExp []OpCode |
386 | 410 | |
411 | +func (be *BytecodeExp) append(op ...OpCode) { | |
412 | + *be = append(*be, op...) | |
413 | +} | |
387 | 414 | func (be *BytecodeExp) appendFloat(f float32) { |
388 | - *be = append(*be, (*(*[4]OpCode)(unsafe.Pointer(&f)))[:]...) | |
415 | + be.append((*(*[4]OpCode)(unsafe.Pointer(&f)))[:]...) | |
389 | 416 | } |
390 | 417 | func (be *BytecodeExp) appendInt(i int32) { |
391 | - *be = append(*be, (*(*[4]OpCode)(unsafe.Pointer(&i)))[:]...) | |
418 | + be.append((*(*[4]OpCode)(unsafe.Pointer(&i)))[:]...) | |
392 | 419 | } |
393 | 420 | func (be BytecodeExp) toF() float32 { |
394 | 421 | return *(*float32)(unsafe.Pointer(&be[0])) |
@@ -396,40 +423,60 @@ func (be BytecodeExp) toF() float32 { | ||
396 | 423 | func (be BytecodeExp) toI() int32 { |
397 | 424 | return *(*int32)(unsafe.Pointer(&be[0])) |
398 | 425 | } |
399 | -func (be *BytecodeExp) AppendValue(t ValueType, v float64) (ok bool) { | |
400 | - if math.IsNaN(v) { | |
426 | +func (be *BytecodeExp) AppendValue(bv BytecodeValue) (ok bool) { | |
427 | + if bv.IsNaN() { | |
401 | 428 | return false |
402 | 429 | } |
403 | - switch t { | |
430 | + switch bv.t { | |
404 | 431 | case VT_Float: |
405 | - *be = append(*be, OC_float) | |
406 | - be.appendFloat(float32(v)) | |
432 | + be.append(OC_float) | |
433 | + be.appendFloat(float32(bv.v)) | |
407 | 434 | case VT_Int: |
408 | - if v >= -128 || v <= 127 { | |
409 | - *be = append(*be, OC_int8, OpCode(v)) | |
435 | + if bv.v >= -128 || bv.v <= 127 { | |
436 | + be.append(OC_int8, OpCode(bv.v)) | |
410 | 437 | } else { |
411 | - *be = append(*be, OC_int) | |
412 | - be.appendInt(int32(v)) | |
438 | + be.append(OC_int) | |
439 | + be.appendInt(int32(bv.v)) | |
413 | 440 | } |
414 | 441 | case VT_Bool: |
415 | - if v != 0 { | |
416 | - *be = append(*be, OC_int8, 1) | |
442 | + if bv.v != 0 { | |
443 | + be.append(OC_int8, 1) | |
417 | 444 | } else { |
418 | - *be = append(*be, OC_int8, 0) | |
445 | + be.append(OC_int8, 0) | |
419 | 446 | } |
420 | 447 | default: |
421 | 448 | return false |
422 | 449 | } |
423 | 450 | return true |
424 | 451 | } |
425 | -func (be BytecodeExp) run(c *Char) (t ValueType, v float64) { | |
426 | - unimplemented() | |
427 | - return VT_Int, 0 | |
428 | -} | |
429 | -func (be BytecodeExp) eval(c *Char) float64 { | |
430 | - _, v := be.run(c) | |
431 | - return v | |
452 | +func (be BytecodeExp) run(c *Char) BytecodeValue { | |
453 | + sys.bcStack.Clear() | |
454 | + for i := 1; i <= len(be); i++ { | |
455 | + switch be[i-1] { | |
456 | + case OC_int8: | |
457 | + sys.bcStack.Push(BytecodeValue{VT_Int, float64(int8(be[i]))}) | |
458 | + i++ | |
459 | + case OC_int: | |
460 | + sys.bcStack.Push(BytecodeValue{VT_Int, float64(be[i:].toI())}) | |
461 | + i += 4 | |
462 | + case OC_float: | |
463 | + sys.bcStack.Push(BytecodeValue{VT_Float, float64(be[i:].toF())}) | |
464 | + i += 4 | |
465 | + case OC_blnot: | |
466 | + top := sys.bcStack.Top() | |
467 | + top.t = VT_Int | |
468 | + if top.v != 0 { | |
469 | + top.v = 0 | |
470 | + } else { | |
471 | + top.v = 1 | |
472 | + } | |
473 | + default: | |
474 | + unimplemented() | |
475 | + } | |
476 | + } | |
477 | + return sys.bcStack.Pop() | |
432 | 478 | } |
479 | +func (be BytecodeExp) eval(c *Char) float64 { return be.run(c).v } | |
433 | 480 | |
434 | 481 | type StateController interface { |
435 | 482 | Run(c *Char) (changeState bool) |
@@ -489,6 +536,89 @@ func (scb StateControllerBase) run(f func(byte, []BytecodeExp) bool) bool { | ||
489 | 536 | return true |
490 | 537 | } |
491 | 538 | |
539 | +type stateDef StateControllerBase | |
540 | + | |
541 | +const ( | |
542 | + stateDef_hitcountpersist byte = iota + 1 | |
543 | + stateDef_movehitpersist | |
544 | + stateDef_hitdefpersist | |
545 | + stateDef_sprpriority | |
546 | + stateDef_facep2 | |
547 | + stateDef_juggle | |
548 | + stateDef_velset | |
549 | + stateDef_anim | |
550 | + stateDef_ctrl | |
551 | + stateDef_poweradd | |
552 | + stateDef_hitcountpersist_c = stateDef_hitcountpersist + SCID_const | |
553 | + stateDef_movehitpersist_c = stateDef_movehitpersist + SCID_const | |
554 | + stateDef_hitdefpersist_c = stateDef_hitdefpersist + SCID_const | |
555 | + stateDef_sprpriority_c = stateDef_sprpriority + SCID_const | |
556 | + stateDef_facep2_c = stateDef_facep2 + SCID_const | |
557 | + stateDef_juggle_c = stateDef_juggle + SCID_const | |
558 | + stateDef_velset_c = stateDef_velset + SCID_const | |
559 | + stateDef_anim_c = stateDef_anim + SCID_const | |
560 | + stateDef_ctrl_c = stateDef_ctrl + SCID_const | |
561 | + stateDef_poweradd_c = stateDef_poweradd + SCID_const | |
562 | +) | |
563 | + | |
564 | +func (sd stateDef) Run(c *Char) bool { | |
565 | + StateControllerBase(sd).run(func(id byte, exp []BytecodeExp) bool { | |
566 | + switch id { | |
567 | + case stateDef_hitcountpersist, stateDef_hitcountpersist_c: | |
568 | + if id == stateDef_hitcountpersist_c || exp[0].eval(c) == 0 { | |
569 | + c.clearHitCount() | |
570 | + } | |
571 | + case stateDef_movehitpersist, stateDef_movehitpersist_c: | |
572 | + if id == stateDef_movehitpersist_c || exp[0].eval(c) == 0 { | |
573 | + c.clearMoveHit() | |
574 | + } | |
575 | + case stateDef_hitdefpersist, stateDef_hitdefpersist_c: | |
576 | + if id == stateDef_hitdefpersist_c || exp[0].eval(c) == 0 { | |
577 | + c.clearHitDef() | |
578 | + } | |
579 | + case stateDef_sprpriority: | |
580 | + c.setSprPriority(int32(exp[0].eval(c))) | |
581 | + case stateDef_sprpriority_c: | |
582 | + c.setSprPriority(exp[0].toI()) | |
583 | + case stateDef_facep2, stateDef_facep2_c: | |
584 | + if id == stateDef_facep2_c || exp[0].eval(c) != 0 { | |
585 | + c.faceP2() | |
586 | + } | |
587 | + case stateDef_juggle: | |
588 | + c.setJuggle(int32(exp[0].eval(c))) | |
589 | + case stateDef_juggle_c: | |
590 | + c.setJuggle(exp[0].toI()) | |
591 | + case stateDef_velset: | |
592 | + c.setXV(float32(exp[0].eval(c))) | |
593 | + if len(exp) > 1 { | |
594 | + c.setYV(float32(exp[1].eval(c))) | |
595 | + if len(exp) > 2 { | |
596 | + exp[2].run(c) | |
597 | + } | |
598 | + } | |
599 | + case stateDef_velset_c: | |
600 | + c.setXV(exp[0].toF()) | |
601 | + if len(exp) > 1 { | |
602 | + c.setYV(exp[1].toF()) | |
603 | + } | |
604 | + case stateDef_anim: | |
605 | + c.changeAnim(int32(exp[0].eval(c))) | |
606 | + case stateDef_anim_c: | |
607 | + c.changeAnim(exp[0].toI()) | |
608 | + case stateDef_ctrl: | |
609 | + c.setCtrl(exp[0].eval(c) != 0) | |
610 | + case stateDef_ctrl_c: | |
611 | + c.setCtrl(exp[0].toI() != 0) | |
612 | + case stateDef_poweradd: | |
613 | + c.addPower(int32(exp[0].eval(c))) | |
614 | + case stateDef_poweradd_c: | |
615 | + c.addPower(exp[0].toI()) | |
616 | + } | |
617 | + return true | |
618 | + }) | |
619 | + return false | |
620 | +} | |
621 | + | |
492 | 622 | type StateBytecode struct { |
493 | 623 | stateType StateType |
494 | 624 | moveType MoveType |
@@ -544,12 +544,27 @@ func (c *Char) clearMoveHit() { | ||
544 | 544 | func (c *Char) clearHitDef() { |
545 | 545 | unimplemented() |
546 | 546 | } |
547 | +func (c *Char) setSprPriority(sprpriority int32) { | |
548 | + c.sprpriority = sprpriority | |
549 | +} | |
547 | 550 | func (c *Char) faceP2() { |
548 | 551 | unimplemented() |
549 | 552 | } |
553 | +func (c *Char) setJuggle(juggle int32) { | |
554 | + c.juggle = juggle | |
555 | +} | |
550 | 556 | func (c *Char) setXV(xv float32) { |
551 | 557 | unimplemented() |
552 | 558 | } |
553 | 559 | func (c *Char) setYV(yv float32) { |
554 | 560 | unimplemented() |
555 | 561 | } |
562 | +func (c *Char) changeAnim(animNo int32) { | |
563 | + unimplemented() | |
564 | +} | |
565 | +func (c *Char) setCtrl(ctrl bool) { | |
566 | + unimplemented() | |
567 | +} | |
568 | +func (c *Char) addPower(power int32) { | |
569 | + unimplemented() | |
570 | +} |
@@ -122,8 +122,26 @@ func Atof(str string) float64 { | ||
122 | 122 | } |
123 | 123 | f = f*10 + float64(a[i]-'0') |
124 | 124 | } |
125 | + e := 0.0 | |
126 | + if i+1 < len(a) && (a[i] == 'e' || a[i] == 'E') { | |
127 | + j := i + 1 | |
128 | + if a[j] == '-' || a[j] == '+' { | |
129 | + j++ | |
130 | + } | |
131 | + for ; j < len(a) && '0' <= a[j] && a[j] <= '9'; j++ { | |
132 | + e = e*10 + float64(a[j]-'0') | |
133 | + } | |
134 | + if e != 0 { | |
135 | + if str[i+1] == '-' { | |
136 | + e *= -1 | |
137 | + } | |
138 | + if p == 0 { | |
139 | + p = i | |
140 | + } | |
141 | + } | |
142 | + } | |
125 | 143 | if p > 0 { |
126 | - f *= math.Pow10(p - i) | |
144 | + f *= math.Pow10(p - i + int(e)) | |
127 | 145 | } |
128 | 146 | if str[0] == '-' { |
129 | 147 | f *= -1 |
@@ -3,84 +3,26 @@ package main | ||
3 | 3 | import ( |
4 | 4 | "fmt" |
5 | 5 | "math" |
6 | + "strconv" | |
6 | 7 | "strings" |
7 | 8 | ) |
8 | 9 | |
9 | 10 | const kuuhaktokigou = " !=<>()|&+-*/%,[]^|:\"\t\r\n" |
10 | 11 | |
11 | -type stateDef StateControllerBase | |
12 | - | |
13 | -const ( | |
14 | - stateDef_hitcountpersist byte = iota + 1 | |
15 | - stateDef_movehitpersist | |
16 | - stateDef_hitdefpersist | |
17 | - stateDef_sprpriority | |
18 | - stateDef_facep2 | |
19 | - stateDef_juggle | |
20 | - stateDef_velset | |
21 | - stateDef_hitcountpersist_c = stateDef_hitcountpersist + SCID_const | |
22 | - stateDef_movehitpersist_c = stateDef_movehitpersist + SCID_const | |
23 | - stateDef_hitdefpersist_c = stateDef_hitdefpersist + SCID_const | |
24 | - stateDef_sprpriority_c = stateDef_sprpriority + SCID_const | |
25 | - stateDef_facep2_c = stateDef_facep2 + SCID_const | |
26 | - stateDef_juggle_c = stateDef_juggle + SCID_const | |
27 | - stateDef_velset_c = stateDef_velset + SCID_const | |
28 | -) | |
29 | - | |
30 | -func (sd stateDef) Run(c *Char) bool { | |
31 | - StateControllerBase(sd).run(func(id byte, exp []BytecodeExp) bool { | |
32 | - switch id { | |
33 | - case stateDef_hitcountpersist, stateDef_hitcountpersist_c: | |
34 | - if id == stateDef_hitcountpersist_c || exp[0].eval(c) == 0 { | |
35 | - c.clearHitCount() | |
36 | - } | |
37 | - case stateDef_movehitpersist, stateDef_movehitpersist_c: | |
38 | - if id == stateDef_movehitpersist_c || exp[0].eval(c) == 0 { | |
39 | - c.clearMoveHit() | |
40 | - } | |
41 | - case stateDef_hitdefpersist, stateDef_hitdefpersist_c: | |
42 | - if id == stateDef_hitdefpersist_c || exp[0].eval(c) == 0 { | |
43 | - c.clearHitDef() | |
44 | - } | |
45 | - case stateDef_sprpriority: | |
46 | - c.sprpriority = int32(exp[0].eval(c)) | |
47 | - case stateDef_sprpriority_c: | |
48 | - c.sprpriority = exp[0].toI() | |
49 | - case stateDef_facep2, stateDef_facep2_c: | |
50 | - if id == stateDef_facep2_c || exp[0].eval(c) != 0 { | |
51 | - c.faceP2() | |
52 | - } | |
53 | - case stateDef_juggle: | |
54 | - c.juggle = int32(exp[0].eval(c)) | |
55 | - case stateDef_juggle_c: | |
56 | - c.juggle = exp[0].toI() | |
57 | - case stateDef_velset: | |
58 | - c.setXV(float32(exp[0].eval(c))) | |
59 | - if len(exp) > 1 { | |
60 | - c.setYV(float32(exp[1].eval(c))) | |
61 | - if len(exp) > 2 { | |
62 | - exp[2].eval(c) | |
63 | - } | |
64 | - } | |
65 | - case stateDef_velset_c: | |
66 | - c.setXV(exp[0].toF()) | |
67 | - if len(exp) > 1 { | |
68 | - c.setYV(exp[1].toF()) | |
69 | - } | |
70 | - } | |
71 | - unimplemented() | |
72 | - return true | |
73 | - }) | |
74 | - return false | |
12 | +type ExpFunc func(out *BytecodeExp, in *string) (BytecodeValue, error) | |
13 | +type Compiler struct { | |
14 | + cmdl *CommandList | |
15 | + valCnt int | |
16 | + maeOp string | |
17 | + usiroOp bool | |
18 | + norange bool | |
19 | + token string | |
75 | 20 | } |
76 | 21 | |
77 | -type ExpFunc func(out *BytecodeExp, in *string) (ValueType, float64, error) | |
78 | -type Compiler struct{ cmdl *CommandList } | |
79 | - | |
80 | 22 | func newCompiler() *Compiler { |
81 | 23 | return &Compiler{} |
82 | 24 | } |
83 | -func (c *Compiler) tokenizer(in *string) string { | |
25 | +func (_ *Compiler) tokenizer(in *string) string { | |
84 | 26 | *in = strings.TrimSpace(*in) |
85 | 27 | if len(*in) == 0 { |
86 | 28 | return "" |
@@ -179,38 +121,269 @@ func (c *Compiler) tokenizer(in *string) string { | ||
179 | 121 | *in = (*in)[1:] |
180 | 122 | return "\"" |
181 | 123 | } |
182 | - ia := strings.IndexAny(*in, kuuhaktokigou) | |
183 | - if ia < 0 { | |
184 | - ia = len(*in) | |
124 | + i, ten := 0, false | |
125 | + for ; i < len(*in); i++ { | |
126 | + if (*in)[i] == '.' { | |
127 | + if ten { | |
128 | + break | |
129 | + } | |
130 | + ten = true | |
131 | + } else if (*in)[i] < '0' || (*in)[i] > '9' { | |
132 | + break | |
133 | + } | |
185 | 134 | } |
186 | - token := (*in)[:ia] | |
187 | - *in = (*in)[ia:] | |
135 | + if i > 0 && i < len(*in) && ((*in)[i] == 'e' || (*in)[i] == 'E') { | |
136 | + j := i + 1 | |
137 | + for i++; i < len(*in); i++ { | |
138 | + if ((*in)[i] < '0' || (*in)[i] > '9') && | |
139 | + (i != j || ((*in)[i] != '-' && (*in)[i] != '+')) { | |
140 | + break | |
141 | + } | |
142 | + } | |
143 | + } | |
144 | + if i == 0 { | |
145 | + i = strings.IndexAny(*in, kuuhaktokigou) | |
146 | + if i < 0 { | |
147 | + i = len(*in) | |
148 | + } | |
149 | + } | |
150 | + token := (*in)[:i] | |
151 | + *in = (*in)[i:] | |
188 | 152 | return token |
189 | 153 | } |
190 | -func (c *Compiler) expBoolOr(out *BytecodeExp, in *string) (ValueType, | |
191 | - float64, error) { | |
154 | +func (_ *Compiler) isOperator(token string) int { | |
155 | + switch token { | |
156 | + case "||": | |
157 | + return 1 | |
158 | + case "^^": | |
159 | + return 2 | |
160 | + case "&&": | |
161 | + return 3 | |
162 | + case "|": | |
163 | + return 4 | |
164 | + case "^": | |
165 | + return 5 | |
166 | + case "&": | |
167 | + return 6 | |
168 | + case "=", "!=": | |
169 | + return 7 | |
170 | + case ">", ">=", "<", "<=": | |
171 | + return 8 | |
172 | + case "+", "-": | |
173 | + return 9 | |
174 | + case "*", "/", "%": | |
175 | + return 10 | |
176 | + case "**": | |
177 | + return 11 | |
178 | + } | |
179 | + return 0 | |
180 | +} | |
181 | +func (c *Compiler) operator(in *string) (string, error) { | |
182 | + if len(c.maeOp) > 0 { | |
183 | + if opp := c.isOperator(c.token); opp <= c.isOperator(c.maeOp) { | |
184 | + if opp > 0 || len(c.token) == 0 || | |
185 | + (c.token[0] != '(' && (c.token[0] < 'A' || c.token[0] > 'Z') && | |
186 | + (c.token[0] < 'a' || c.token[0] > 'z')) { | |
187 | + return "", Error(c.maeOp + "が不正です") | |
188 | + } | |
189 | + *in = c.token + " " + *in | |
190 | + c.token = c.maeOp | |
191 | + c.maeOp = "" | |
192 | + c.norange = true | |
193 | + } | |
194 | + } | |
195 | + return c.token, nil | |
196 | +} | |
197 | +func (c *Compiler) number(token string) BytecodeValue { | |
198 | + f, err := strconv.ParseFloat(token, 64) | |
199 | + if err != nil && f == 0 { | |
200 | + return BytecodeNaN() | |
201 | + } | |
202 | + if strings.Index(token, ".") >= 0 { | |
203 | + c.usiroOp = false | |
204 | + return BytecodeValue{VT_Float, f} | |
205 | + } | |
206 | + if strings.IndexAny(token, "Ee") >= 0 { | |
207 | + return BytecodeNaN() | |
208 | + } | |
209 | + c.usiroOp = false | |
210 | + if f > math.MaxInt32 { | |
211 | + return BytecodeValue{VT_Int, float64(math.MaxInt32)} | |
212 | + } | |
213 | + if f < math.MinInt32 { | |
214 | + return BytecodeValue{VT_Int, float64(math.MinInt32)} | |
215 | + } | |
216 | + return BytecodeValue{VT_Int, f} | |
217 | +} | |
218 | +func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue, | |
219 | + error) { | |
220 | + c.usiroOp, c.norange = true, false | |
221 | + bv := c.number(c.token) | |
222 | + if !bv.IsNaN() { | |
223 | + c.valCnt++ | |
224 | + c.token = c.tokenizer(in) | |
225 | + return bv, nil | |
226 | + } | |
227 | + unimplemented() | |
228 | + c.valCnt++ | |
229 | + c.token = c.tokenizer(in) | |
230 | + return bv, nil | |
231 | +} | |
232 | +func (c *Compiler) expPostNot(out *BytecodeExp, in *string) (BytecodeValue, | |
233 | + error) { | |
234 | + bv, err := c.expValue(out, in) | |
235 | + if err != nil { | |
236 | + return BytecodeNaN(), err | |
237 | + } | |
238 | + for c.token == "!" { | |
239 | + c.usiroOp = true | |
240 | + if bv.IsNaN() { | |
241 | + out.append(OC_blnot) | |
242 | + } else { | |
243 | + bv.t = VT_Bool | |
244 | + if bv.v != 0 { | |
245 | + bv.v = 0 | |
246 | + } else { | |
247 | + bv.v = 1 | |
248 | + } | |
249 | + } | |
250 | + c.token = c.tokenizer(in) | |
251 | + } | |
252 | + if len(c.maeOp) == 0 && c.usiroOp && c.token == "(" { | |
253 | + oldin := *in | |
254 | + var dummyout BytecodeExp | |
255 | + if _, err := c.expValue(&dummyout, in); err != nil { | |
256 | + return BytecodeNaN(), err | |
257 | + } | |
258 | + if c.isOperator(c.token) <= 0 { | |
259 | + return BytecodeNaN(), Error("演算子がありません") | |
260 | + } | |
261 | + oldin = oldin[:len(oldin)-len(*in)] | |
262 | + *in = "(" + oldin[:strings.LastIndex(oldin, c.token)] + *in | |
263 | + } | |
264 | + return bv, nil | |
265 | +} | |
266 | +func (c *Compiler) expPow(out *BytecodeExp, in *string) (BytecodeValue, | |
267 | + error) { | |
268 | + bv, err := c.expPostNot(out, in) | |
269 | + if err != nil { | |
270 | + return BytecodeNaN(), err | |
271 | + } | |
272 | + unimplemented() | |
273 | + return bv, nil | |
274 | +} | |
275 | +func (c *Compiler) expMldv(out *BytecodeExp, in *string) (BytecodeValue, | |
276 | + error) { | |
277 | + bv, err := c.expPow(out, in) | |
278 | + if err != nil { | |
279 | + return BytecodeNaN(), err | |
280 | + } | |
281 | + unimplemented() | |
282 | + return bv, nil | |
283 | +} | |
284 | +func (c *Compiler) expAdsb(out *BytecodeExp, in *string) (BytecodeValue, | |
285 | + error) { | |
286 | + bv, err := c.expMldv(out, in) | |
287 | + if err != nil { | |
288 | + return BytecodeNaN(), err | |
289 | + } | |
290 | + unimplemented() | |
291 | + return bv, nil | |
292 | +} | |
293 | +func (c *Compiler) expGrls(out *BytecodeExp, in *string) (BytecodeValue, | |
294 | + error) { | |
295 | + bv, err := c.expAdsb(out, in) | |
296 | + if err != nil { | |
297 | + return BytecodeNaN(), err | |
298 | + } | |
299 | + unimplemented() | |
300 | + return bv, nil | |
301 | +} | |
302 | +func (c *Compiler) expEqu(out *BytecodeExp, in *string) (BytecodeValue, | |
303 | + error) { | |
304 | + bv, err := c.expGrls(out, in) | |
305 | + if err != nil { | |
306 | + return BytecodeNaN(), err | |
307 | + } | |
308 | + unimplemented() | |
309 | + return bv, nil | |
310 | +} | |
311 | +func (c *Compiler) expAnd(out *BytecodeExp, in *string) (BytecodeValue, | |
312 | + error) { | |
313 | + bv, err := c.expEqu(out, in) | |
314 | + if err != nil { | |
315 | + return BytecodeNaN(), err | |
316 | + } | |
192 | 317 | unimplemented() |
193 | - return 0, 0, nil | |
318 | + return bv, nil | |
319 | +} | |
320 | +func (c *Compiler) expXor(out *BytecodeExp, in *string) (BytecodeValue, | |
321 | + error) { | |
322 | + bv, err := c.expAnd(out, in) | |
323 | + if err != nil { | |
324 | + return BytecodeNaN(), err | |
325 | + } | |
326 | + unimplemented() | |
327 | + return bv, nil | |
328 | +} | |
329 | +func (c *Compiler) expOr(out *BytecodeExp, in *string) (BytecodeValue, error) { | |
330 | + bv, err := c.expXor(out, in) | |
331 | + if err != nil { | |
332 | + return BytecodeNaN(), err | |
333 | + } | |
334 | + unimplemented() | |
335 | + return bv, nil | |
336 | +} | |
337 | +func (c *Compiler) expBoolAnd(out *BytecodeExp, in *string) (BytecodeValue, | |
338 | + error) { | |
339 | + bv, err := c.expOr(out, in) | |
340 | + if err != nil { | |
341 | + return BytecodeNaN(), err | |
342 | + } | |
343 | + unimplemented() | |
344 | + return bv, nil | |
345 | +} | |
346 | +func (c *Compiler) expBoolXor(out *BytecodeExp, in *string) (BytecodeValue, | |
347 | + error) { | |
348 | + bv, err := c.expBoolAnd(out, in) | |
349 | + if err != nil { | |
350 | + return BytecodeNaN(), err | |
351 | + } | |
352 | + unimplemented() | |
353 | + return bv, nil | |
354 | +} | |
355 | +func (c *Compiler) expBoolOr(out *BytecodeExp, in *string) (BytecodeValue, | |
356 | + error) { | |
357 | + defer func(ovc int, omp string) { | |
358 | + c.valCnt, c.maeOp = ovc, omp | |
359 | + }(c.valCnt, c.maeOp) | |
360 | + bv, err := c.expBoolXor(out, in) | |
361 | + if err != nil { | |
362 | + return BytecodeNaN(), err | |
363 | + } | |
364 | + unimplemented() | |
365 | + return bv, nil | |
194 | 366 | } |
195 | 367 | func (c *Compiler) typedExp(ef ExpFunc, out *BytecodeExp, in *string, |
196 | 368 | vt ValueType) (float64, error) { |
369 | + c.token = c.tokenizer(in) | |
197 | 370 | var be BytecodeExp |
198 | - t, v, err := ef(&be, in) | |
371 | + bv, err := ef(&be, in) | |
199 | 372 | if err != nil { |
200 | 373 | return 0, err |
201 | 374 | } |
202 | 375 | if len(be) == 0 && vt != VT_Variant { |
203 | 376 | if vt == VT_Bool { |
204 | - if v != 0 { | |
205 | - v = 1 | |
377 | + if bv.v != 0 { | |
378 | + bv.v = 1 | |
206 | 379 | } else { |
207 | - v = 0 | |
380 | + bv.v = 0 | |
208 | 381 | } |
209 | 382 | } |
210 | - return v, nil | |
383 | + return bv.v, nil | |
211 | 384 | } |
212 | - *out = append(*out, be...) | |
213 | - out.AppendValue(t, v) | |
385 | + out.append(be...) | |
386 | + out.AppendValue(bv) | |
214 | 387 | return math.NaN(), nil |
215 | 388 | } |
216 | 389 | func (c *Compiler) argExpression(in *string, |
@@ -220,13 +393,8 @@ func (c *Compiler) argExpression(in *string, | ||
220 | 393 | if err != nil { |
221 | 394 | return nil, 0, err |
222 | 395 | } |
223 | - oldin := *in | |
224 | - if token := c.tokenizer(in); len(token) > 0 { | |
225 | - if token == "," { | |
226 | - *in = oldin | |
227 | - } else { | |
228 | - return nil, 0, Error(token + "が不正です") | |
229 | - } | |
396 | + if len(c.token) > 0 && c.token != "," { | |
397 | + return nil, 0, Error(c.token + "が不正です") | |
230 | 398 | } |
231 | 399 | return be, v, nil |
232 | 400 | } |
@@ -237,8 +405,8 @@ func (c *Compiler) fullExpression(in *string, | ||
237 | 405 | if err != nil { |
238 | 406 | return nil, 0, err |
239 | 407 | } |
240 | - if token := c.tokenizer(in); len(token) > 0 { | |
241 | - return nil, 0, Error(token + "が不正です") | |
408 | + if len(c.token) > 0 { | |
409 | + return nil, 0, Error(c.token + "が不正です") | |
242 | 410 | } |
243 | 411 | return be, v, nil |
244 | 412 | } |
@@ -321,7 +489,7 @@ func (c *Compiler) stateParam(is IniSection, name string, | ||
321 | 489 | data, ok := is[name] |
322 | 490 | if ok { |
323 | 491 | if err := f(data); err != nil { |
324 | - return Error(name + ": " + err.Error()) | |
492 | + return Error(data + "\n" + name + ": " + err.Error()) | |
325 | 493 | } |
326 | 494 | delete(is, name) |
327 | 495 | } |
@@ -344,13 +512,16 @@ func (c *Compiler) scAdd(sc *StateControllerBase, id byte, | ||
344 | 512 | } |
345 | 513 | bes = append(bes, be) |
346 | 514 | vs = append(vs, v) |
515 | + if n < numArg && c.token != "," { | |
516 | + break | |
517 | + } | |
347 | 518 | } |
348 | 519 | cns := true |
349 | 520 | for i, v := range vs { |
350 | 521 | if math.IsNaN(v) { |
351 | 522 | cns = false |
352 | 523 | } else { |
353 | - bes[i].AppendValue(vt, v) | |
524 | + bes[i].AppendValue(BytecodeValue{vt, v}) | |
354 | 525 | } |
355 | 526 | } |
356 | 527 | if cns { |
@@ -530,7 +701,21 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
530 | 701 | }); err != nil { |
531 | 702 | return err |
532 | 703 | } |
533 | - unimplemented() | |
704 | + if err := c.stateParam(is, "anim", func(data string) error { | |
705 | + return c.scAdd(&sc, stateDef_anim, data, VT_Int, 1) | |
706 | + }); err != nil { | |
707 | + return err | |
708 | + } | |
709 | + if err := c.stateParam(is, "ctrl", func(data string) error { | |
710 | + return c.scAdd(&sc, stateDef_ctrl, data, VT_Bool, 1) | |
711 | + }); err != nil { | |
712 | + return err | |
713 | + } | |
714 | + if err := c.stateParam(is, "poweradd", func(data string) error { | |
715 | + return c.scAdd(&sc, stateDef_poweradd, data, VT_Int, 1) | |
716 | + }); err != nil { | |
717 | + return err | |
718 | + } | |
534 | 719 | sbc.stateDef = stateDef(sc) |
535 | 720 | return nil |
536 | 721 | }) |
@@ -93,6 +93,7 @@ type System struct { | ||
93 | 93 | loadMutex sync.Mutex |
94 | 94 | ignoreMostErrors bool |
95 | 95 | stringPool [MaxSimul * 2]StringPool |
96 | + bcStack BytecodeStack | |
96 | 97 | } |
97 | 98 | |
98 | 99 | func (s *System) init(w, h int32) *lua.LState { |