mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 16:29:21 +00:00
tweaks
This commit is contained in:
parent
9219ec539d
commit
5b9af0b5ae
@ -267,8 +267,8 @@ fun determineCompilationOptions(program: Program, compTarget: ICompilationTarget
|
|||||||
private fun processAst(program: Program, errors: IErrorReporter, compilerOptions: CompilationOptions) {
|
private fun processAst(program: Program, errors: IErrorReporter, compilerOptions: CompilationOptions) {
|
||||||
// perform initial syntax checks and processings
|
// perform initial syntax checks and processings
|
||||||
println("Processing for target ${compilerOptions.compTarget.name}...")
|
println("Processing for target ${compilerOptions.compTarget.name}...")
|
||||||
program.preprocessAst(program, errors)
|
program.preprocessAst(errors)
|
||||||
program.checkIdentifiers(errors, program, compilerOptions)
|
program.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
|
||||||
// ...but what do we gain from this? We can leave it as it is now: where a char literal is no more than syntactic sugar for an UBYTE value.
|
// ...but what do we gain from this? We can leave it as it is now: where a char literal is no more than syntactic sugar for an UBYTE value.
|
||||||
@ -283,11 +283,11 @@ private fun processAst(program: Program, errors: IErrorReporter, compilerOptions
|
|||||||
errors.report()
|
errors.report()
|
||||||
program.addTypecasts(errors, compilerOptions)
|
program.addTypecasts(errors, compilerOptions)
|
||||||
errors.report()
|
errors.report()
|
||||||
program.variousCleanups(program, errors, compilerOptions)
|
program.variousCleanups(errors, compilerOptions)
|
||||||
errors.report()
|
errors.report()
|
||||||
program.checkValid(errors, compilerOptions)
|
program.checkValid(errors, compilerOptions)
|
||||||
errors.report()
|
errors.report()
|
||||||
program.checkIdentifiers(errors, program, compilerOptions)
|
program.checkIdentifiers(errors, compilerOptions)
|
||||||
errors.report()
|
errors.report()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ private fun postprocessAst(program: Program, errors: IErrorReporter, compilerOpt
|
|||||||
program.desugaring(errors)
|
program.desugaring(errors)
|
||||||
program.addTypecasts(errors, compilerOptions)
|
program.addTypecasts(errors, compilerOptions)
|
||||||
errors.report()
|
errors.report()
|
||||||
program.variousCleanups(program, errors, compilerOptions)
|
program.variousCleanups(errors, compilerOptions)
|
||||||
val callGraph = CallGraph(program)
|
val callGraph = CallGraph(program)
|
||||||
callGraph.checkRecursiveCalls(errors)
|
callGraph.checkRecursiveCalls(errors)
|
||||||
errors.report()
|
errors.report()
|
||||||
|
@ -636,8 +636,6 @@ internal class AstChecker(private val program: Program,
|
|||||||
if(parameter==null)
|
if(parameter==null)
|
||||||
err("string var must be initialized with a string literal")
|
err("string var must be initialized with a string literal")
|
||||||
}
|
}
|
||||||
else if (decl.type==VarDeclType.VAR && decl.value !is StringLiteralValue)
|
|
||||||
err("string var can only be initialized with a string literal")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(compilerOptions.zeropage==ZeropageType.DONTUSE && decl.zeropage==ZeropageWish.REQUIRE_ZEROPAGE)
|
if(compilerOptions.zeropage==ZeropageType.DONTUSE && decl.zeropage==ZeropageWish.REQUIRE_ZEROPAGE)
|
||||||
@ -869,8 +867,15 @@ internal class AstChecker(private val program: Program,
|
|||||||
errors.err("left operand is not numeric or str", expr.left.position)
|
errors.err("left operand is not numeric or str", expr.left.position)
|
||||||
if(rightDt!in NumericDatatypes && rightDt != DataType.STR)
|
if(rightDt!in NumericDatatypes && rightDt != DataType.STR)
|
||||||
errors.err("right operand is not numeric or str", expr.right.position)
|
errors.err("right operand is not numeric or str", expr.right.position)
|
||||||
if(leftDt!=rightDt)
|
if(leftDt!=rightDt) {
|
||||||
errors.err("left and right operands aren't the same type", expr.left.position)
|
if(leftDt==DataType.STR && rightDt in IntegerDatatypes) {
|
||||||
|
// only exception allowed: str * constvalue
|
||||||
|
if(expr.right.constValue(program)!=null)
|
||||||
|
errors.err("can only use string repeat with a constant number value", expr.left.position)
|
||||||
|
} else {
|
||||||
|
errors.err("left and right operands aren't the same type", expr.left.position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(expr.operator !in ComparisonOperators) {
|
if(expr.operator !in ComparisonOperators) {
|
||||||
if (leftDt == DataType.STR && rightDt == DataType.STR || leftDt in ArrayDatatypes && rightDt in ArrayDatatypes) {
|
if (leftDt == DataType.STR && rightDt == DataType.STR || leftDt in ArrayDatatypes && rightDt in ArrayDatatypes) {
|
||||||
|
@ -77,17 +77,17 @@ internal fun Program.verifyFunctionArgTypes() {
|
|||||||
fixer.visit(this)
|
fixer.visit(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Program.preprocessAst(program: Program, errors: IErrorReporter) {
|
internal fun Program.preprocessAst(errors: IErrorReporter) {
|
||||||
val transforms = AstPreprocessor(program, errors)
|
val transforms = AstPreprocessor(this, errors)
|
||||||
transforms.visit(this)
|
transforms.visit(this)
|
||||||
var mods = transforms.applyModifications()
|
var mods = transforms.applyModifications()
|
||||||
while(mods>0)
|
while(mods>0)
|
||||||
mods = transforms.applyModifications()
|
mods = transforms.applyModifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Program.checkIdentifiers(errors: IErrorReporter, program: Program, options: CompilationOptions) {
|
internal fun Program.checkIdentifiers(errors: IErrorReporter, options: CompilationOptions) {
|
||||||
|
|
||||||
val checker2 = AstIdentifiersChecker(errors, program, options.compTarget)
|
val checker2 = AstIdentifiersChecker(errors, this, options.compTarget)
|
||||||
checker2.visit(this)
|
checker2.visit(this)
|
||||||
|
|
||||||
if(errors.noErrors()) {
|
if(errors.noErrors()) {
|
||||||
@ -101,8 +101,8 @@ internal fun Program.checkIdentifiers(errors: IErrorReporter, program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Program.variousCleanups(program: Program, errors: IErrorReporter, options: CompilationOptions) {
|
internal fun Program.variousCleanups(errors: IErrorReporter, options: CompilationOptions) {
|
||||||
val process = VariousCleanups(program, errors, options)
|
val process = VariousCleanups(this, errors, options)
|
||||||
process.visit(this)
|
process.visit(this)
|
||||||
if(errors.noErrors())
|
if(errors.noErrors())
|
||||||
process.applyModifications()
|
process.applyModifications()
|
||||||
|
@ -341,7 +341,7 @@ It can be correctly displayed on the screen only if a iso-8859-15 charset has be
|
|||||||
You can concatenate two string literals using '+', which can be useful to
|
You can concatenate two string literals using '+', which can be useful to
|
||||||
split long strings over separate lines. But remember that the length
|
split long strings over separate lines. But remember that the length
|
||||||
of the total string still cannot exceed 255 characaters.
|
of the total string still cannot exceed 255 characaters.
|
||||||
A string literal can also be repeated a given number of times using '*'.
|
A string literal can also be repeated a given number of times using '*', where the repeat number must be a constant value.
|
||||||
And a new string value can be assigned to another string, but no bounds check is done
|
And a new string value can be assigned to another string, but no bounds check is done
|
||||||
so be sure the destination string is large enough to contain the new value (it is overwritten in memory)::
|
so be sure the destination string is large enough to contain the new value (it is overwritten in memory)::
|
||||||
|
|
||||||
|
@ -3,8 +3,7 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- allow "xxx" * constexpr (where constexpr is not a number literal, now gives expression error not same type)
|
...
|
||||||
- is * lower prio than bitwise & ? fix prios if so!
|
|
||||||
|
|
||||||
|
|
||||||
Need help with
|
Need help with
|
||||||
@ -22,6 +21,7 @@ Blocked by an official Commander-x16 r39 release
|
|||||||
|
|
||||||
Future Things and Ideas
|
Future Things and Ideas
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
- allow "xxx" * constexpr (where constexpr is not a number literal, now gives expression error not same type)
|
||||||
- can we promise a left-to-right function call argument evaluation? without sacrificing performance
|
- can we promise a left-to-right function call argument evaluation? without sacrificing performance
|
||||||
- unify FunctioncallExpression + FunctioncallStatement and PipeExpression + Pipe statement, may require moving Expression/Statement into interfaces instead of abstract base classes
|
- unify FunctioncallExpression + FunctioncallStatement and PipeExpression + Pipe statement, may require moving Expression/Statement into interfaces instead of abstract base classes
|
||||||
- for the pipe operator: recognise a placeholder (``?`` or ``%`` or ``_``) in a non-unary function call to allow things as ``4 |> mkword(?, $44) |> print_uw``
|
- for the pipe operator: recognise a placeholder (``?`` or ``%`` or ``_``) in a non-unary function call to allow things as ``4 |> mkword(?, $44) |> print_uw``
|
||||||
|
Loading…
Reference in New Issue
Block a user