Roman Numeral-like Code Generator
Bash, 54 48 bytes
-6 bytes by adapting Dominic van Essen's output-prevention trick
printf &quot;:|:
((s+=p&lt;$1?$1-2*p:$1))
p=$1
echo \$s&quot;

This assumes the program must not have any excess output, which turns out to be one of the tricker parts. I expect one of the golfing languages that will output by default at the end of the program would do best here.
Try it online!
Explanation
Example output for 3 concatenated with output for 10 (the concatenated program outputs 7):
:|:
((s+=p&lt;3?3-2*p:3))
p=3
echo $s:|:
((s+=p&lt;10?10-2*p:10))
p=10
echo $s


:|: prevents any echo from a previous fragment from outputting
s is the sum value so far (implicitly 0 at the start of the program)
p is the previous value

Each fragment assumes that the current value is not less than the next value, and thus adds it to the sum. It also checks whether the previous fragment was wrong to assume this (ie. the previous value was less than the current value), and if so corrects the sum by subtracting double the previous value.