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 13ef22c commit b3f7d87
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BEGIN {
split("",DependenciesCnt) # name -> dep cnt
split("",DependencyArgsCnt) # name,i -> args cnt
split("",DependencyArgs) # name,depI,argI -> val
split("",DependencyArgsType) # name,depI,argI -> string|var
split("",DependencyArgsType) # name,depI,argI -> str|var
split("",Doc) # name -> doc str
split("",ReachedIf) # name -> condition line
GlobCnt = 0 # count of files for glob
Expand Down Expand Up @@ -221,6 +221,7 @@ function registerGoal(goalName, priv, i) {
if ("@params" == $3)
for (i=4; i <= NF; i++)
GoalParams[goalName,GoalParamsCnt[goalName]++] = $i # TODO $NF=="@private"?
# TODO error if @params on other position
}

function globGoal(i) { return (GlobGoalName ? GlobGoalName "@" : "") GlobFiles[i] }
Expand Down Expand Up @@ -303,7 +304,7 @@ function registerDependsOn(goalName, i,dep,x,y) {
x = goalName SUBSEP DependenciesCnt[goalName]
y = x SUBSEP DependencyArgsCnt[x]++
DependencyArgs[y] = $i
DependencyArgsType[y] = Quotes[i] ? "string" : "var"
DependencyArgsType[y] = Quotes[i] ? "str" : "var"
}
} else
registerDependency(goalName, dep)
Expand Down Expand Up @@ -595,6 +596,50 @@ function topologicalSortPerform(includeReachedIf,reachedGoals, node, result, loo
arrPush(result, node)
}

#
# args: { F => "file1" }
#
function instantiate(goal,args,newArgs, i,j,depArg,depArgType,dep,goalNameInstantiated,argsCnt) { # -> goalNameInstantiated
# print ">instantiating " goal " { " renderArgs(args) "} ..."

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

Goal[goalNameInstantiated = instantiateGoalName(goal, args)]
DependencyCnt[goalNameInstantiated] = DependencyCnt[goal]

for (i=0; i < DependencyCnt[goal]; i++) {
# TODO goal,i to var
dep = Dependency[goal,i]

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

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

newArgs[GoalParams[dep,j]] = \
depArgType == "str" ? \
depArg : \
depArgType == "var" ? \
(depArg in args ? args[depArg] : addError("wrong arg " depArg, DependenciesLineNo[goal,i])) : \
die("wrong depArgType: " depArgType)
}

Dependency[goalNameInstantiated,i] = instantiate(dep,newArgs)
}

return goalNameInstantiated
}
function instantiateGoalName(goal, args, res,cnt,i){
if ((cnt = GoalParamsCnt[goal]) == 0) { return goal }
res = goal
for (i=0; i < cnt; i++) {
res = res "@" args[GoalParams[goal,i]]
}
# print "@@ " res
return res
}

function currentTimeMillis( res) {
if (Gawk)
return int(gettimeofday()*1000)
Expand Down

0 comments on commit b3f7d87

Please sign in to comment.