4
4
import com .compilerprogramming .ezlang .parser .AST ;
5
5
import com .compilerprogramming .ezlang .types .Scope ;
6
6
import com .compilerprogramming .ezlang .types .Symbol ;
7
- import com .compilerprogramming .ezlang .types .Type ;
7
+ import com .compilerprogramming .ezlang .types .EZType ;
8
8
import com .compilerprogramming .ezlang .types .TypeDictionary ;
9
9
10
10
import java .util .*;
@@ -17,7 +17,7 @@ public class CompiledFunction {
17
17
public BasicBlock currentBlock ;
18
18
private BasicBlock currentBreakTarget ;
19
19
private BasicBlock currentContinueTarget ;
20
- public Type . TypeFunction functionType ;
20
+ public EZType . EZTypeFunction functionType ;
21
21
public final RegisterPool registerPool ;
22
22
private final TypeDictionary typeDictionary ;
23
23
@@ -39,7 +39,7 @@ public class CompiledFunction {
39
39
40
40
public CompiledFunction (Symbol .FunctionTypeSymbol functionSymbol , TypeDictionary typeDictionary , EnumSet <Options > options ) {
41
41
AST .FuncDecl funcDecl = (AST .FuncDecl ) functionSymbol .functionDecl ;
42
- this .functionType = (Type . TypeFunction ) functionSymbol .type ;
42
+ this .functionType = (EZType . EZTypeFunction ) functionSymbol .type ;
43
43
this .registerPool = new RegisterPool ();
44
44
// Incremental SSA is an optional feature
45
45
this .issa = (options != null && options .contains (Options .ISSA )) ? new IncrementalSSABraun (this ) : new NoopIncrementalSSA ();
@@ -60,8 +60,8 @@ public CompiledFunction(Symbol.FunctionTypeSymbol functionSymbol, TypeDictionary
60
60
public CompiledFunction (Symbol .FunctionTypeSymbol functionSymbol , TypeDictionary typeDictionary ) {
61
61
this (functionSymbol ,typeDictionary ,null );
62
62
}
63
- public CompiledFunction (Type . TypeFunction functionType , TypeDictionary typeDictionary ) {
64
- this .functionType = (Type . TypeFunction ) functionType ;
63
+ public CompiledFunction (EZType . EZTypeFunction functionType , TypeDictionary typeDictionary ) {
64
+ this .functionType = (EZType . EZTypeFunction ) functionType ;
65
65
this .registerPool = new RegisterPool ();
66
66
this .issa = new NoopIncrementalSSA (); this .BID = 0 ;
67
67
this .entry = this .currentBlock = createBlock ();
@@ -325,7 +325,7 @@ private boolean compileExpr(AST.Expr expr) {
325
325
private boolean compileCallExpr (AST .CallExpr callExpr ) {
326
326
compileExpr (callExpr .callee );
327
327
var callee = pop ();
328
- Type . TypeFunction calleeType = null ;
328
+ EZType . EZTypeFunction calleeType = null ;
329
329
if (callee instanceof Operand .LocalFunctionOperand functionOperand )
330
330
calleeType = functionOperand .functionType ;
331
331
else throw new CompilerException ("Cannot call a non function type" );
@@ -347,28 +347,28 @@ private boolean compileCallExpr(AST.CallExpr callExpr) {
347
347
for (int i = 0 ; i < args .size (); i ++)
348
348
pop ();
349
349
Operand .TempRegisterOperand ret = null ;
350
- if (callExpr .callee .type instanceof Type . TypeFunction tf &&
351
- !(tf .returnType instanceof Type . TypeVoid )) {
350
+ if (callExpr .callee .type instanceof EZType . EZTypeFunction tf &&
351
+ !(tf .returnType instanceof EZType . EZTypeVoid )) {
352
352
ret = createTemp (tf .returnType );
353
353
}
354
354
codeCall (returnStackPos , ret , calleeType , args .toArray (new Operand .RegisterOperand [args .size ()]));
355
355
return false ;
356
356
}
357
357
358
- private Type . TypeStruct getStructType (Type t ) {
359
- if (t instanceof Type . TypeStruct typeStruct ) {
358
+ private EZType . EZTypeStruct getStructType (EZType t ) {
359
+ if (t instanceof EZType . EZTypeStruct typeStruct ) {
360
360
return typeStruct ;
361
361
}
362
- else if (t instanceof Type . TypeNullable ptr &&
363
- ptr .baseType instanceof Type . TypeStruct typeStruct ) {
362
+ else if (t instanceof EZType . EZTypeNullable ptr &&
363
+ ptr .baseType instanceof EZType . EZTypeStruct typeStruct ) {
364
364
return typeStruct ;
365
365
}
366
366
else
367
367
throw new CompilerException ("Unexpected type: " + t );
368
368
}
369
369
370
370
private boolean compileFieldExpr (AST .GetFieldExpr fieldExpr ) {
371
- Type . TypeStruct typeStruct = getStructType (fieldExpr .object .type );
371
+ EZType . EZTypeStruct typeStruct = getStructType (fieldExpr .object .type );
372
372
int fieldIndex = typeStruct .getFieldIndex (fieldExpr .fieldName );
373
373
if (fieldIndex < 0 )
374
374
throw new CompilerException ("Field " + fieldExpr .fieldName + " not found" );
@@ -391,7 +391,7 @@ private boolean compileArrayIndexExpr(AST.ArrayLoadExpr arrayIndexExpr) {
391
391
}
392
392
393
393
private boolean compileSetFieldExpr (AST .SetFieldExpr setFieldExpr ) {
394
- Type . TypeStruct structType = (Type . TypeStruct ) setFieldExpr .object .type ;
394
+ EZType . EZTypeStruct structType = (EZType . EZTypeStruct ) setFieldExpr .object .type ;
395
395
int fieldIndex = structType .getFieldIndex (setFieldExpr .fieldName );
396
396
if (fieldIndex == -1 )
397
397
throw new CompilerException ("Field " + setFieldExpr .fieldName + " not found in struct " + structType .name );
@@ -441,7 +441,7 @@ private boolean compileInitExpr(AST.InitExpr initExpr) {
441
441
}
442
442
443
443
private boolean compileSymbolExpr (AST .NameExpr symbolExpr ) {
444
- if (symbolExpr .type instanceof Type . TypeFunction functionType )
444
+ if (symbolExpr .type instanceof EZType . EZTypeFunction functionType )
445
445
pushOperand (new Operand .LocalFunctionOperand (functionType ));
446
446
else {
447
447
Symbol .VarSymbol varSymbol = (Symbol .VarSymbol ) symbolExpr .symbol ;
@@ -549,29 +549,29 @@ private boolean compileUnaryExpr(AST.UnaryExpr unaryExpr) {
549
549
}
550
550
551
551
private boolean compileConstantExpr (AST .LiteralExpr constantExpr ) {
552
- if (constantExpr .type instanceof Type . TypeInteger )
552
+ if (constantExpr .type instanceof EZType . EZTypeInteger )
553
553
pushConstant (constantExpr .value .num .intValue (), constantExpr .type );
554
- else if (constantExpr .type instanceof Type . TypeNull )
554
+ else if (constantExpr .type instanceof EZType . EZTypeNull )
555
555
pushNullConstant (constantExpr .type );
556
556
else throw new CompilerException ("Invalid constant type" );
557
557
return false ;
558
558
}
559
559
560
- private void pushConstant (long value , Type type ) {
560
+ private void pushConstant (long value , EZType type ) {
561
561
pushOperand (new Operand .ConstantOperand (value , type ));
562
562
}
563
563
564
- private void pushNullConstant (Type type ) {
564
+ private void pushNullConstant (EZType type ) {
565
565
pushOperand (new Operand .NullConstantOperand (type ));
566
566
}
567
567
568
- private Operand .TempRegisterOperand createTemp (Type type ) {
568
+ private Operand .TempRegisterOperand createTemp (EZType type ) {
569
569
var tempRegister = new Operand .TempRegisterOperand (registerPool .newTempReg (type ));
570
570
pushOperand (tempRegister );
571
571
return tempRegister ;
572
572
}
573
573
574
- Type typeOfOperand (Operand operand ) {
574
+ EZType typeOfOperand (Operand operand ) {
575
575
if (operand instanceof Operand .ConstantOperand constant )
576
576
return constant .type ;
577
577
else if (operand instanceof Operand .NullConstantOperand nullConstantOperand )
@@ -582,7 +582,7 @@ else if (operand instanceof Operand.RegisterOperand registerOperand)
582
582
}
583
583
584
584
private Operand .TempRegisterOperand createTempAndMove (Operand src ) {
585
- Type type = typeOfOperand (src );
585
+ EZType type = typeOfOperand (src );
586
586
var temp = createTemp (type );
587
587
codeMove (src , temp );
588
588
return temp ;
@@ -644,16 +644,16 @@ else if (indexed instanceof Operand.LoadFieldOperand loadFieldOperand)
644
644
codeMove (value , indexed );
645
645
}
646
646
647
- private void codeNew (Type type , AST .Expr len , AST .Expr initVal ) {
648
- if (type instanceof Type . TypeArray typeArray )
647
+ private void codeNew (EZType type , AST .Expr len , AST .Expr initVal ) {
648
+ if (type instanceof EZType . EZTypeArray typeArray )
649
649
codeNewArray (typeArray , len , initVal );
650
- else if (type instanceof Type . TypeStruct typeStruct )
650
+ else if (type instanceof EZType . EZTypeStruct typeStruct )
651
651
codeNewStruct (typeStruct );
652
652
else
653
653
throw new CompilerException ("Unexpected type: " + type );
654
654
}
655
655
656
- private void codeNewArray (Type . TypeArray typeArray , AST .Expr len , AST .Expr initVal ) {
656
+ private void codeNewArray (EZType . EZTypeArray typeArray , AST .Expr len , AST .Expr initVal ) {
657
657
var temp = createTemp (typeArray );
658
658
Operand lenOperand = null ;
659
659
Operand initValOperand = null ;
@@ -685,7 +685,7 @@ private void codeNewArray(Type.TypeArray typeArray, AST.Expr len, AST.Expr initV
685
685
code (insn );
686
686
}
687
687
688
- private void codeNewStruct (Type . TypeStruct typeStruct ) {
688
+ private void codeNewStruct (EZType . EZTypeStruct typeStruct ) {
689
689
var temp = createTemp (typeStruct );
690
690
var target = (Operand .RegisterOperand ) issa .write (temp );
691
691
var insn = new Instruction .NewStruct (typeStruct , target );
@@ -729,7 +729,7 @@ private void codeCBR(BasicBlock block, Operand condition, BasicBlock trueBlock,
729
729
730
730
private void codeCall (int newBase ,
731
731
Operand .RegisterOperand targetOperand ,
732
- Type . TypeFunction calleeType ,
732
+ EZType . EZTypeFunction calleeType ,
733
733
Operand .RegisterOperand ...arguments ) {
734
734
if (targetOperand != null )
735
735
targetOperand = (Operand .RegisterOperand ) issa .write (targetOperand );
0 commit comments