From 7d596f3ed69968b97e0bc56a8c2797afde7050b9 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Sat, 5 Jan 2019 01:04:08 +0100 Subject: [PATCH] Minor improvements --- docs/lang/literals.md | 7 ++++++ millfork-udl.xml | 2 +- .../compiler/mos/MosExpressionCompiler.scala | 6 +++++ src/main/scala/millfork/node/Node.scala | 22 +++++++++++++++---- .../millfork/output/AbstractAssembler.scala | 4 ++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/docs/lang/literals.md b/docs/lang/literals.md index 359afecc..561e55a5 100644 --- a/docs/lang/literals.md +++ b/docs/lang/literals.md @@ -21,6 +21,9 @@ It is not allowed in any other places. String literals can be used as either array initializers or expressions of type `pointer`. +If a string literal is used as an expression, then the text data will be located in the default code segment, +regardless of which code segment the current function is located it. This may be subject to change in future releases. + String literals are surrounded with double quotes and optionally followed by the name of the encoding: "this is a string" ascii @@ -101,6 +104,10 @@ An array is initialized with either: * `@word_be` – like the above, but opposite: `@word_be [$1122]` is equivalent to `[$11, $22]` + + * `@long` (=`@long_le`), `@long_be`: similar, but with four bytes + `@long [$11223344]` is equivalent to `[$44, $33, $22, $11]` + `@long_be [$11223344]` is equivalent to `[$11, $22, $33, $44]` * a list of byte literals and/or other array initializers, surrounded by brackets: diff --git a/millfork-udl.xml b/millfork-udl.xml index 757750aa..d9c40d4e 100644 --- a/millfork-udl.xml +++ b/millfork-udl.xml @@ -24,7 +24,7 @@ - void byte sbyte ubyte array word farword pointer farpointer long word_be word_le file int8 int16 int24 int32 int40 int48 int56 int64 signed8 fast + void byte sbyte ubyte array word farword pointer farpointer long word_be word_le long_be long_le file int8 int16 int24 int32 int40 int48 int56 int64 signed8 fast if else for return while do asm extern import segment break continue default alias enum defaultz petscii ascii scr petscr pet atascii atari bbc sinclair apple2 jis jisx iso_de iso_yu iso_no iso_dk iso_se iso_fi petsciiz asciiz scrz petscrz petz atasciiz atariz bbcz sinclairz apple2z jisz jisxz iso_dez iso_yuz iso_noz iso_dkz iso_sez iso_fiz until to downto parallelto static stack ref const volatile paralleluntil inline noinline macro register kernal_interrupt interrupt reentrant hi lo sin cos tan nonet align "sta " "lda " "jmp " "bit " "eor " "adc " "sbc " "ora " "and " "ldx " "ldy " "stx " "sty " "tax" "tay" "tya" "txa" "txs" "tsx" "sei" "cli" "clv" "clc" "cld" "sed" "sec" "bra " "beq " "bne " "bmi " "bpl " "bcc " "bcs " "bvs " bvc " "jsr " rts" "rti" "brk" "rol" "ror" "asl" "lsr" "inc " "dec " "cmp " "cpx " "cpy " inx iny dex dey pla pha plp hp phx plx phy ply "stz " "ldz " tza taz "tsb " "trb " ra txy tyx pld plb phb phd phk xce "STA " "LDA " "JMP " "BIT " "EOR " "ADC " "SBC " "ORA " "AND " "LDX " "LDY " "STX " "STY " "TAX" "TAY" "TYA" "TXA" "TXS" "TSX" "SEI" "CLI" "CLV" "CLC" "CLD" "SED" "SEC" "BEQ " "BRA " "BNE " "BMI " "BPL " "BCC " "BCS " "BVS " BVC " "JSR " RTS" "RTI" "BRK" "ROL" "ROR" "ASL" "LSR" "INC " "DEC " "CMP " "CPX " "CPY " INX INY DEX DEY PLA PHA PLP HP PHX PLX PHY PLY "STZ " "LDZ " TZA TAZ "TSB " "TRB " RA TXY TYX PLD PLB PHB PHD PHK XCE diff --git a/src/main/scala/millfork/compiler/mos/MosExpressionCompiler.scala b/src/main/scala/millfork/compiler/mos/MosExpressionCompiler.scala index fe002151..cdc88577 100644 --- a/src/main/scala/millfork/compiler/mos/MosExpressionCompiler.scala +++ b/src/main/scala/millfork/compiler/mos/MosExpressionCompiler.scala @@ -38,6 +38,12 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] { case RegisterVariable(MosRegister.YA, _) => List( AssemblyLine(LDA, Immediate, expr.hiByte), AssemblyLine(LDY, Immediate, expr.loByte)) + case RegisterVariable(MosRegister.XY, _) => List( + AssemblyLine(LDY, Immediate, expr.hiByte), + AssemblyLine(LDX, Immediate, expr.loByte)) + case RegisterVariable(MosRegister.YX, _) => List( + AssemblyLine(LDX, Immediate, expr.hiByte), + AssemblyLine(LDY, Immediate, expr.loByte)) case m: VariableInMemory => val elidability = if (m.isVolatile) Elidability.Volatile else Elidability.Elidable val addrMode = if (m.zeropage) ZeroPage else Absolute diff --git a/src/main/scala/millfork/node/Node.scala b/src/main/scala/millfork/node/Node.scala index 2e70d2cd..361965e9 100644 --- a/src/main/scala/millfork/node/Node.scala +++ b/src/main/scala/millfork/node/Node.scala @@ -264,13 +264,27 @@ case class ProcessedContents(processor: String, values: ArrayContents) extends A override def getAllExpressions: List[Expression] = processor match { case "word" | "word_le" => values.getAllExpressions.flatMap(expr => List( - FunctionCallExpression("lo", List(expr)), - FunctionCallExpression("hi", List(expr)) + FunctionCallExpression("lo", List(expr)).pos(expr.position), + FunctionCallExpression("hi", List(expr)).pos(expr.position) )) case "word_be" => values.getAllExpressions.flatMap(expr => List( - FunctionCallExpression("hi", List(expr)), - FunctionCallExpression("lo", List(expr)) + FunctionCallExpression("hi", List(expr)).pos(expr.position), + FunctionCallExpression("lo", List(expr)).pos(expr.position) + )) + case "long" | "long_le" => + values.getAllExpressions.flatMap(expr => List( + FunctionCallExpression("byte", List(expr)).pos(expr.position), + FunctionCallExpression("byte", List(FunctionCallExpression(">>", List(expr, LiteralExpression(8, 1))).pos(expr.position))).pos(expr.position), + FunctionCallExpression("byte", List(FunctionCallExpression(">>", List(expr, LiteralExpression(16, 1))).pos(expr.position))).pos(expr.position), + FunctionCallExpression("byte", List(FunctionCallExpression(">>", List(expr, LiteralExpression(24, 1))).pos(expr.position))).pos(expr.position) + )) + case "long_be" => + values.getAllExpressions.flatMap(expr => List( + FunctionCallExpression("byte", List(FunctionCallExpression(">>", List(expr, LiteralExpression(24, 1))).pos(expr.position))).pos(expr.position), + FunctionCallExpression("byte", List(FunctionCallExpression(">>", List(expr, LiteralExpression(16, 1))).pos(expr.position))).pos(expr.position), + FunctionCallExpression("byte", List(FunctionCallExpression(">>", List(expr, LiteralExpression(8, 1))).pos(expr.position))).pos(expr.position), + FunctionCallExpression("byte", List(expr)).pos(expr.position) )) } diff --git a/src/main/scala/millfork/output/AbstractAssembler.scala b/src/main/scala/millfork/output/AbstractAssembler.scala index d4d41042..29bd4548 100644 --- a/src/main/scala/millfork/output/AbstractAssembler.scala +++ b/src/main/scala/millfork/output/AbstractAssembler.scala @@ -262,7 +262,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program for (item <- items) { env.eval(item) match { case Some(c) => writeByte(bank, index, c) - case None => log.error(s"Non-constant contents of array `$name`") + case None => log.error(s"Non-constant contents of array `$name`", item.position) } bank0.occupied(index) = true bank0.initialized(index) = true @@ -367,7 +367,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program for (item <- items) { env.eval(item) match { case Some(c) => writeByte(bank, index, c) - case None => log.error(s"Non-constant contents of array `$name`") + case None => log.error(s"Non-constant contents of array `$name`", item.position) } index += 1 }