This commit is contained in:
Irmen de Jong 2021-10-19 01:12:28 +02:00
parent 40bf117497
commit 502bf90007
5 changed files with 11 additions and 9 deletions

View File

@ -280,6 +280,8 @@ private fun processAst(programAst: Program, errors: IErrorReporter, compilerOpti
programAst.checkIdentifiers(errors, compilerOptions) programAst.checkIdentifiers(errors, compilerOptions)
errors.report() errors.report()
// TODO: turning char literals into UBYTEs via an encoding should really happen in code gen - but for that we'd need DataType.CHAR // TODO: turning char literals into UBYTEs via an encoding should really happen in code gen - but for that we'd need DataType.CHAR
// NOTE: we will then lose the opportunity to do constant-folding on any expression containing a char literal, but how often will those occur?
// Also they might be optimized away eventually in codegen or by the assembler even
programAst.charLiteralsToUByteLiterals(errors, compilerOptions.compTarget) programAst.charLiteralsToUByteLiterals(errors, compilerOptions.compTarget)
errors.report() errors.report()
programAst.constantFold(errors, compilerOptions.compTarget) programAst.constantFold(errors, compilerOptions.compTarget)

View File

@ -132,7 +132,7 @@ class ModuleImporter(private val program: Program,
} else { } else {
val dropCurDir = if(sourcePaths.isNotEmpty() && sourcePaths[0].name == ".") 1 else 0 val dropCurDir = if(sourcePaths.isNotEmpty() && sourcePaths[0].name == ".") 1 else 0
sourcePaths.drop(dropCurDir) + sourcePaths.drop(dropCurDir) +
// FIXME: won't work until Prog8Parser is fixed s.t. it fully initialzes the modules it returns // TODO: won't work until Prog8Parser is fixed s.t. it fully initializes the modules it returns. ??? (what won't work?)
listOf(Path(importingModule.position.file).parent ?: Path("")) + listOf(Path(importingModule.position.file).parent ?: Path("")) +
listOf(Path(".", "prog8lib")) listOf(Path(".", "prog8lib"))
} }

View File

@ -2,7 +2,7 @@
main { main {
str myBar = "main.bar" str myBar = "main.bar"
;foo_bar: ;foo_bar:
; %asminclude "foo_bar.asm" ; FIXME: should be accessible from inside start() but give assembler error. See github issue #62 ; %asminclude "foo_bar.asm" ; TODO: should be accessible from inside start() but give assembler error. See github issue #62
sub start() { sub start() {
txt.print(myBar) txt.print(myBar)
txt.print(&foo_bar) txt.print(&foo_bar)

View File

@ -301,7 +301,7 @@ class TypecastExpression(var expression: Expression, var type: DataType, val imp
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent) override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
override fun referencesIdentifier(vararg scopedName: String) = expression.referencesIdentifier(*scopedName) override fun referencesIdentifier(vararg scopedName: String) = expression.referencesIdentifier(*scopedName)
override fun inferType(program: Program): InferredTypes.InferredType = InferredTypes.knownFor(type) override fun inferType(program: Program) = InferredTypes.knownFor(type)
override fun constValue(program: Program): NumericLiteralValue? { override fun constValue(program: Program): NumericLiteralValue? {
val cv = expression.constValue(program) ?: return null val cv = expression.constValue(program) ?: return null
val cast = cv.cast(type) val cast = cv.cast(type)
@ -334,7 +334,7 @@ data class AddressOf(var identifier: IdentifierReference, override val position:
override fun constValue(program: Program): NumericLiteralValue? = null override fun constValue(program: Program): NumericLiteralValue? = null
override fun referencesIdentifier(vararg scopedName: String) = false override fun referencesIdentifier(vararg scopedName: String) = false
override fun inferType(program: Program): InferredTypes.InferredType = InferredTypes.knownFor(DataType.UWORD) override fun inferType(program: Program) = InferredTypes.knownFor(DataType.UWORD)
override fun accept(visitor: IAstVisitor) = visitor.visit(this) override fun accept(visitor: IAstVisitor) = visitor.visit(this)
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent) override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
} }
@ -359,7 +359,7 @@ class DirectMemoryRead(var addressExpression: Expression, override val position:
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent) override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
override fun referencesIdentifier(vararg scopedName: String) = false override fun referencesIdentifier(vararg scopedName: String) = false
override fun inferType(program: Program): InferredTypes.InferredType = InferredTypes.knownFor(DataType.UBYTE) override fun inferType(program: Program) = InferredTypes.knownFor(DataType.UBYTE)
override fun constValue(program: Program): NumericLiteralValue? = null override fun constValue(program: Program): NumericLiteralValue? = null
override fun toString(): String { override fun toString(): String {
@ -422,7 +422,7 @@ class NumericLiteralValue(val type: DataType, // only numerical types allowed
override fun toString(): String = "NumericLiteral(${type.name}:$number)" override fun toString(): String = "NumericLiteral(${type.name}:$number)"
override fun inferType(program: Program): InferredTypes.InferredType = InferredTypes.knownFor(type) override fun inferType(program: Program) = InferredTypes.knownFor(type)
override fun hashCode(): Int = Objects.hash(type, number) override fun hashCode(): Int = Objects.hash(type, number)
@ -518,7 +518,7 @@ class CharLiteral(val value: Char,
override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent) override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent)
override fun toString(): String = "'${escape(value.toString())}'" override fun toString(): String = "'${escape(value.toString())}'"
override fun inferType(program: Program): InferredTypes.InferredType = InferredTypes.knownFor(DataType.UNDEFINED) // FIXME: CharLiteral.inferType override fun inferType(program: Program) = InferredTypes.knownFor(DataType.UBYTE)
operator fun compareTo(other: CharLiteral): Int = value.compareTo(other.value) operator fun compareTo(other: CharLiteral): Int = value.compareTo(other.value)
override fun hashCode(): Int = Objects.hash(value, altEncoding) override fun hashCode(): Int = Objects.hash(value, altEncoding)
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
@ -550,7 +550,7 @@ class StringLiteralValue(val value: String,
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent) override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
override fun toString(): String = "'${escape(value)}'" override fun toString(): String = "'${escape(value)}'"
override fun inferType(program: Program): InferredTypes.InferredType = InferredTypes.knownFor(DataType.STR) override fun inferType(program: Program) = InferredTypes.knownFor(DataType.STR)
operator fun compareTo(other: StringLiteralValue): Int = value.compareTo(other.value) operator fun compareTo(other: StringLiteralValue): Int = value.compareTo(other.value)
override fun hashCode(): Int = Objects.hash(value, altEncoding) override fun hashCode(): Int = Objects.hash(value, altEncoding)
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {

View File

@ -14,7 +14,7 @@ Blocked by Commander-x16 v39 release
Future Future
^^^^^^ ^^^^^^
- get rid of all TODO's and FIXME's in the code - get rid of all TODO's in the code
- improve testability further, add more tests, address more questions/issues from the testability discussions. - improve testability further, add more tests, address more questions/issues from the testability discussions.
- replace certain uses of inferredType.getOr(DataType.UNDEFINED) by i.getOrElse({ errorhandler }) - replace certain uses of inferredType.getOr(DataType.UNDEFINED) by i.getOrElse({ errorhandler })
- see if we can remove more "[InferredType].getOr(DataType.UNDEFINED)" - see if we can remove more "[InferredType].getOr(DataType.UNDEFINED)"