def compileGoal(self,g,wamprog,previousVars): for i,a in enumerate(g.args): if parser.isProcessedConstant(a): wamprog.append(('pushconst',a)) elif a in previousVars: wamprog.append(('pushboundvar',a)) else: wamprog.append(('pushfreevar',a)) previousVars.add(a) wamprog.append(('callp','%s/%s' % (g.functor,g.arity)))
def compileRule(self,rule,wamprog): # allocate variables nvars = rule.nvars if nvars>0: wamprog.append(('allocate',nvars,list(reversed(rule.variableList)))) previousVars = set() # compile code to match the head if rule.lhs: for i,a in enumerate(rule.lhs.args): relativeHeapIndex = -len(rule.lhs.args) + i if parser.isProcessedConstant(a): wamprog.append(('unifyconst',a,relativeHeapIndex)) elif a in previousVars: wamprog.append(('unifyboundvar',a,relativeHeapIndex)) else: wamprog.append(('initfreevar',a,relativeHeapIndex)) previousVars.add(a) # compile the body for g in rule.rhs: self.compileGoal(g,wamprog,previousVars) wamprog.append(('returnp',))