/* Task evaluator */ file = arg(1) p=0 /* Load it into memory */ do forever a=linein(file) if a="#" then leave p=p+1 program.p=a end /* enumerate number of subs This thing assumes that the coder knows how to put Sub and Endsub after the routine. If they dont match, it will dump a lot of weird stuff into the sub */ numsub=0 name=1 startpos=2 endpos=3 len=4 do i=1 to p a=program.i /* Drop the program into a temp variable */ if word(a,1)="Sub" then do /* if the first word is 'Sub' its probably the start of a sub */ numsub=numsub+1 /* Yay! bump the sub count -- we found another sub */ subs.numsub.name=word(a,2) /* Throw the name of the sub into the subname field */ subs.numsub.startpos=i /* Derive the start position from the INCing program line number */ end if word(a,1)="Endsub" then do /* We reached the end of the sub */ subs.numsub.endpos=i /* Store the location of the end of the sub for later yanking */ end end /* Store the subs This will dump each sub into a different stem so we can multithread them all easier in rexx ... */ do i=1 to numsub /* Do this for all the subs we found */ routine.i.len = endpos - startpos /* determine the length of the code */ floo=0 /* clear floo so we can keep track of the routine stem count */ do q=subs.i.startpos to subs.i.endpos /* Do a loop where it starts to where it stops */ floo=floo+1 /* INC floop for our routine stem count */ routine.i.floo = program.q /* Drop the program into our routine stem */ end end /* First, we will execute sub main to see what we end up launching. */ count = 0 /* clear the program counter */ threads = 1 /* tell the interpreter we have 1 thread */ thread.1 = 1 /* tell the interpreter the thread is "main" */ subpointer.1 = 1 /* setup the sub pointer to start at the first line */ lock.1 = 0 /* avoid lockup of thread */ var = 0 /* clear the variable count ?? */ varnum = 0 /* clear variable count */ markdo.1 = 0 /* clear the only do go-back */ sleep.1 = 0 /* clear the sleep holder */ history.1 = 0 /* clear the wait history value */ main: do i=1 to threads /* We are going to do a loop so we can check on our threads one by one */ the_thread=thread.i /* store the current thread's sub number into a variable */ the_pointer=subpointer.i /* store the current thread's program counter into a variable */ code=routine.the_thread.the_pointer /* Get the current line of code */ if lock.the_thread = 0 then do /* the lock is just to pause threads we dont like from doing anything */ inst=word(code,1) /* Grab out the current instruction */ /* say "thread: "i" SubLine: "the_pointer" Code: "code */ if inst="Comm" then call sub_comm if inst="ChildWait" then call sub_childwait if inst="Do" then call sub_do if inst="Sleep" then call sub_sleep if inst="Loop" then call sub_loop if inst="Print" then call sub_print if inst="Let" then call sub_let if inst="Sub" then call sub_submain if inst="EndSub" then call sub_endsub if inst="Wait" then call sub_wait end end signal main sub_submain: /* these subs should be parsed out out the sub stems, but im lazy */ subpointer.i=subpointer.i+1 return sub_endsub: /* these subs should be parsed out out the sub stems, but im lazy Im just going to halt execution of everything at this point -- later on it should just kill that particular child. */ say "###TASK -- EndSub reached in routine "sub.the_thread.name say "###TASK -- Exiting" exit return sub_comm: description=1 content=2 the_variable=substr(word(code,2),2) the_value=word(code,3) if the_value="" then the_value=0 do var=var+1 /* inc the var count */ storge.var.description = the_variable /* populate the name */ storage.var.content = the_value /* populate the value */ subpointer.i=subpointer.i+1 /* everything is good, bump the program counter for that sub */ end return sub_childwait: /* This will pause execution until all the children launched ends.. For simplicity sake, it will never end in this version */ lock.the_thread=1 /* Lock up the thread just so this call never returns */ z=words(code) /* Figure out how many childs we have to pull out of the function */ z=z-1 /* subtract the "ChildWait" word */ do y=1 to z /* Do it for all the childs to launch */ new_threads = y + 1 /* Start this off at word 2 so we dont count the function as a thread */ do x=1 to numsub /* Check the full list of sub names so we can match it up with the sub number */ if subs.x.name = word(code,new_threads) then do /* Did we find it? */ threads = threads + 1 /* bump the thread count */ thread.threads = x /* set the thread up for the right sub number */ subpointer.threads = 1 /* set the new thread's counter to 1 */ lock.threads = 0 /* Dont lock it up */ markdo.threads = 0 /* Clear the single do go-back */ sleep.threads = 0 /* clear the sleep counter */ history.threads = 0 /* clear the single wait history check */ end /* We wont do any error checking right now to see if the sub really was found or not */ end end return sub_do: z=subpointer.i markdo.i = z subpointer.i=subpointer.i+1 return sub_sleep: seconds = time('s') sleept = sleeptil.i if sleep.i=0 then do timewait = word(code,2) sleeptil.i= seconds + timewait sleep.i=1 end if sleep.i=1 then do if seconds > sleept then subpointer.i=subpointer.i+1 if seconds > sleept then sleep.i=0 end return sub_loop: subpointer.i = markdo.i return sub_print: subpointer.i=subpointer.i+1 stuffthere=0 temp="" if substr(word(code,2),1,1)="$" then do stuffthere=1 call get_var temp=results end if stuffthere=1 then do say temp end if stuffthere=0 then do start=index(code,'"') stop=index(code,'"',start+1) stopoff=stop-start say substr(code,start+1,stopoff-1) end return get_var: results="NULL" svar=word(code,2) svar=substr(svar,2) if svar="rand" then do z = random(1,9999,time('s')) results=z return end if var=0 then do results="NULL" return end do y=1 to var if storage.var.description=svar then do results=storage.var.content return end end return sub_let: subpointer.i=subpointer.i+1 svar=word(code,2) svar=substr(svar,2) if var=0 then do var=1 storage.var.description=svar storage.var.content=word(code,3) if word(code,3) = "$rand" then do storage.var.content=random(1,9999,time('s')) end return end /* check to see if this variable exists before we deligate a new one */ do z=1 to var if storage.z.description=svar then do storage.z.content=word(code,3) if word(code,3) = "$rand" then do storage.var.content=random(1,9999,time('s')) end return end end /* we will have to deligate a new one cuz we didnt find it */ do var=var+1 storage.var.description=svar varlist.var.content=word(code,3) if word(code,3) = "$rand" then do storage.var.content=random(1,9999,time('s')) end end return sub_wait: svar=word(code,2) do z=1 to var if storage.z.description=svar then do if storage.z.content~=history.i then do subpointer.i=subpointer.i+1 history.i=storage.z.content return end end end return