44import com .compilerprogramming .ezlang .parser .AST ;
55import com .compilerprogramming .ezlang .types .Scope ;
66import com .compilerprogramming .ezlang .types .Symbol ;
7- import com .compilerprogramming .ezlang .types .Type ;
7+ import com .compilerprogramming .ezlang .types .EZType ;
88import com .compilerprogramming .ezlang .types .TypeDictionary ;
99
1010import java .util .*;
@@ -17,7 +17,7 @@ public class CompiledFunction {
1717 public BasicBlock currentBlock ;
1818 private BasicBlock currentBreakTarget ;
1919 private BasicBlock currentContinueTarget ;
20- public Type . TypeFunction functionType ;
20+ public EZType . EZTypeFunction functionType ;
2121 public final RegisterPool registerPool ;
2222 private final TypeDictionary typeDictionary ;
2323
@@ -39,7 +39,7 @@ public class CompiledFunction {
3939
4040 public CompiledFunction (Symbol .FunctionTypeSymbol functionSymbol , TypeDictionary typeDictionary , EnumSet <Options > options ) {
4141 AST .FuncDecl funcDecl = (AST .FuncDecl ) functionSymbol .functionDecl ;
42- this .functionType = (Type . TypeFunction ) functionSymbol .type ;
42+ this .functionType = (EZType . EZTypeFunction ) functionSymbol .type ;
4343 this .registerPool = new RegisterPool ();
4444 // Incremental SSA is an optional feature
4545 this .issa = (options != null && options .contains (Options .ISSA )) ? new IncrementalSSABraun (this ) : new NoopIncrementalSSA ();
@@ -60,8 +60,8 @@ public CompiledFunction(Symbol.FunctionTypeSymbol functionSymbol, TypeDictionary
6060 public CompiledFunction (Symbol .FunctionTypeSymbol functionSymbol , TypeDictionary typeDictionary ) {
6161 this (functionSymbol ,typeDictionary ,null );
6262 }
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 ;
6565 this .registerPool = new RegisterPool ();
6666 this .issa = new NoopIncrementalSSA (); this .BID = 0 ;
6767 this .entry = this .currentBlock = createBlock ();
@@ -325,7 +325,7 @@ private boolean compileExpr(AST.Expr expr) {
325325 private boolean compileCallExpr (AST .CallExpr callExpr ) {
326326 compileExpr (callExpr .callee );
327327 var callee = pop ();
328- Type . TypeFunction calleeType = null ;
328+ EZType . EZTypeFunction calleeType = null ;
329329 if (callee instanceof Operand .LocalFunctionOperand functionOperand )
330330 calleeType = functionOperand .functionType ;
331331 else throw new CompilerException ("Cannot call a non function type" );
@@ -347,28 +347,28 @@ private boolean compileCallExpr(AST.CallExpr callExpr) {
347347 for (int i = 0 ; i < args .size (); i ++)
348348 pop ();
349349 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 )) {
352352 ret = createTemp (tf .returnType );
353353 }
354354 codeCall (returnStackPos , ret , calleeType , args .toArray (new Operand .RegisterOperand [args .size ()]));
355355 return false ;
356356 }
357357
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 ) {
360360 return typeStruct ;
361361 }
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 ) {
364364 return typeStruct ;
365365 }
366366 else
367367 throw new CompilerException ("Unexpected type: " + t );
368368 }
369369
370370 private boolean compileFieldExpr (AST .GetFieldExpr fieldExpr ) {
371- Type . TypeStruct typeStruct = getStructType (fieldExpr .object .type );
371+ EZType . EZTypeStruct typeStruct = getStructType (fieldExpr .object .type );
372372 int fieldIndex = typeStruct .getFieldIndex (fieldExpr .fieldName );
373373 if (fieldIndex < 0 )
374374 throw new CompilerException ("Field " + fieldExpr .fieldName + " not found" );
@@ -391,7 +391,7 @@ private boolean compileArrayIndexExpr(AST.ArrayLoadExpr arrayIndexExpr) {
391391 }
392392
393393 private boolean compileSetFieldExpr (AST .SetFieldExpr setFieldExpr ) {
394- Type . TypeStruct structType = (Type . TypeStruct ) setFieldExpr .object .type ;
394+ EZType . EZTypeStruct structType = (EZType . EZTypeStruct ) setFieldExpr .object .type ;
395395 int fieldIndex = structType .getFieldIndex (setFieldExpr .fieldName );
396396 if (fieldIndex == -1 )
397397 throw new CompilerException ("Field " + setFieldExpr .fieldName + " not found in struct " + structType .name );
@@ -441,7 +441,7 @@ private boolean compileInitExpr(AST.InitExpr initExpr) {
441441 }
442442
443443 private boolean compileSymbolExpr (AST .NameExpr symbolExpr ) {
444- if (symbolExpr .type instanceof Type . TypeFunction functionType )
444+ if (symbolExpr .type instanceof EZType . EZTypeFunction functionType )
445445 pushOperand (new Operand .LocalFunctionOperand (functionType ));
446446 else {
447447 Symbol .VarSymbol varSymbol = (Symbol .VarSymbol ) symbolExpr .symbol ;
@@ -549,29 +549,29 @@ private boolean compileUnaryExpr(AST.UnaryExpr unaryExpr) {
549549 }
550550
551551 private boolean compileConstantExpr (AST .LiteralExpr constantExpr ) {
552- if (constantExpr .type instanceof Type . TypeInteger )
552+ if (constantExpr .type instanceof EZType . EZTypeInteger )
553553 pushConstant (constantExpr .value .num .intValue (), constantExpr .type );
554- else if (constantExpr .type instanceof Type . TypeNull )
554+ else if (constantExpr .type instanceof EZType . EZTypeNull )
555555 pushNullConstant (constantExpr .type );
556556 else throw new CompilerException ("Invalid constant type" );
557557 return false ;
558558 }
559559
560- private void pushConstant (long value , Type type ) {
560+ private void pushConstant (long value , EZType type ) {
561561 pushOperand (new Operand .ConstantOperand (value , type ));
562562 }
563563
564- private void pushNullConstant (Type type ) {
564+ private void pushNullConstant (EZType type ) {
565565 pushOperand (new Operand .NullConstantOperand (type ));
566566 }
567567
568- private Operand .TempRegisterOperand createTemp (Type type ) {
568+ private Operand .TempRegisterOperand createTemp (EZType type ) {
569569 var tempRegister = new Operand .TempRegisterOperand (registerPool .newTempReg (type ));
570570 pushOperand (tempRegister );
571571 return tempRegister ;
572572 }
573573
574- Type typeOfOperand (Operand operand ) {
574+ EZType typeOfOperand (Operand operand ) {
575575 if (operand instanceof Operand .ConstantOperand constant )
576576 return constant .type ;
577577 else if (operand instanceof Operand .NullConstantOperand nullConstantOperand )
@@ -582,7 +582,7 @@ else if (operand instanceof Operand.RegisterOperand registerOperand)
582582 }
583583
584584 private Operand .TempRegisterOperand createTempAndMove (Operand src ) {
585- Type type = typeOfOperand (src );
585+ EZType type = typeOfOperand (src );
586586 var temp = createTemp (type );
587587 codeMove (src , temp );
588588 return temp ;
@@ -644,16 +644,16 @@ else if (indexed instanceof Operand.LoadFieldOperand loadFieldOperand)
644644 codeMove (value , indexed );
645645 }
646646
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 )
649649 codeNewArray (typeArray , len , initVal );
650- else if (type instanceof Type . TypeStruct typeStruct )
650+ else if (type instanceof EZType . EZTypeStruct typeStruct )
651651 codeNewStruct (typeStruct );
652652 else
653653 throw new CompilerException ("Unexpected type: " + type );
654654 }
655655
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 ) {
657657 var temp = createTemp (typeArray );
658658 Operand lenOperand = null ;
659659 Operand initValOperand = null ;
@@ -685,7 +685,7 @@ private void codeNewArray(Type.TypeArray typeArray, AST.Expr len, AST.Expr initV
685685 code (insn );
686686 }
687687
688- private void codeNewStruct (Type . TypeStruct typeStruct ) {
688+ private void codeNewStruct (EZType . EZTypeStruct typeStruct ) {
689689 var temp = createTemp (typeStruct );
690690 var target = (Operand .RegisterOperand ) issa .write (temp );
691691 var insn = new Instruction .NewStruct (typeStruct , target );
@@ -729,7 +729,7 @@ private void codeCBR(BasicBlock block, Operand condition, BasicBlock trueBlock,
729729
730730 private void codeCall (int newBase ,
731731 Operand .RegisterOperand targetOperand ,
732- Type . TypeFunction calleeType ,
732+ EZType . EZTypeFunction calleeType ,
733733 Operand .RegisterOperand ...arguments ) {
734734 if (targetOperand != null )
735735 targetOperand = (Operand .RegisterOperand ) issa .write (targetOperand );
0 commit comments