|
@@ -117,15 +117,17 @@ func (a *dynarr) Set(v scope.Value) {
|
|
case *dynarr:
|
|
case *dynarr:
|
|
a.val = x.val
|
|
a.val = x.val
|
|
case STRING:
|
|
case STRING:
|
|
- v := make([]interface{}, len(x))
|
|
|
|
- for i := 0; i < len(x); i++ {
|
|
|
|
- v[i] = CHAR(x[i])
|
|
|
|
|
|
+ z := []rune(string(x))
|
|
|
|
+ v := make([]interface{}, len(z))
|
|
|
|
+ for i := 0; i < len(z); i++ {
|
|
|
|
+ v[i] = CHAR(z[i])
|
|
}
|
|
}
|
|
a.val = v
|
|
a.val = v
|
|
case SHORTSTRING:
|
|
case SHORTSTRING:
|
|
- v := make([]interface{}, len(x))
|
|
|
|
- for i := 0; i < len(x); i++ {
|
|
|
|
- v[i] = SHORTCHAR(x[i])
|
|
|
|
|
|
+ z := []rune(string(x))
|
|
|
|
+ v := make([]interface{}, len(z))
|
|
|
|
+ for i := 0; i < len(z); i++ {
|
|
|
|
+ v[i] = SHORTCHAR(z[i])
|
|
}
|
|
}
|
|
a.val = v
|
|
a.val = v
|
|
case INTEGER:
|
|
case INTEGER:
|
|
@@ -136,18 +138,19 @@ func (a *dynarr) Set(v scope.Value) {
|
|
}
|
|
}
|
|
|
|
|
|
func (a *arr) tryString() (ret string) {
|
|
func (a *arr) tryString() (ret string) {
|
|
- for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
|
|
|
|
|
|
+ stop := false
|
|
|
|
+ for i := 0; !stop && i < len(a.val) && a.val[i] != nil; i++ {
|
|
switch x := a.val[i].(type) {
|
|
switch x := a.val[i].(type) {
|
|
case CHAR:
|
|
case CHAR:
|
|
- if int(x) == 0 {
|
|
|
|
- break
|
|
|
|
|
|
+ stop = int(x) == 0
|
|
|
|
+ if !stop {
|
|
|
|
+ ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
}
|
|
}
|
|
- ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
|
|
case SHORTCHAR:
|
|
case SHORTCHAR:
|
|
- if int(x) == 0 {
|
|
|
|
- break
|
|
|
|
|
|
+ stop = int(x) == 0
|
|
|
|
+ if !stop {
|
|
|
|
+ ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
}
|
|
}
|
|
- ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(x))
|
|
halt.As(100, reflect.TypeOf(x))
|
|
}
|
|
}
|
|
@@ -170,6 +173,7 @@ func (a *arr) String() (ret string) {
|
|
return ret
|
|
return ret
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//возвращает *idx
|
|
func (a *arr) Get(id scope.Value) scope.Value {
|
|
func (a *arr) Get(id scope.Value) scope.Value {
|
|
switch i := id.(type) {
|
|
switch i := id.(type) {
|
|
case *data:
|
|
case *data:
|
|
@@ -195,7 +199,7 @@ func (i *idx) String() string {
|
|
}
|
|
}
|
|
|
|
|
|
func (i *idx) Set(v scope.Value) {
|
|
func (i *idx) Set(v scope.Value) {
|
|
- //fmt.Println(i, len(i.arr.val))
|
|
|
|
|
|
+ t := i.arr.link.Complex()
|
|
switch x := v.(type) {
|
|
switch x := v.(type) {
|
|
case *idx:
|
|
case *idx:
|
|
i.arr.val[i.idx] = x.arr.val[x.idx]
|
|
i.arr.val[i.idx] = x.arr.val[x.idx]
|
|
@@ -203,24 +207,47 @@ func (i *idx) Set(v scope.Value) {
|
|
i.Set(x.val.(scope.Value))
|
|
i.Set(x.val.(scope.Value))
|
|
case CHAR:
|
|
case CHAR:
|
|
i.arr.val[i.idx] = x
|
|
i.arr.val[i.idx] = x
|
|
|
|
+ case STRING:
|
|
|
|
+ _ = t.(object.ArrayType)
|
|
|
|
+ i.arr.val[i.idx].(*arr).Set(x)
|
|
default:
|
|
default:
|
|
- halt.As(100, reflect.TypeOf(x))
|
|
|
|
|
|
+ halt.As(100, reflect.TypeOf(x), x, t)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (i *idx) Get() scope.Value {
|
|
|
|
+ x := i.arr.val[i.idx]
|
|
|
|
+ switch z := x.(type) {
|
|
|
|
+ case CHAR:
|
|
|
|
+ return z
|
|
|
|
+ case nil:
|
|
|
|
+ b := i.arr.link.Complex().(object.ArrayType).Base()
|
|
|
|
+ switch b {
|
|
|
|
+ case object.CHAR:
|
|
|
|
+ return CHAR(rune(0))
|
|
|
|
+ default:
|
|
|
|
+ halt.As(101, reflect.TypeOf(b))
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ halt.As(100, i.idx, reflect.TypeOf(z))
|
|
|
|
+ }
|
|
|
|
+ panic(0)
|
|
|
|
+}
|
|
|
|
+
|
|
func (a *dynarr) tryString() (ret string) {
|
|
func (a *dynarr) tryString() (ret string) {
|
|
- for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
|
|
|
|
|
|
+ stop := false
|
|
|
|
+ for i := 0; !stop && i < len(a.val) && a.val[i] != nil; i++ {
|
|
switch x := a.val[i].(type) {
|
|
switch x := a.val[i].(type) {
|
|
case CHAR:
|
|
case CHAR:
|
|
- if int(x) == 0 {
|
|
|
|
- break
|
|
|
|
|
|
+ stop = int(x) == 0
|
|
|
|
+ if !stop {
|
|
|
|
+ ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
}
|
|
}
|
|
- ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
|
|
case SHORTCHAR:
|
|
case SHORTCHAR:
|
|
- if int(x) == 0 {
|
|
|
|
- break
|
|
|
|
|
|
+ stop = int(x) == 0
|
|
|
|
+ if !stop {
|
|
|
|
+ ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
}
|
|
}
|
|
- ret = fmt.Sprint(ret, string([]rune{rune(x)}))
|
|
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(x))
|
|
halt.As(100, reflect.TypeOf(x))
|
|
}
|
|
}
|
|
@@ -420,6 +447,16 @@ func newData(o object.Object) (ret scope.Variable) {
|
|
}
|
|
}
|
|
case object.ArrayType:
|
|
case object.ArrayType:
|
|
ret = &arr{link: o, length: t.Len()}
|
|
ret = &arr{link: o, length: t.Len()}
|
|
|
|
+ if a := ret.(*arr); t.Base() == object.COMPLEX {
|
|
|
|
+ a.val = make([]interface{}, int(t.Len()))
|
|
|
|
+ for i := 0; i < int(t.Len()); i++ {
|
|
|
|
+ fake := object.New(object.VARIABLE, int(cp.SomeAdr()))
|
|
|
|
+ fake.SetName("[?]")
|
|
|
|
+ fake.SetType(object.COMPLEX)
|
|
|
|
+ fake.SetComplex(t.Complex())
|
|
|
|
+ a.val[i] = newData(fake)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
case object.DynArrayType:
|
|
case object.DynArrayType:
|
|
ret = &dynarr{link: o}
|
|
ret = &dynarr{link: o}
|
|
default:
|
|
default:
|
|
@@ -440,6 +477,8 @@ func fromg(x interface{}) scope.Value {
|
|
return BOOLEAN(x)
|
|
return BOOLEAN(x)
|
|
case *big.Int:
|
|
case *big.Int:
|
|
return SET{bits: x}
|
|
return SET{bits: x}
|
|
|
|
+ case string:
|
|
|
|
+ return STRING(x)
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(x))
|
|
halt.As(100, reflect.TypeOf(x))
|
|
}
|
|
}
|
|
@@ -517,7 +556,7 @@ func vfrom(v scope.Value) scope.Value {
|
|
default:
|
|
default:
|
|
halt.As(100, n.link.Type())
|
|
halt.As(100, n.link.Type())
|
|
}
|
|
}
|
|
- case INTEGER:
|
|
|
|
|
|
+ case INTEGER, CHAR:
|
|
return n
|
|
return n
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(n))
|
|
halt.As(100, reflect.TypeOf(n))
|
|
@@ -563,10 +602,24 @@ func gfrom(v scope.Value) interface{} {
|
|
} else {
|
|
} else {
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
+ case object.CHAR:
|
|
|
|
+ if n.val != nil {
|
|
|
|
+ return n.tryString()
|
|
|
|
+ } else {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
default:
|
|
default:
|
|
halt.As(100, n.link.Complex().(object.ArrayType).Base())
|
|
halt.As(100, n.link.Complex().(object.ArrayType).Base())
|
|
}
|
|
}
|
|
panic(0)
|
|
panic(0)
|
|
|
|
+ case *idx:
|
|
|
|
+ switch n.arr.link.Complex().(object.ArrayType).Base() {
|
|
|
|
+ case object.CHAR:
|
|
|
|
+ return rune(n.Get().(CHAR))
|
|
|
|
+ default:
|
|
|
|
+ halt.As(100, n.arr.link.Complex().(object.ArrayType).Base())
|
|
|
|
+ }
|
|
|
|
+ panic(0)
|
|
case PTR:
|
|
case PTR:
|
|
assert.For(n == NIL, 40)
|
|
assert.For(n == NIL, 40)
|
|
return nil
|
|
return nil
|
|
@@ -574,6 +627,8 @@ func gfrom(v scope.Value) interface{} {
|
|
return int32(n)
|
|
return int32(n)
|
|
case BOOLEAN:
|
|
case BOOLEAN:
|
|
return bool(n)
|
|
return bool(n)
|
|
|
|
+ case STRING:
|
|
|
|
+ return string(n)
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(n))
|
|
halt.As(100, reflect.TypeOf(n))
|
|
}
|
|
}
|
|
@@ -883,7 +938,7 @@ func (o *ops) Div(a, b scope.Value) scope.Value {
|
|
case INTEGER:
|
|
case INTEGER:
|
|
switch y := b.(type) {
|
|
switch y := b.(type) {
|
|
case INTEGER:
|
|
case INTEGER:
|
|
- return INTEGER(x / y)
|
|
|
|
|
|
+ return INTEGER(math.Floor(float64(x) / float64(y)))
|
|
default:
|
|
default:
|
|
panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
}
|
|
}
|
|
@@ -915,7 +970,12 @@ func (o *ops) Mod(a, b scope.Value) scope.Value {
|
|
case INTEGER:
|
|
case INTEGER:
|
|
switch y := b.(type) {
|
|
switch y := b.(type) {
|
|
case INTEGER:
|
|
case INTEGER:
|
|
- return INTEGER(x % y)
|
|
|
|
|
|
+ z := x % y
|
|
|
|
+ switch {
|
|
|
|
+ case (x < 0) != (y < 0):
|
|
|
|
+ z = z + y
|
|
|
|
+ }
|
|
|
|
+ return INTEGER(z)
|
|
default:
|
|
default:
|
|
panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
}
|
|
}
|
|
@@ -1041,14 +1101,17 @@ func (o *ops) Len(a object.Object, _a, _b scope.Value) (ret scope.Value) {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
switch a := _a.(type) {
|
|
switch a := _a.(type) {
|
|
- // case string:
|
|
|
|
- // ret = int64(utf8.RuneCountInString(_a.(string)))
|
|
|
|
- // case []interface{}:
|
|
|
|
- // ret = int64(len(_a.([]interface{})))
|
|
|
|
case *arr:
|
|
case *arr:
|
|
ret = INTEGER(int32(a.length))
|
|
ret = INTEGER(int32(a.length))
|
|
case *dynarr:
|
|
case *dynarr:
|
|
ret = INTEGER(int32(len(a.val)))
|
|
ret = INTEGER(int32(len(a.val)))
|
|
|
|
+ case STRING:
|
|
|
|
+ rs := []rune(string(a))
|
|
|
|
+ ln := len(rs)
|
|
|
|
+ ret = INTEGER(0)
|
|
|
|
+ for l := 0; l < ln && rs[l] != 0; l++ {
|
|
|
|
+ ret = INTEGER(l + 1)
|
|
|
|
+ }
|
|
default:
|
|
default:
|
|
panic(fmt.Sprintln("unsupported", reflect.TypeOf(a)))
|
|
panic(fmt.Sprintln("unsupported", reflect.TypeOf(a)))
|
|
}
|
|
}
|
|
@@ -1129,6 +1192,17 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(x))
|
|
halt.As(100, reflect.TypeOf(x))
|
|
}
|
|
}
|
|
|
|
+ case object.LONGINT:
|
|
|
|
+ switch x := a.(type) {
|
|
|
|
+ case *data:
|
|
|
|
+ return o.Conv(vfrom(x), typ)
|
|
|
|
+ case INTEGER:
|
|
|
|
+ return LONGINT(x)
|
|
|
|
+ case REAL:
|
|
|
|
+ return LONGINT(math.Floor(float64(x)))
|
|
|
|
+ default:
|
|
|
|
+ halt.As(100, reflect.TypeOf(x))
|
|
|
|
+ }
|
|
case object.SET:
|
|
case object.SET:
|
|
switch x := a.(type) {
|
|
switch x := a.(type) {
|
|
case *data:
|
|
case *data:
|
|
@@ -1167,6 +1241,8 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
|
|
return SHORTSTRING(x.tryString())
|
|
return SHORTSTRING(x.tryString())
|
|
case *arr:
|
|
case *arr:
|
|
return SHORTSTRING(x.tryString())
|
|
return SHORTSTRING(x.tryString())
|
|
|
|
+ case STRING:
|
|
|
|
+ return SHORTSTRING(x)
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(x))
|
|
halt.As(100, reflect.TypeOf(x))
|
|
}
|
|
}
|
|
@@ -1206,6 +1282,20 @@ func (o *ops) Abs(a scope.Value) scope.Value {
|
|
panic(100)
|
|
panic(100)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (o *ops) Minus(a scope.Value) scope.Value {
|
|
|
|
+ switch x := a.(type) {
|
|
|
|
+ case *data:
|
|
|
|
+ return o.Minus(vfrom(x))
|
|
|
|
+ case INTEGER:
|
|
|
|
+ return INTEGER(-x)
|
|
|
|
+ case LONGINT:
|
|
|
|
+ return LONGINT(-x)
|
|
|
|
+ default:
|
|
|
|
+ halt.As(100, reflect.TypeOf(x))
|
|
|
|
+ }
|
|
|
|
+ panic(100)
|
|
|
|
+}
|
|
|
|
+
|
|
func (o *ops) Odd(a scope.Value) scope.Value {
|
|
func (o *ops) Odd(a scope.Value) scope.Value {
|
|
switch x := a.(type) {
|
|
switch x := a.(type) {
|
|
case *data:
|
|
case *data:
|
|
@@ -1274,9 +1364,11 @@ func (o *ops) Eq(a, b scope.Value) scope.Value {
|
|
}
|
|
}
|
|
|
|
|
|
func (o *ops) Neq(a, b scope.Value) scope.Value {
|
|
func (o *ops) Neq(a, b scope.Value) scope.Value {
|
|
- switch a.(type) {
|
|
|
|
|
|
+ switch i := a.(type) {
|
|
case *data:
|
|
case *data:
|
|
return o.Neq(vfrom(a), b)
|
|
return o.Neq(vfrom(a), b)
|
|
|
|
+ case *idx:
|
|
|
|
+ return o.Neq(vfrom(i.Get()), b)
|
|
default:
|
|
default:
|
|
switch b.(type) {
|
|
switch b.(type) {
|
|
case *data:
|
|
case *data:
|
|
@@ -1319,6 +1411,13 @@ func (o *ops) Neq(a, b scope.Value) scope.Value {
|
|
default:
|
|
default:
|
|
panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
}
|
|
}
|
|
|
|
+ case CHAR:
|
|
|
|
+ switch y := b.(type) {
|
|
|
|
+ case CHAR:
|
|
|
|
+ return BOOLEAN(x != y)
|
|
|
|
+ default:
|
|
|
|
+ panic(fmt.Sprintln(reflect.TypeOf(y)))
|
|
|
|
+ }
|
|
default:
|
|
default:
|
|
panic(fmt.Sprintln(reflect.TypeOf(x)))
|
|
panic(fmt.Sprintln(reflect.TypeOf(x)))
|
|
}
|
|
}
|
|
@@ -1442,6 +1541,10 @@ func (o *ops) TypeOf(x scope.Value) (object.Type, object.ComplexType) {
|
|
}
|
|
}
|
|
case *rec:
|
|
case *rec:
|
|
return v.link.Type(), v.link.Complex()
|
|
return v.link.Type(), v.link.Complex()
|
|
|
|
+ case *dynarr:
|
|
|
|
+ return v.link.Type(), v.link.Complex()
|
|
|
|
+ case *arr:
|
|
|
|
+ return v.link.Type(), v.link.Complex()
|
|
default:
|
|
default:
|
|
halt.As(100, reflect.TypeOf(v))
|
|
halt.As(100, reflect.TypeOf(v))
|
|
}
|
|
}
|