type.js 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Config } from "../util/config";
  2. import { Types } from "./types";
  3. import { BaseTypes } from "./baseTypes";
  4. export class Type {
  5. constructor(baseType) {
  6. this.baseType = baseType;
  7. }
  8. get value () {
  9. return this.baseType.value;
  10. }
  11. get ord () {
  12. return this.baseType.ord;
  13. }
  14. stringInfo () {
  15. return [{type: this.baseType.name, dim: 0}];
  16. }
  17. isCompatible (another) {
  18. if(another instanceof Type) {
  19. let result = this.baseType.isCompatible(another.baseType);
  20. if(result) {
  21. return true;
  22. } else if(Config.enable_type_casting) {
  23. if (this.baseType === BaseTypes.INTEGER || this.baseType === BaseTypes.REAL) {
  24. if (another.baseType === BaseTypes.INTEGER || another.baseType === BaseTypes.REAL) {
  25. return true;
  26. }
  27. }
  28. }
  29. }
  30. return false;
  31. }
  32. }