Some programming languages allow calculation of values at compile time.



Task

Calculate    10!    (ten factorial)   at compile time.

Print the result when the program is run.

Discuss what limitations apply to compile-time calculations in your language.




 
'LIBRARY CALLS
'=============
 
extern lib "../../oxygen.dll"
 
declare o2_basic (string src)
declare o2_exec  (optional sys p) as sys
declare o2_errno () as sys
declare o2_error () as string
 
extern lib "kernel32.dll"
 
declare QueryPerformanceFrequency(quad*freq)
declare QueryPerformanceCounter(quad*count)
 
end extern
 
'EMBEDDED SOURCE CODE
'====================
 
src=quote
 
===Source===
 
def  Pling10 2*3*4*5*6*7*8*9*10
 
byte a[pling10] 'Pling10 is resolved to a number here at compile time
 
print pling10
 
===Source===
 
 
'TIMER
'=====
 
quad ts,tc,freq
QueryPerformanceFrequency freq
QueryPerformanceCounter ts
 
'COMPILE/EXECUTE
'===============
 
o2_basic src
 
if o2_errno then
  print o2_error
else
  QueryPerformanceCounter tc
  print "Compile time: " str((tc-ts)*1000/freq, 1) " MilliSeconds"
  o2_exec 'Run the program
end if
 