'#pragma reserve' statement to reserve backend keywords

Forum for discussion about the documentation project.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: '#pragma reserve' statement to reserve backend keywords

Post by srvaldez »

fxm, both of your examples give the error 4: Duplicated definition at the appropriate line.
Last edited by srvaldez on Oct 18, 2021 15:34, edited 1 time in total.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

The compile errors are what was expected, like the comment in the source code.
I am using the last build of St_W from last night (2021-10-17).
My question was rather for Jeff.

My aim was to demonstrate the difference between '#pragma reserve' and '#pragma reserve (shared)'.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

Jeff, what do you have to say about this post ? : viewtopic.php?p=286205#p286205
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

fxm wrote:Jeff, what do you have to say about this post ? : viewtopic.php?p=286205#p286205
There is still buggy behaviour there, I think.

One issue might be the scope resolution at the time of processing '#pragma reserve'. Some of the parser context it is stored in global state and some of the context is passed as arguments through the parsers. Because #pragma is handled by the pre-processor, it can only access the global state. I might have some bad logic there.

Another issue might be that I'm confusing myself which rules to follow. Duplicate symbols depend on the symbol class. For example, variables can be shadowed, but not constants.
'' variables

Code: Select all

var shared V = 0
sub A
	var V = 1
end sub

namespace ns
	var shared V = 0
	sub A
		var V = 1
	end sub
end namespace
'' constants

Code: Select all

const C = 0
sub A
	const C = 1      '' duplicate definition
end sub

namespace ns
	const C = 0
	sub A
		const C = 1  '' duplicate definition
	end sub
end namespace
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

#pragma reserve symbol
and
#pragma reserve (shared) symbol
From a user point of view, it would be annoying to have 2 separate commands, which would do different things under the hood, but which would induce the same behavior in the code when used.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

fxm wrote:From a user point of view, it would be annoying to have 2 separate commands, which would do different things under the hood, but which would induce the same behavior in the code when used.
It has been a useful exploration for me, but I'm going to remove the '(shared)' variant and clean-up the compiler code. We already have the solution to reserve words used by ASM and backends, and there is no need to complicate this further.

'#pragma reserve (asm) symbol'
- reserves a symbol in ASM statements and ASM blocks to avoid errors in the gas backends

'#pragma reserve symbol'
- reserves a symbol in the current namespace / scope. When used at module level, prevents symbol from interfering with reserved words in the backend.

Next will we just need to add the symbols automatically which should allow us to close the bug #515 Reserved variable names (0.21.1)
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

Update: I've cleaned up the code and removed the #pragma reserve (shared) variant and I've added the reserved words for within ASM blocks, and this is pushed to fbc/master.

Bug #515 is still not fixed. because I didn't add the checks for 'dim shared cs ...' etc. It will have to be a separate look-up list and can't be stored in the global namespace.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

I will update the documentation when I have the corresponding fbc build (from St_W site):
- #PRAGMA RESERVE
- Identifier Rules
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

I will try to finish this feature / bug-fix today before the nightly build. I'm going to replace (shared) with (extern) as it better indicates purpose. Hopefully I will have some examples soon.

Maybe next time, a new problem to fix first. #944 Array descriptors are defined more than once (gcc backend)
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

coderJeff wrote:I will try to finish this feature / bug-fix today before the nightly build.
KeyPgPpPragmaReserve → fxm [updated syntax]
coderJeff wrote:I'm going to replace (shared) with (extern) as it better indicates purpose.
???
But there is no compiler error message yet when using these keywords as fbc procedure names ?
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

coderJeff wrote:I will try to finish this feature / bug-fix today before the nightly build.
I didn't get it done in time. Too many troubles. And I don't have time now. Hopefully I will have time today after work to get it added to fbc/master.

I preferred to use a warning message instead of an error just in case the logic is wrong for automatically added asm symbol names (like cs, eax, etc).

Code: Select all

#pragma reserve (extern) symbol1
#pragma reserve (extern) symbol2

dim shared symbol1 as integer

sub symbol2
end sub

/'
extern.bas(4) warning 47(1): Use of reserved global or backend symbol, symbol1
extern.bas(6) warning 47(1): Use of reserved global or backend symbol, symbol2
'/
'asm' and 'extern' can be combined in '#pragma reserve (asm,extern) symbol'
- asm adds it to the list of reserved words for the inline assembler
- extern adds it to the list of external or global words
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

I finally had some time to get changes committed:

Reserved symbols for INLINE ASM are combination of LIST A and LIST B on all targets. Note: this is not correct for non-x86 targets. There is an old reminder in the source code: "' TODO: support x86_64, arm, aarch64; select keyword list based on compilation target". Currently, LIST A+B is always selected for inline ASM statements and ASM blocks.

