Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AssemblyScript] Added basic AssemblyScript support #6408

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f25a3d6
[Assembly Script] Add basic Assembly Script support
LucasSwitz Jan 19, 2021
61c3c89
[AssemblyScript] Created basic standalone AssemlbyScript generator
LucasSwitz Jan 21, 2021
68f3a3b
Merge branch 'master' into assembly_script_support
LucasSwitz Jan 21, 2021
ddd08c9
[AssemblyScript] added AssemblyScript source to build
LucasSwitz Jan 21, 2021
8801f84
Merge branch 'assembly_script_support' of https://github.com/LucasSwi…
LucasSwitz Jan 21, 2021
df9b280
[AssemlbyScript] Added AssemblyScript generator to Cmake and labeler
LucasSwitz Jan 21, 2021
ff78ada
[AssemblyScript] Removed unused imports from GenEnum.
LucasSwitz Jan 26, 2021
ca4864a
Merge branch 'master' into assembly_script_support
LucasSwitz Jan 26, 2021
45b3cf3
[AssemblyScript] Aligned with new FieldDef
LucasSwitz Jan 26, 2021
9009f14
Merge branch 'master' into assembly_script_support
LucasSwitz Feb 12, 2021
f259c0c
Merge branch 'master' into assembly_script_support
LucasSwitz Mar 24, 2021
fbc284e
Removed unused GenPrefixedImport logic
LucasSwitz Mar 24, 2021
8e5a436
Removed unused GenPrefixedImport logic
LucasSwitz Mar 24, 2021
90382ac
Merge branch 'assembly_script_support' of https://github.com/LucasSwi…
LucasSwitz Mar 24, 2021
a2766d7
Merge branch 'master' into assembly_script_support
LucasSwitz May 13, 2021
8721423
Update BUILD.bazel
LucasSwitz May 13, 2021
22e3322
Replace Long types with i64 / u64
LucasSwitz May 27, 2021
45fea2d
Merge branch 'assembly_script_support' of https://github.com/LucasSwi…
LucasSwitz May 27, 2021
c071b69
Replace Long types with i64 / u64
LucasSwitz May 27, 2021
63bdba5
Merge branch 'master' into assembly_script_support
LucasSwitz May 27, 2021
50a7279
Ran clang formatter
LucasSwitz May 27, 2021
d5fc36d
Fixed readInt64 type
LucasSwitz May 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions as/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
FILE_IDENTIFIER_LENGTH,
} from './constants';
import { Offset, IGeneratedObject } from './types';
import { Long } from './long';

