@abaplint/runtime
Version:
Transpiler - Runtime
160 lines • 5.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.gt = gt;
const _parse_1 = require("../operators/_parse");
const types_1 = require("../types");
const integer_1 = require("../types/integer");
function gt(left, right) {
if (right instanceof integer_1.Integer) {
if (left instanceof integer_1.Integer) {
return left.get() > right.get();
}
else if (left instanceof types_1.Float) {
return left.getRaw() > right.get();
}
else if (left instanceof types_1.Character) {
return (0, _parse_1.parse)(left) > right.get();
}
else if (left instanceof types_1.Integer8) {
const l = left.get();
const r = BigInt(right.get());
return l > r;
}
}
else if (right instanceof types_1.Float) {
if (left instanceof types_1.Float) {
return left.getRaw() > right.getRaw();
}
else if (left instanceof integer_1.Integer) {
return left.get() > right.getRaw();
}
else if (left instanceof types_1.Integer8) {
const l = left.get();
const r = BigInt(right.getRaw());
return l > r;
}
}
else if (right instanceof types_1.Integer8) {
if (left instanceof types_1.Table || left instanceof types_1.HashedTable) {
throw new Error("runtime_todo, gt TABLE");
}
const l = left instanceof types_1.Integer8 ? left.get() : BigInt((0, _parse_1.parse)(left));
const r = right instanceof types_1.Integer8 ? right.get() : BigInt((0, _parse_1.parse)(right));
return l > r;
}
if (left instanceof types_1.FieldSymbol) {
if (left.getPointer() === undefined) {
throw new Error("GETWA_NOT_ASSIGNED");
}
return gt(left.getPointer(), right);
}
else if (right instanceof types_1.FieldSymbol) {
if (right.getPointer() === undefined) {
throw new Error("GETWA_NOT_ASSIGNED");
}
return gt(left, right.getPointer());
}
if (left instanceof types_1.Table || right instanceof types_1.Table || left instanceof types_1.HashedTable || right instanceof types_1.HashedTable) {
throw new Error("runtime_todo, gt TABLE");
}
else if (left instanceof types_1.Hex || right instanceof types_1.Hex || left instanceof types_1.HexUInt8 || right instanceof types_1.HexUInt8) {
return gt_with_hex(left, right);
}
if (left instanceof types_1.Integer8) {
const l = left.get();
const r = BigInt((0, _parse_1.parse)(right));
return l > r;
}
if (left instanceof types_1.Structure || right instanceof types_1.Structure) {
if (!(right instanceof types_1.Structure)) {
return gt(left.getCharacter(), right);
}
else if (!(left instanceof types_1.Structure)) {
return gt(left, right.getCharacter());
}
}
let l = undefined;
if (typeof left === "number" || typeof left === "string") {
l = left;
}
else if (left instanceof types_1.Float || left instanceof types_1.DecFloat34) {
l = left.getRaw();
}
else {
l = left.get();
}
let r = undefined;
if (typeof right === "number" || typeof right === "string") {
r = right;
}
else if (right instanceof types_1.Float || right instanceof types_1.DecFloat34) {
r = right.getRaw();
}
else {
r = right.get();
}
if (typeof l === "string" && typeof r === "number") {
if (l === "") {
l = 0;
}
else {
l = parseInt(l, 10);
}
}
else if (typeof l === "number" && typeof r === "string") {
if (r === "") {
r = 0;
}
else {
r = parseInt(r, 10);
}
}
if (l === undefined) {
return true; // todo, not sure this is correct
}
else if (r === undefined) {
return true; // todo, not sure this is correct
}
return l > r;
}
///////////////////////////////////////////////////////////////////
function gt_with_hex(left, right) {
const left_hex = get_hex_from_parameter(left);
const right_hex = get_hex_from_parameter(right);
return left_hex > right_hex;
}
function get_hex_from_parameter(comparison_part) {
// todo: optimize?
let hex_from_parameter = "";
switch (typeof comparison_part) {
case "number":
hex_from_parameter = comparison_part.toString(16);
break;
case "string":
hex_from_parameter = comparison_part.split("")
.map(c => c.charCodeAt(0).toString(16).padStart(2, "0"))
.join("");
break;
case "object":
if (comparison_part instanceof types_1.Hex
|| comparison_part instanceof types_1.XString
|| comparison_part instanceof types_1.HexUInt8
|| comparison_part instanceof types_1.Character) {
hex_from_parameter = comparison_part.get();
}
else if (comparison_part instanceof integer_1.Integer) {
hex_from_parameter = comparison_part.get().toString(16).toUpperCase();
if (hex_from_parameter.length % 2 === 1) {
hex_from_parameter = "0" + hex_from_parameter;
}
}
else {
throw new Error("runtime_todo, gt hex1");
}
break;
default:
throw new Error("runtime_todo, gt hex2");
}
return hex_from_parameter;
}
//# sourceMappingURL=gt.js.map