Skip to content

Commit

Permalink
New type names
Browse files Browse the repository at this point in the history
"Int" is now "Integer" and "Bool" is "Boolean".
  • Loading branch information
BenediktMagnus committed Mar 7, 2024
1 parent f07480f commit 4162fe3
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion examples/everything/everything.ph
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Everything;

import Standard.Io;

function add (a: Int, b: Int): Int
function add (a: Integer, b: Integer): Integer
{
let result := a + b;

Expand Down
2 changes: 1 addition & 1 deletion examples/fibonacci/fibonacci.ph
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Fibonacci;
import Standard.Io;
import Standard.Conversion;

function calculateFibonacci (n: Int): Int
function calculateFibonacci (n: Integer): Integer
{
if n < 2
{
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/myModule.ph
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Standard.Io;
module ModulesExample.MyModule;

constant helloFromModule: String := 'Hello got from MyModule!';
variable sayHelloCounter: Int := 0;
variable sayHelloCounter: Integer := 0;

function getHello (): String
{
Expand Down
8 changes: 4 additions & 4 deletions src/connector/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,11 @@ export class Connector
{
const condition = this.connectExpression(ifStatement.condition, context);

if (!condition.type.equals(BuildInTypes.bool))
if (!condition.type.equals(BuildInTypes.boolean))
{
this.diagnostic.throw(
new Diagnostic.Error(
'The return type of the condition in an if statement must be Bool.',
'The return type of the condition in an if statement must be Boolean.',
Diagnostic.Codes.UnexpectedNonBooleanExpressionInIfStatementError,
ifStatement.condition.token
)
Expand Down Expand Up @@ -874,11 +874,11 @@ export class Connector
{
const condition = this.connectExpression(whileStatement.condition, context);

if (!condition.type.equals(BuildInTypes.bool))
if (!condition.type.equals(BuildInTypes.boolean))
{
this.diagnostic.throw(
new Diagnostic.Error(
'The return type of the condition in an while statement must be Bool.',
'The return type of the condition in an while statement must be Boolean.',
Diagnostic.Codes.UnexpectedNonBooleanExpressionInWhileStatementError,
whileStatement.condition.token
)
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/buildInFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class BuildInFunctions
{
public static readonly stringsAreEqual = new SemanticSymbols.Function(
Namespace.constructFromStrings('Standard', 'String', 'stringsAreEqual'),
BuildInTypes.bool,
BuildInTypes.boolean,
[
new SemanticSymbols.FunctionParameter(
Namespace.constructFromStrings('Standard', 'String', 'stringsAreEqual', 'string1'),
Expand All @@ -36,7 +36,7 @@ export abstract class BuildInFunctions
[
new SemanticSymbols.FunctionParameter(
Namespace.constructFromStrings('Standard', 'Memory', 'allocate', 'size'),
BuildInTypes.int // FIXME: This should be UInt.
BuildInTypes.integer // FIXME: This should be UInt.
)
],
null,
Expand Down
40 changes: 20 additions & 20 deletions src/definitions/buildInOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ import { UnarySemanticOperator } from '../connector/semanticOperators/unarySeman

export abstract class BuildInOperators
{
public static readonly unaryIntAddition = new UnarySemanticOperator(SemanticOperatorKind.Addition, BuildInTypes.int, BuildInTypes.int);
public static readonly unaryIntSubtraction = new UnarySemanticOperator(SemanticOperatorKind.Subtraction, BuildInTypes.int, BuildInTypes.int);
public static readonly unaryIntAddition = new UnarySemanticOperator(SemanticOperatorKind.Addition, BuildInTypes.integer, BuildInTypes.integer);
public static readonly unaryIntSubtraction = new UnarySemanticOperator(SemanticOperatorKind.Subtraction, BuildInTypes.integer, BuildInTypes.integer);

public static readonly unaryIntNot = new UnarySemanticOperator(SemanticOperatorKind.Not, BuildInTypes.int, BuildInTypes.int);
public static readonly unaryIntNot = new UnarySemanticOperator(SemanticOperatorKind.Not, BuildInTypes.integer, BuildInTypes.integer);

public static readonly unaryBoolNot = new UnarySemanticOperator(SemanticOperatorKind.Not, BuildInTypes.bool, BuildInTypes.bool);
public static readonly unaryBoolNot = new UnarySemanticOperator(SemanticOperatorKind.Not, BuildInTypes.boolean, BuildInTypes.boolean);

public static readonly binaryIntAddition = new BinarySemanticOperator(SemanticOperatorKind.Addition, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntSubtraction = new BinarySemanticOperator(SemanticOperatorKind.Subtraction, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntMultiplication = new BinarySemanticOperator(SemanticOperatorKind.Multiplication, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntDivision = new BinarySemanticOperator(SemanticOperatorKind.Division, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntModulo = new BinarySemanticOperator(SemanticOperatorKind.Modulo, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntAddition = new BinarySemanticOperator(SemanticOperatorKind.Addition, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);
public static readonly binaryIntSubtraction = new BinarySemanticOperator(SemanticOperatorKind.Subtraction, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);
public static readonly binaryIntMultiplication = new BinarySemanticOperator(SemanticOperatorKind.Multiplication, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);
public static readonly binaryIntDivision = new BinarySemanticOperator(SemanticOperatorKind.Division, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);
public static readonly binaryIntModulo = new BinarySemanticOperator(SemanticOperatorKind.Modulo, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);

public static readonly binaryIntAnd = new BinarySemanticOperator(SemanticOperatorKind.And, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntOr = new BinarySemanticOperator(SemanticOperatorKind.Or, BuildInTypes.int, BuildInTypes.int, BuildInTypes.int);
public static readonly binaryIntAnd = new BinarySemanticOperator(SemanticOperatorKind.And, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);
public static readonly binaryIntOr = new BinarySemanticOperator(SemanticOperatorKind.Or, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.integer);

public static readonly binaryBoolAnd = new BinarySemanticOperator(SemanticOperatorKind.And, BuildInTypes.bool, BuildInTypes.bool, BuildInTypes.bool);
public static readonly binaryBoolOr = new BinarySemanticOperator(SemanticOperatorKind.Or, BuildInTypes.bool, BuildInTypes.bool, BuildInTypes.bool);
public static readonly binaryBoolAnd = new BinarySemanticOperator(SemanticOperatorKind.And, BuildInTypes.boolean, BuildInTypes.boolean, BuildInTypes.boolean);
public static readonly binaryBoolOr = new BinarySemanticOperator(SemanticOperatorKind.Or, BuildInTypes.boolean, BuildInTypes.boolean, BuildInTypes.boolean);

public static readonly binaryIntEqual = new BinarySemanticOperator(SemanticOperatorKind.Equal, BuildInTypes.int, BuildInTypes.int, BuildInTypes.bool);
public static readonly binaryIntNotEqual = new BinarySemanticOperator(SemanticOperatorKind.NotEqual, BuildInTypes.int, BuildInTypes.int, BuildInTypes.bool);
public static readonly binaryIntLess = new BinarySemanticOperator(SemanticOperatorKind.Less, BuildInTypes.int, BuildInTypes.int, BuildInTypes.bool);
public static readonly binaryIntGreater = new BinarySemanticOperator(SemanticOperatorKind.Greater, BuildInTypes.int, BuildInTypes.int, BuildInTypes.bool);
public static readonly binaryIntEqual = new BinarySemanticOperator(SemanticOperatorKind.Equal, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.boolean);
public static readonly binaryIntNotEqual = new BinarySemanticOperator(SemanticOperatorKind.NotEqual, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.boolean);
public static readonly binaryIntLess = new BinarySemanticOperator(SemanticOperatorKind.Less, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.boolean);
public static readonly binaryIntGreater = new BinarySemanticOperator(SemanticOperatorKind.Greater, BuildInTypes.integer, BuildInTypes.integer, BuildInTypes.boolean);

public static readonly binaryBoolEqual = new BinarySemanticOperator(SemanticOperatorKind.Equal, BuildInTypes.bool, BuildInTypes.bool, BuildInTypes.bool);
public static readonly binaryBoolNotEqual = new BinarySemanticOperator(SemanticOperatorKind.NotEqual, BuildInTypes.bool, BuildInTypes.bool, BuildInTypes.bool);
public static readonly binaryBoolEqual = new BinarySemanticOperator(SemanticOperatorKind.Equal, BuildInTypes.boolean, BuildInTypes.boolean, BuildInTypes.boolean);
public static readonly binaryBoolNotEqual = new BinarySemanticOperator(SemanticOperatorKind.NotEqual, BuildInTypes.boolean, BuildInTypes.boolean, BuildInTypes.boolean);

public static readonly binaryStringEqual = new BinarySemanticOperator(SemanticOperatorKind.Equal, BuildInTypes.string, BuildInTypes.string, BuildInTypes.bool);
public static readonly binaryStringEqual = new BinarySemanticOperator(SemanticOperatorKind.Equal, BuildInTypes.string, BuildInTypes.string, BuildInTypes.boolean);

private static unaryOperators: UnarySemanticOperator[] = [
BuildInOperators.unaryIntAddition,
Expand Down
16 changes: 8 additions & 8 deletions src/definitions/buildInTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ export abstract class BuildInTypes
{
public static readonly noType = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'NoType'), []);
// TODO: Ints are often misused for UInts. Should be corrected:
public static readonly int = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'Int'), []);
public static readonly bool = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'Bool'), []);
public static readonly integer = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'Integer'), []);
public static readonly boolean = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'Boolean'), []);
public static readonly string = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'String'), []);
public static readonly pointer = new SemanticSymbols.ConcreteType(Namespace.constructFromStrings('Phosphor', 'Pointer'), []);

public static getTypeByName (name: string): SemanticSymbols.Type|null
{
switch (name)
{
case this.int.namespace.baseName:
return this.int;
case this.integer.namespace.baseName:
return this.integer;
case this.string.namespace.baseName:
return this.string;
case this.bool.namespace.baseName:
return this.bool;
case this.boolean.namespace.baseName:
return this.boolean;
case this.pointer.namespace.baseName:
return this.pointer;
default:
Expand All @@ -33,12 +33,12 @@ export abstract class BuildInTypes
switch (tokenKind)
{
case TokenKind.IntegerToken:
return this.int;
return this.integer;
case TokenKind.StringToken:
return this.string;
case TokenKind.TrueKeyword:
case TokenKind.FalseKeyword:
return this.bool;
return this.boolean;
default:
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/intermediateLowerer/intermediateLowerer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IntermediateSize } from './intermediateSize';
import { IntermediateSymbolKind } from './intermediateSymbolKind';
import { SemanticKind } from '../connector/semanticKind';

/* TODO: When (if?) the Bool type size is changed from Int8 to UInt8 (i.e. unsigned), the value of true must be changed from -1 to 255.
/* TODO: When (if?) the Boolean type size is changed from Int8 to UInt8 (i.e. unsigned), the value of true must be changed from -1 to 255.
-> Should we rather introduce a boolean type in the intermediate language? */
// TODO: Could there be a better name than "lowerer" for the transformation into intermediate code?

Expand Down Expand Up @@ -181,9 +181,9 @@ export class IntermediateLowerer
{
switch (type)
{
case BuildInTypes.int:
case BuildInTypes.integer:
return IntermediateSize.Native;
case BuildInTypes.bool:
case BuildInTypes.boolean:
return IntermediateSize.Int8;
case BuildInTypes.noType:
return IntermediateSize.Void;
Expand Down Expand Up @@ -668,13 +668,13 @@ export class IntermediateLowerer

switch (literalExpression.type)
{
case BuildInTypes.int:
case BuildInTypes.integer:
{
literalOrConstant = new IntermediateSymbols.Literal(literalExpression.value, this.typeToSize(literalExpression.type));

break;
}
case BuildInTypes.bool:
case BuildInTypes.boolean:
{
let value: string;

Expand All @@ -689,7 +689,7 @@ export class IntermediateLowerer
}
else
{
throw new Error(`Intermediate Lowerer error: Unknown Bool value of "${literalExpression.value}"`);
throw new Error(`Intermediate Lowerer error: Unknown Boolean value of "${literalExpression.value}"`);
}

literalOrConstant = new IntermediateSymbols.Literal(value, this.typeToSize(literalExpression.type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class SizeOfExpressionLoweredNode
{
this.kind = SemanticKind.SizeOfExpression;

this.type = BuildInTypes.int; // FIXME: Must be UInt.
this.type = BuildInTypes.integer; // FIXME: Must be UInt.

this.parameter = parameter;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/endToEnd/sourceToIntermediate/inputs/bitwise.ph
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Bitwise;

function testNot (a: Int): Int
function testNot (a: Integer): Integer
{
return !a;
}

function testAnd (a: Int, b: Int): Int
function testAnd (a: Integer, b: Integer): Integer
{
return a & b;
}

function testOr (a: Int, b: Int): Int
function testOr (a: Integer, b: Integer): Integer
{
return a | b;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/endToEnd/sourceToIntermediate/inputs/functions.ph
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Functions;

function add (a: Int, b: Int): Int
function add (a: Integer, b: Integer): Integer
{
let result := a + b;

return result;
}

function testAdd (): Int
function testAdd (): Integer
{
let sum := add(1, 2);

Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/sourceToIntermediate/inputs/ifElse.ph
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module IfElse;

function testIfElse (): Bool
function testIfElse (): Boolean
{
if 2 = 2
{
Expand Down
14 changes: 7 additions & 7 deletions tests/endToEnd/sourceToIntermediate/inputs/logic.ph
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
module Logic;

function testNot (a: Bool): Bool
function testNot (a: Boolean): Boolean
{
return !a;
}

function testAnd (a: Bool, b: Bool): Bool
function testAnd (a: Boolean, b: Boolean): Boolean
{
return a & b;
}

function testOr (a: Bool, b: Bool): Bool
function testOr (a: Boolean, b: Boolean): Boolean
{
return a | b;
}

function testEqual (a: Int, b: Int): Bool
function testEqual (a: Integer, b: Integer): Boolean
{
return a = b;
}

function testNotEqual (a: Int, b: Int): Bool
function testNotEqual (a: Integer, b: Integer): Boolean
{
return a != b;
}

function testLess (a: Int, b: Int): Bool
function testLess (a: Integer, b: Integer): Boolean
{
return a < b;
}

function testGreater (a: Int, b: Int): Bool
function testGreater (a: Integer, b: Integer): Boolean
{
return a > b;
}
Expand Down
14 changes: 7 additions & 7 deletions tests/endToEnd/sourceToIntermediate/inputs/math.ph
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
module Math;

function testUnaryPlus (a: Int): Int
function testUnaryPlus (a: Integer): Integer
{
return +a;
}

function testUnaryMinus (a: Int): Int
function testUnaryMinus (a: Integer): Integer
{
return -a;
}

function testAddition (a: Int, b: Int): Int
function testAddition (a: Integer, b: Integer): Integer
{
return a + b;
}

function testSubtraction (a: Int, b: Int): Int
function testSubtraction (a: Integer, b: Integer): Integer
{
return a - b;
}

function testMultiplication (a: Int, b: Int): Int
function testMultiplication (a: Integer, b: Integer): Integer
{
return a * b;
}

function testDivision (a: Int, b: Int): Int
function testDivision (a: Integer, b: Integer): Integer
{
return a / b;
}

function testModulo (a: Int, b: Int): Int
function testModulo (a: Integer, b: Integer): Integer
{
return a % b;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/sourceToIntermediate/inputs/strings.ph
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Strings;

function testStringCompare (a: String, b: String): Bool
function testStringCompare (a: String, b: String): Boolean
{
return a = b;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/endToEnd/sourceToIntermediate/inputs/whileLoop.ph
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module WhileLoop;

function getMax (): Int
function getMax (): Integer
{
return 4;
}

function testWhileLoop (): Bool
function testWhileLoop (): Boolean
{
let variable counter := 0;

Expand Down
Loading

0 comments on commit 4162fe3

Please sign in to comment.