Skip to content

Commit a8a3aa6

Browse files
committed
[js] More uint64 and int64 tweaks
1 parent 9709afb commit a8a3aa6

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/vm/js/nqp-runtime/container-specs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class NativeRef {
250250
});
251251
} else if (primitiveType == 4) { // int64
252252
this.STable.addInternalMethods(class {
253-
$$iscont_s() {
253+
$$iscont_i() {
254254
return 1;
255255
}
256256

src/vm/js/nqp-runtime/refs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ function attrRef_s(currentHLL, get, set) {
3939
return ref;
4040
}
4141

42+
function attrRef_i64(currentHLL, get, set) {
43+
const refType = currentHLL.get('int64_attr_ref');
44+
if (refType === undefined) {
45+
throw 'No int64 attribute reference type registered for current HLL';
46+
}
47+
const STable = refType._STable;
48+
const ref = STable.REPR.allocate(STable);
49+
ref.get = get;
50+
ref.set = set;
51+
return ref;
52+
}
53+
4254
op.getattrref_i = function(currentHLL, obj, classHandle, attrName) {
4355
return attrRef_i(currentHLL,
4456
() => obj.$$getattr_i(classHandle, attrName),
@@ -184,3 +196,6 @@ op.atposref_s = function(currentHLL, obj, index) {
184196
helpers.attrRef_i = attrRef_i;
185197
helpers.attrRef_n = attrRef_n;
186198
helpers.attrRef_s = attrRef_s;
199+
200+
helpers.attrRef_i64 = attrRef_i64;
201+
helpers.attrRef_u64 = attrRef_i64; // TODO - think if that's good

src/vm/js/nqp-runtime/reprs.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class P6opaque extends REPRWithAttributes {
522522
return 'return this.$$bindattr$' + slot + '(value)';
523523
}, ', value', false, 'bind a value');
524524

525-
const suffixes = ['_s', '_i', '_n'];
525+
const suffixes = ['_s', '_i', '_n', '_i64', '_u64'];
526526
for (const suffix of suffixes) {
527527
/* TODO only check attributes of proper type */
528528
this.generateUniversalAccessor(STable, '$$getattr' + suffix, function(slot) {
@@ -790,11 +790,23 @@ class P6int extends REPR {
790790

791791
generateFlattenedAccessors(ownerSTable, attrContentSTable, slot) {
792792
const attr = slotToAttr(slot);
793-
ownerSTable.addInternalMethod('$$getattr$' + slot, function() {
794-
const obj = attrContentSTable.REPR.allocate(attrContentSTable);
795-
obj.$$setInt(this[attr]);
796-
return obj;
797-
});
793+
if (this.bits == 64) {
794+
/* HACK - int64 and uint64 attributes are for now set in this werid way */
795+
ownerSTable.addInternalMethod('$$getattr$' + slot, function() {
796+
const objectWithAttr = this;
797+
return new (class {
798+
$$assign(ctx, value) {
799+
objectWithAttr[attr] = value.$$getInt64();
800+
}
801+
});
802+
});
803+
} else {
804+
ownerSTable.addInternalMethod('$$getattr$' + slot, function() {
805+
const obj = attrContentSTable.REPR.allocate(attrContentSTable);
806+
obj.$$setInt(this[attr]);
807+
return obj;
808+
});
809+
}
798810
}
799811

800812
generateRefAccessors(ownerSTable, attrContentSTable, slot) {
@@ -1240,7 +1252,7 @@ class VMArray extends REPR {
12401252
return value;
12411253
}
12421254
});
1243-
} else if (this.primType === 1) {
1255+
} else if (this.primType === 1 || this.primType === 4 || this.primType == 5) {
12441256
let mangle;
12451257
if (this.type !== Null) {
12461258
const repr = this.type._STable.REPR;

0 commit comments

Comments
 (0)