Skip to content

Commit 68d5f07

Browse files
Upload latest offline copy (1.1.3)
One of the tests was failing on 32 bit systems, now it isn't. * Integer table keys that fit into a script integer but not a system default int value will no longer be truncated sometimes. Such keys were always supposed to go in the hash part of the table, but before this fix the keys were being truncated first in some cases. (table.go
1 parent c34eafe commit 68d5f07

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ noise, each change listed here will list the files I modified for that change.
224224
single person teams, where the only important use is rolling back bad changes and such)
225225

226226

227+
* * *
228+
229+
1.1.3
230+
231+
One of the tests was failing on 32 bit systems, now it isn't.
232+
233+
* Integer table keys that fit into a script integer but not a system default int value will no longer be truncated sometimes.
234+
Such keys were always supposed to go in the hash part of the table, but before this fix the keys were being truncated first
235+
in some cases. (table.go)
236+
227237
* * *
228238

229239
1.1.2
@@ -234,7 +244,7 @@ and a few other miscellaneous VM issues (mostly related to metatables).
234244
This version also adds a minor new feature, nothing to get excited about... Basically I made it so that JSON or XML encoding
235245
an AST produces slightly more readable results for operator expression nodes. Someone else suggested the idea (actually they
236246
submitted a patch, yay them!). I never would have thought to do this myself (never needed it), but now that I have it, it
237-
seems like it could be useful for debugging the compiler amoung other things.
247+
seems like it could be useful for debugging the compiler among other things.
238248

239249
Unfortunately due to the way the AST and most encodings work, it is impossible to unmarshal the AST. I am not 100% sure if
240250
it is possible with XML or not, but it certainly will not work with JSON. This could maybe be fixed, but would be way too

table.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,21 @@ func (tbl *table) maybeExtend(key int) bool {
159159
}
160160

161161
// Internal helper
162-
func (tbl *table) setInt(k int, v value) {
162+
func (tbl *table) setInt(k int64, v value) {
163163
// Store the value or clear the key.
164164
hash := false
165-
k2 := k - TableIndexOffset
166-
if k2 >= 0 && k2 < len(tbl.array) {
165+
k2 := int(k) - TableIndexOffset
166+
k2ok := int64(int(k)) == k
167+
if k2ok && k2 >= 0 && k2 < len(tbl.array) {
167168
tbl.array[k2] = v
168-
} else if k2 >= 0 && v != nil && tbl.maybeExtend(k2) {
169+
} else if k2ok && k2 >= 0 && v != nil && tbl.maybeExtend(k2) {
169170
tbl.array[k2] = v
170171
} else if v == nil {
171172
hash = true
172-
delete(tbl.hash, int64(k))
173+
delete(tbl.hash, k)
173174
} else {
174175
hash = true
175-
tbl.hash[int64(k)] = v
176+
tbl.hash[k] = v
176177
}
177178

178179
// Decide if the stored length was invalidated and fix it if possible.
@@ -211,25 +212,26 @@ func (tbl *table) Exists(k value) bool {
211212
return false
212213
}
213214

214-
if i := int(idx); float64(i) == idx {
215+
if i := int64(idx); float64(i) == idx {
215216
return tbl.existsInt(i)
216217
}
217218
v, ok := tbl.hash[k]
218219
return ok && v != nil
219220
case int64:
220-
return tbl.existsInt(int(idx))
221+
return tbl.existsInt(idx)
221222
default:
222223
v, ok := tbl.hash[k]
223224
return ok && v != nil
224225
}
225226
}
226227

227-
func (tbl *table) existsInt(k int) bool {
228-
k2 := k - TableIndexOffset
229-
if 0 <= k2 && k2 < len(tbl.array) {
228+
func (tbl *table) existsInt(k int64) bool {
229+
k2 := int(k) - TableIndexOffset
230+
k2ok := int64(int(k)) == k
231+
if k2ok && 0 <= k2 && k2 < len(tbl.array) {
230232
return tbl.array[k2] != nil
231233
}
232-
v, ok := tbl.hash[int64(k)]
234+
v, ok := tbl.hash[k]
233235
return ok && v != nil
234236
}
235237

@@ -243,15 +245,15 @@ func (tbl *table) SetRaw(k, v value) {
243245
return
244246
}
245247

246-
if i := int(idx); float64(i) == idx {
248+
if i := int64(idx); float64(i) == idx {
247249
tbl.setInt(i, v)
248250
} else if v == nil {
249251
delete(tbl.hash, k)
250252
} else {
251253
tbl.hash[k] = v
252254
}
253255
case int64:
254-
tbl.setInt(int(idx), v)
256+
tbl.setInt(idx, v)
255257
default:
256258
if v == nil {
257259
delete(tbl.hash, k)
@@ -262,12 +264,13 @@ func (tbl *table) SetRaw(k, v value) {
262264
}
263265

264266
// Internal helper
265-
func (tbl *table) getInt(k int) value {
266-
k2 := k - TableIndexOffset
267-
if 0 <= k2 && k2 < len(tbl.array) {
267+
func (tbl *table) getInt(k int64) value {
268+
k2 := int(k) - TableIndexOffset
269+
k2ok := int64(int(k)) == k
270+
if k2ok && 0 <= k2 && k2 < len(tbl.array) {
268271
return tbl.array[k2]
269272
}
270-
return tbl.hash[int64(k)]
273+
return tbl.hash[k]
271274
}
272275

273276
// GetRaw reads the value at index k from the table without using any meta methods.
@@ -280,11 +283,11 @@ func (tbl *table) GetRaw(k value) value {
280283
return nil
281284
}
282285

283-
if i := int(idx); float64(i) == idx {
286+
if i := int64(idx); float64(i) == idx {
284287
return tbl.getInt(i)
285288
}
286289
case int64:
287-
return tbl.getInt(int(idx))
290+
return tbl.getInt(idx)
288291
}
289292
// Non-number or non-integral float.
290293
return tbl.hash[k]

0 commit comments

Comments
 (0)