Reserved symbols for global/external/backend and as reported in bug #515, are from LIST A only. This is new for fbc-1.09.0. And use of these symbols for module level procedures and shared variables will generate a compile warning.

List A (inline asm and global/external/backend symbols):
dl, di, si, cl, bl, al, bp, sp, dx, cx, bx, ax, edx, edi, esi, ecx, ebx, eax, ebp, esp, st, cs, ds, es, fs, gs, ss, mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, word, dword, qword, fword, mmword, oword, r8, r9, r10, r11, r12, r13, r14, r15, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w, rax, rbp, rbx, rcx, rdi, rdx, rsi, rsp, tbyte, xmmword, ymmword, zmmword, ah, axl, bh, bpl, bxl, ch, cxl, dh, dil, dr0, dr1, dr2, dr3, dr4, dr5, dr6, dr7, dxl, eip, eq, ge, gt, le, lt, ne, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d, rip, sil, spl, ymm0, ymm1, ymm2, ymm3, ymm4, ymm5, ymm6, ymm7, ymm8, ymm9, ymm10, ymm11, ymm12, ymm13, ymm14, ymm15, zmm0, zmm1, zmm2, zmm3, zmm4, zmm5, zmm6, zmm7, zmm8, zmm9, zmm10, zmm11, zmm12, zmm13, zmm14, zmm15, zmm16, zmm17, zmm18, zmm19, zmm20, zmm21, zmm22, zmm23, zmm24, zmm25, zmm26, zmm27, zmm28, zmm29, zmm30, zmm31
List B (inline asm):
byte, ptr, offset, aaa, aad, aam, aas, adc, add, addpd, addps, addsd, addss, and, andpd, andps, andnpd, andnps, arpl, bound, bsf, bsr, bswap, bt, btc, btr, bts, call, cbw, cwde, cdq, clc, cld, clflush, cli, clts, cmc, cmova, cmovae, cmovb, cmovbe, cmovc, cmove, cmovg, cmovge, cmovl, cmovle, cmovna, cmovnae, cmovnb, cmovnbe, cmovnc, cmovne, cmovng, cmovnge, cmovnl, cmovnle, cmovno, cmovnp, cmovns, cmovnz, cmovo, cmovp, cmovpe, cmovpe, cmovpo, cmovs, cmovz, cmp, cmppd, cmpps, cmps, cmpsb, cmpsw, cmpsd, cmpss, cmpxchg, cmpxchg8b, comisd, comiss, cpuid, cvtdq2pd, cvtdq2ps, cvtpd2dq, cvtpd2pi, cvtpd2ps, cvtpi2pd, cvtpi2ps, cvtps2dq, cvtps2pd, cvtps2pi, cvtsd2si, cvtsd2ss, cvtsi2sd, cvtsi2ss, cvtss2sd, cvtss2si, cvttpd2pi, cvttpd2dq, cvttps2dq, cvttps2pi, cvttsd2si, cvttss2si, cwd, daa, das, dec, div, divpd, divps, divss, emms, enter, f2xm1, fabs, fadd, faddp, fiadd, fbld, fbstp, fchs, fclex, fnclex, fcmovb, fcmove, fcmovbe, fcmovu, fcmovnb, fcmovne, fcmovnbe, fcmovnu, fcom, fcomp, fcompp, fcomi, fcomip, fucomi, fucomip, fcos, fdecstp, fdiv, fdivp, fidiv, fdivr, fdivrp, fidivr, ffree, ficom, ficomp, fild, fincstp, finit, fninit, fist, fistp, fld, fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, fldcw, fldenv, fmul, fmulp, fimul, fnop, fpatan, fprem, fprem1, fptan, frndint, frstor, fsave, fnsave, fscale, fsin, fsincos, fsqrt, fst, fstp, fstcw, fnstcw, fstenv, fnstenv, fstsw, fnstsw, fsub, fsubp, fisub, fsubr, fsubrp, fisubr, ftst, fucom, fucomp, fucompp, fwait, fxam, fxch, fxrstor, fxsave, fxtract, fyl2x, fyl2xp1, hlt, idiv, imul, in, inc, ins, insb, insw, insd, int, into, invd, invlpg, iret, iretd, ja, jae, jb, jbe, jc, jcxz, jecxz, je, jg, jge, jl, jle, jna, jnae, jnb, jnbe, jnc, jne, jng, jnge, jnl, jnle, jno, jnp, jns, jnz, jo, jp, jpe, jpo, js, jz, jmp, lahf, lar, ldmxcsr, lds, les, lfs, lgs, lss, lea, leave, lfence, lgdt, lidt, lldt, lmsw, lock, lods, lodsb, lodsw, lodsd, loop, loope, loopz, loopne, loopnz, lsl, ltr, maskmovdqu, maskmovq, maxpd, maxps, maxsd, maxss, mfence, minpd, minps, minsd, minss, mov, movapd, movaps, movd, movdqa, movdqu, movdq2q, movhlps, movhpd, movhps, movlhps, movlpd, movlps, movmskpd, movmskps, movntdq, movnti, movntpd, movntps, movntq, movq, movq2dq, movs, movsb, movsw, movsd, movss, movsx, movupd, movups, movzx, mul, mulpd, mulps, mulsd, mulss, neg, nop, not, or, orpd, orps, out, outs, outsb, outsw, outsd, packsswb, packssdw, packuswb, paddb, paddw, paddd, paddq, paddsb, paddsw, paddusb, paddusw, pand, pandn, pause, pavgb, pavgw, pcmpeqb, pcmpeqw, pcmpeqd, pcmpgtb, pcmpgtw, pcmpgtd, pextrw, pinsrw, pmaddwd, pmaxsw, pmaxub, pminsw, pminub, pmovmskb, pmulhuv, pmulhw, pmullw, pmuludq, pop, popa, popad, popf, popfd, por, prefetcht0, prefetcht1, prefetcht2, prefetchnta, psadbw, pshufd, pshufhw, pshuflw, pshufw, psllw, pslld, psllq, psraw, psrad, psrldq, psrlw, psrld, psrlq, psubb, psubw, psubd, psubq, psubsb, psubsw, psubusb, psubusw, punpckhbw, punpckhwd, punpckhdq, punpckhqdq, punpcklbw, punpcklwd, punpckldq, punpcklqdq, push, pusha, pushad, pushf, pushfd, pxor, rcl, rcr, rol, ror, rcpps, rcpss, rdmsr, rdpmc, rdtsc, rep, repe, repz, repne, repnz, ret, rsm, rsqrtps, rsqrtss, sahf, sal, sar, shl, shr, sbb, scas, scasb, scasw, scasd, seta, setae, setb, setbe, setc, sete, setg, setge, setl, setle, setna, setnae, setnb, setnbe, setnc, setne, setng, setnge, setnl, setnle, setno, setnp, setns, setnz, seto, setp, setpe, setpo, sets, setz, sfence, sgdt, sidt, shld, shrd, shufpd, shufps, sldt, smsw, sqrtpd, sqrtps, sqrtsd, sqrtss, stc, std, sti, stmxcsr, stos, stosb, stosw, stosd, str, sub, subpd, subps, subsd, subss, sysenter, sysexit, test, ucomisd, ucomiss, ud2, unpckhpd, unpckhps, unpcklpd, unpcklps, verr, verw, wait, wbinvd, wrmsr, xadd, xchg, xlat, xlatb, xor, xorpd, xorps, pavgusb, pfadd, pfsub, pfsubr, pfacc, pfcmpge, pfcmpgt, pfcmpeq, pfmin, pfmax, pi2fw, pi2fd, pf2iw, pf2id, pfrcp, pfrsqrt, pfmul, pfrcpit1, pfrsqit1, pfrcpit2, pmulhrw, pswapw, femms, prefetch, prefetchw, pfnacc, pfpnacc, pswapd, pmulhuw
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

