• Introduction:
    Every programmer, who develop a bigger project, very soon exceeds speed limitations of the compiler. Same with PowerD. Then they try to find a solution, that would speedup the compilation. One solution is to buy a faster hardware... like in the PC world. But there is a better way. Separate the big source into smaller pieces, where each one will be compiler much faster. Nevertheless, it not that simple.

  • Variable sharing:
    The most important thing when You have multiple sources, is to share global variables between them. You have to define (DEF) those variables in only one source. In all other sources, where are these variables used, You can add just a reference to the variable (EDEF). Both should be defined with same type to not to cause mismatch errors, which can't be handled by the compiler.

  • Function sharing:
    Same as with variables, only You define those procedure references as EPROC name(args)(results).

  • Sharing module:
    If You use more sources, it would be better to make for each source a module, that will contain all the variable and procedure references. This can be simply generated by:
      1.> dc source1.d gm
    

    This GM=GENMODULE/S switch will generate file called 'source1.m' that will contain all the variable and procedure references. Such module should be then used (MODULE) in all the other sources, that use the source1.d's functions or variables. The generated module will also contain the reference to the linking object file of the source1.d called usualy source1.o.

  • Multiple source small project compilation:
    For smaller projects it's enough to compile each source individualy with 'dc source'. Each source, that doesn't contain the main() procedure should have enables the OPT NOEXE, because else will appear an error, that there is no main() procedure. In our case, it's enough to add just a module of the given source:

    Main Source called main.d:
      MODULE  '*read','*save'
    
      PROC main()
        read()
        save('ram:file.txt')
      ENDPROC
    


    first source called read.d:
      OPT NOEXE
    
      DEF str[32]:STRING
    
      PROC read()
        WriteF('Enter a string: ')
        ReadEStr(stdout,str)
      ENDPROC
    



    and second source called save.d:
      OPT NOEXE
    
      MODULE  '*read'
    
      PROC save(name)
        DEF f
        IF f:=Open(name,NEWFILE)
          Write(f,str,StrLen(str))
          Close(f)
        ENDIF
      ENDPROC
    

    Now our sources are finished. Main source, resp. main() function use both the save() function from the save.d file and the read() function from the read.d source, so we have to define both modules. First source read.d contains the definition of the variable str. The read() function writes a string ans waits for You to enter some text. Second source save.d opens a file with given name ('ram:file.txt') and saves there the contents of the str variable, which isn't here defined. That's why we have there the module '*read', because there is defined the variable reference.
    Now we have to compile our sources. First we have to compile the read.d source, because it is used in both next sources. Enter:
      1.> dc read gm
    

    Now (if everything is ok) You can see, that there is a new file called read.m and it contains:
      OPT	LINK='*read.o'
    
      EPROC read()
    
    
      EDEF	str:PTR TO CHAR
    

    Now enter:
      1.> dc save gm
    

    Now (if everything is ok) You can see, that there is a new file called save.m and it contains:
      OPT	LINK='*save.o'
    
      EPROC save(name)
    

    Now enter:
      1.> dc main
    

    And if everything is ok, enter main, and when it asks, enter some string:
      1.> main
      Enter a string: hello world
    

    Now, there is a file in ramdisk called file.txt, that contains the string You entered.

  • Multiple source project compilation:
    For bigger projects is the above quiet useless, because each time You change something, You have to recompile both the changed source and the main source. Everything is the same as above, except one thing. You don't have to compile anything directly with dc, but with a bit smarter pc (project compiler) and You have to build Your own project file as described here.

    The project file (let call it 'test.dpr' should look like:
      PowerD Project v1
    
      // main source file:
      obj='main.o'
    
      // rest objects:
      obj='read.o'
      obj='save.o'
    
      // executeble file:
      exe='main'
    

    And if You enter:
      1.> pc test
    

    It compiles all changed files and link them together to executable called 'main'.