flat assembler
Message board for the users of flat assembler.
Index
> Main > [solved] [fasmg] Peculiar results in CALM with define |
Author |
|
Calanor 14 Jan 2021, 10:55
So, I figured I'd write a small CALM instruction in order to try to get the hang of things. The idea was to write code that would define and assign a value to a name if it has not been previously defined. Inspired by Tomasz suggestion to use take or transform to check if a name's been defined, I wrote a small instruction to try things out.
Code: calminstruction setdefaultvalue? var*, arg*& transform var jyes var_defined local cmd arrange cmd, =define var arg assemble cmd var_defined: end calminstruction ;define testing 'defined' SetDefaultValue testing, 'default' display testing, 13, 10 This will result in the compiler reporting that it failed to generate the code within the allowed number of passes. I also tried using arrange at the start of the code to copy "var" into a temporary variable and use that one instead when assembling the line, but that made no apparent difference. The final "display" is actually executed in spite of the generated error and will display the correct result. I've noticed when writing other CALM code that the compiler doesn't actually seem to stop when encountering a CALM-related error, which has caused some confusion and made bug hunting more complicated. Regarding arrange, I don't necessarily have to declare a variable as local before using it as the destination for arrange. How is this handled by the compiler? Will it automatically consider the variable to be a new local one and if so is there any actual reason why one would like to declare it as local anyway? Will the compile speed be affected in any way? |
|||
14 Jan 2021, 10:55 |
|
Tomasz Grysztar 14 Jan 2021, 11:41
When a symbol is defined exactly once in the source and it is not forced by any other means to be considered "variable", it is allowed to be forward-referenced. Your problem is therefore similar to the classic one:
Code: if ~ defined testing testing = 1 end if In some of the macro sets for fasmg you may notice specific methods used to ensure that no disruptive forward-referencing occurs: Code: if ~ defined SSE restore SSE ; this ensures that symbol cannot be forward-referenced SSE = 1 Calanor wrote: I've noticed when writing other CALM code that the compiler doesn't actually seem to stop when encountering a CALM-related error, which has caused some confusion and made bug hunting more complicated. Calanor wrote: Regarding arrange, I don't necessarily have to declare a variable as local before using it as the destination for arrange. How is this handled by the compiler? Will it automatically consider the variable to be a new local one and if so is there any actual reason why one would like to declare it as local anyway? Will the compile speed be affected in any way? |
|||
14 Jan 2021, 11:41 |
|
revolution 14 Jan 2021, 12:08
Tomasz Grysztar wrote: When a symbol is defined exactly once in the source and it is not forced by any other means to be considered "variable", it is allowed to be forward-referenced. Your problem is therefore similar to the classic one: Code: if ~ defined testing testing = 1 testing = 1 end if display testing + '0' |
|||
14 Jan 2021, 12:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.