Side effect when using for example #cmdline "-asm ...": the warning messages ('Use of reserved ...') can be doubled (if there are no other errors).
Example with fbc 64-bit:

Code: Select all

#cmdline "-asm att"

Sub ah()
End Sub

ah()
Print "OK"

Sleep
Compiler output:
...\FBIde0.4.6r4-FreeBASIC1.09.0.win64\FBIDETEMP.bas(9) warning 47(1): Use of reserved global or backend symbol, ah
...\FBIde0.4.6r4-FreeBASIC1.09.0.win64\FBIDETEMP.bas(9) warning 47(1): Use of reserved global or backend symbol, ah
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: '#pragma reserve' statement to reserve backend keywords

Post by fxm »

'#pragma reserve (asm, extern) symbol' is an alternative syntax to '#pragma reserve (extern) symbol' and there is a duplication error if both are used on the same symbol.

'#pragma reserve (extern, asm) symbol' is also allowed but does not induce duplication error with '#pragma reserve (extern) symbol' but on the other hand it duplicates with '#pragma reserve (asm) symbol' ???
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: '#pragma reserve' statement to reserve backend keywords

Post by coderJeff »

fxm wrote:' '#pragma reserve (extern, asm) symbol' is also allowed but does not induce duplication error with '#pragma reserve (extern) symbol'
Thanks, I see my logic error. I'll fix this ASAP.
Post Reply