export class Builder {
private bb: ByteBuffer;
Expand Down Expand Up @@ -143,7 +142,7 @@ export class Builder {
this.bb.writeInt32((this.space -= 4), value);
}

writeInt64(value: Long): void {
writeInt64(value: i64): void {
this.bb.writeInt64((this.space -= 8), value);
}

Expand Down Expand Up @@ -186,7 +185,7 @@ export class Builder {
* Add an `int64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int64` to add the the buffer.
*/
addInt64(value: Long): void {
addInt64(value: i64): void {
this.prep(8, 0);
this.writeInt64(value);
}
Expand Down Expand Up @@ -230,7 +229,7 @@ export class Builder {
}
}

addFieldInt64(voffset: i32, value: Long, defaultValue: Long): void {
addFieldInt64(voffset: i32, value: i64, defaultValue: i64): void {
if (this.force_defaults || !value.equals(defaultValue)) {
this.addInt64(value);
this.slot(voffset);
Expand Down Expand Up @@ -605,13 +604,6 @@ export class Builder {
return this.endVector();
}

/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(low: i32, high: i32): Long {
return Long.create(low, high);
}

/**
* A helper function to pack an object
*
Expand Down
48 changes: 26 additions & 22 deletions as/byte-buffer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FILE_IDENTIFIER_LENGTH, SIZEOF_INT } from './constants';
import { Long } from './long';
import { int32, isLittleEndian, float32, float64 } from './utils';
import { Offset, Table, IGeneratedObject } from './types';

Expand Down Expand Up @@ -51,15 +50,15 @@ export class ByteBuffer {
}

readInt8(offset: i32): i32 {
return (i32(this.readUint8(offset)) << 24) >> 24;
return this.readUint8(offset) as i32;
}

readUint8(offset: i32): i32 {
return this.bytes_[offset];
}

readInt16(offset: i32): i32 {
return (i32(this.readUint16(offset)) << 16) >> 16;
return this.readUint16(offset) as i32;
}

readUint16(offset: i32): i32 {
Expand All @@ -75,16 +74,16 @@ export class ByteBuffer {
);
}

readUint32(offset: i32): i32 {
return this.readInt32(offset) >>> 0;
readUint32(offset: i32): u32 {
return this.readInt32(offset);
}

readInt64(offset: i32): Long {
return new Long(this.readInt32(offset), this.readInt32(offset + 4));
readInt64(offset: i32): i32 {
return this.readInt32(offset) | (this.readInt32(offset + 4) << 32);
LucasSwitz marked this conversation as resolved.
Show resolved Hide resolved
}

readUint64(offset: i32): Long {
return new Long(this.readUint32(offset), this.readUint32(offset + 4));
readUint64(offset: i32): u64 {
return this.readInt64(offset) as u64;
}

readFloat32(offset: i32): f32 {
Expand Down Expand Up @@ -130,14 +129,26 @@ export class ByteBuffer {
this.bytes_[offset + 3] = value >> 24;
}

writeInt64(offset: i32, value: Long): void {
this.writeInt32(offset, value.low);
this.writeInt32(offset + 4, value.high);
writeInt64(offset: i32, value: i32): void {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
this.bytes_[offset + 2] = value >> 16;
this.bytes_[offset + 3] = value >> 24;
this.bytes_[offset + 4] = value >> 32;
this.bytes_[offset + 5] = value >> 38;
this.bytes_[offset + 6] = value >> 46;
this.bytes_[offset + 7] = value >> 54;
}

writeUint64(offset: i32, value: Long): void {
this.writeUint32(offset, value.low);
this.writeUint32(offset + 4, value.high);
writeUint64(offset: i32, value: i32): void {
this.bytes_[offset] = value;
this.bytes_[offset + 1] = value >> 8;
this.bytes_[offset + 2] = value >> 16;
this.bytes_[offset + 3] = value >> 24;
this.bytes_[offset + 4] = value >> 32;
this.bytes_[offset + 5] = value >> 38;
this.bytes_[offset + 6] = value >> 46;
this.bytes_[offset + 7] = value >> 54;
}

writeFloat32(offset: i32, value: f32): void {
Expand Down Expand Up @@ -308,13 +319,6 @@ export class ByteBuffer {
return true;
}

/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(low: i32, high: i32): Long {
return Long.create(low, high);
}

/**
* A helper function for generating list for obj api
*/
Expand Down
2 changes: 0 additions & 2 deletions as/flatbuffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as constants from './constants';
import * as types from './types';
import * as utils from './utils';

import { Long as LongClass } from './long';
import { Encoding as EncodingEnum } from './encoding';
import { Builder as BuilderClass } from './builder';
import { ByteBuffer as ByteBufferClass } from './byte-buffer';
Expand All @@ -24,6 +23,5 @@ export const float32 = utils.float32;
export const float64 = utils.float64;
export const isLittleEndian = utils.isLittleEndian;

export type Long = LongClass;
export type Builder = BuilderClass;
export type ByteBuffer = ByteBufferClass;
26 changes: 0 additions & 26 deletions as/long.ts

This file was deleted.

19 changes: 7 additions & 12 deletions src/idl_gen_as.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ class AsGenerator : public BaseGenerator {
case BASE_TYPE_VECTOR: return "[]";

case BASE_TYPE_LONG:
int64_t constant = StringToInt(value.constant.c_str());
return NumToString(constant) + " as i64";
case BASE_TYPE_ULONG: {
int64_t constant = StringToInt(value.constant.c_str());
std::string createLong = context + ".createLong";
return createLong + "(" + NumToString(static_cast<int32_t>(constant)) +
", " + NumToString(static_cast<int32_t>(constant >> 32)) + ")";
return NumToString(constant) + " as u64";
}

default: return value.constant;
Expand All @@ -263,8 +263,9 @@ class AsGenerator : public BaseGenerator {
case BASE_TYPE_BOOL: return "boolean";
case BASE_TYPE_FLOAT: return "f32";
case BASE_TYPE_LONG:
return "i64";
case BASE_TYPE_ULONG:
return allowNull ? "flatbuffers.Long|null" : "flatbuffers.Long";
return "u64";
default:
if (IsScalar(type.base_type)) {
if (type.enum_def) {
Expand Down Expand Up @@ -1232,7 +1233,7 @@ class AsGenerator : public BaseGenerator {
code += "false";
} else if (field.value.type.element == BASE_TYPE_LONG ||
field.value.type.element == BASE_TYPE_ULONG) {
code += GenBBAccess() + ".createLong(0, 0)";
code += "0";
} else if (IsScalar(field.value.type.element)) {
if (field.value.type.enum_def) {
code += field.value.constant;
Expand Down Expand Up @@ -1378,14 +1379,8 @@ class AsGenerator : public BaseGenerator {
code += NumToString(it - struct_def.fields.vec.begin()) + ", ";
if (field.value.type.base_type == BASE_TYPE_BOOL) { code += "+"; }
code += argname + ", ";
if (!IsScalar(field.value.type.base_type)) {
if (!IsScalar(field.value.type.base_type) || IsLong(field.value.type.base_type) || HasNullDefault(field)) {
code += "0";
} else if (HasNullDefault(field)) {
if (IsLong(field.value.type.base_type)) {
code += "builder.createLong(0, 0)";
} else {
code += "0";
}
} else {
if (field.value.type.base_type == BASE_TYPE_BOOL) { code += "+"; }
code += GenDefaultValue(field, "builder", imports);
Expand Down