Skip to content

Commit

Permalink
Parameterized goals #115
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Jan 20, 2023
1 parent 7d28a5a commit 2cea87f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function registerDependsOn(goalName, i,dep,x,y) {
if (i != 3) addError("@args only allowed at position 3") # TODO finalize error msg
if (i == NF) addError("must be at least one argument") # TODO finalize error msg
while (++i <= NF) {
x = goalName SUBSEP DependenciesCnt[goalName]
x = goalName SUBSEP (DependenciesCnt[goalName]-1)
y = x SUBSEP DependencyArgsCnt[x]++
DependencyArgs[y] = $i
DependencyArgsType[y] = Quotes[i] ? "str" : "var"
Expand Down Expand Up @@ -366,11 +366,11 @@ body,goalBody,goalBodies,resolvedGoals,exitCode, t0,t1,t2, goalTimed, list) {

checkBeforeRun()

dbgA("GoalParamsCnt",GoalParamsCnt)
dbgA("GoalParams",GoalParams)
dbgA("DependencyArgsCnt",DependencyArgsCnt)
dbgA("DependencyArgs",DependencyArgs)
dbgA("DependencyArgsType",DependencyArgsType)
dbgA("GoalParamsCnt",GoalParamsCnt)
dbgA("GoalParams",GoalParams)
dbgA("DependencyArgsCnt",DependencyArgsCnt)
dbgA("DependencyArgs",DependencyArgs)
dbgA("DependencyArgsType",DependencyArgsType)

if (Error)
die(Error)
Expand Down Expand Up @@ -608,12 +608,14 @@ function renderArgs(args, s,k) { s = ""; for (k in args) s = s k "=>" args[k]
# args: { F => "file1" }
#
function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInstantiated,argsCnt) { # -> goalNameInstantiated
print ">instantiating " goal " { " renderArgs(args) "} ..."
print ">instantiating " goal " { " renderArgs(args) "} ..."

if (!(goal in GoalsByName)) { die("unknown goal: " goal) }

if (GoalParamsCnt[goal] > 0) {
GoalsByName[goalNameInstantiated = instantiateGoalName(goal, args)] = GoalsByName[goal]
goalNameInstantiated = instantiateGoalName(goal, args)

if (goalNameInstantiated != goal) {
GoalsByName[goalNameInstantiated] = GoalsByName[goal]
DependenciesCnt[goalNameInstantiated] = DependenciesCnt[goal]
arrPush(GoalNames, goalNameInstantiated)
CodePre[goalNameInstantiated] = CodePre[goal] # TODO attach dependency var values
Expand All @@ -629,10 +631,14 @@ function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInst

if ((argsCnt = DependencyArgsCnt[goal,i]) != GoalParamsCnt[dep]) { addError("wrong args count", DependenciesLineNo[goal,i]) }

# print "argsCnt " argsCnt

for (j=0; j < argsCnt; j++) {
depArg = DependencyArgs [goal,i,j]
depArgType = DependencyArgsType[goal,i,j]

# print "@ " depArg " " depArgType

newArgs[GoalParams[dep,j]] = \
depArgType == "str" ? \
depArg : \
Expand All @@ -648,7 +654,7 @@ function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInst
return goalNameInstantiated
}
function instantiateGoalName(goal, args, res,cnt,i){
# if ((cnt = GoalParamsCnt[goal]) == 0) { return goal }
if ((cnt = GoalParamsCnt[goal]) == 0) { return goal }
res = goal
for (i=0; i < cnt; i++) {
res = res "@" args[GoalParams[goal,i]]
Expand Down

0 comments on commit 2cea87f

Please sign in to comment.