本文整理汇总了Golang中vamos/lang/ast.Node.Loc方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Loc方法的具体用法?Golang Node.Loc怎么用?Golang Node.Loc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vamos/lang/ast.Node
的用法示例。
在下文中一共展示了Node.Loc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: panicEvalError
func panicEvalError(n ast.Node, s string) {
var loc *token.Location
if n != nil {
loc = n.Loc()
}
panic(NewEvalError("Evaluation error", s, loc))
}
示例2: panicApplicationError
func panicApplicationError(n ast.Node, s string) {
var loc *token.Location
if n != nil {
loc = n.Loc()
}
panic(NewEvalError("Application panic", s, loc))
}
示例3: evalInvokeProcedure
func evalInvokeProcedure(dynamicEnv Env, f *Procedure, head ast.Node, unevaledArgs ast.Nodes, shouldEvalMacros bool) packet {
defer func() {
if e := recover(); e != nil {
switch errorValue := e.(type) {
case *EvalError:
fmt.Printf("TRACE: (%v: %v): call to %v\n", head.Loc().Filename, head.Loc().Line, f.Name)
panic(errorValue)
default:
panic(errorValue)
}
}
}()
// Validate parameters
isVariableNumberOfParams := false
for _, param := range f.Parameters {
switch paramVal := param.(type) {
case *ast.Symbol:
if paramVal.Name == "&rest" {
isVariableNumberOfParams = true
}
default:
panicEvalError(head, "Procedure parameters should only be symbols: "+param.String())
}
}
if !isVariableNumberOfParams {
if len(unevaledArgs) != len(f.Parameters) {
panicEvalError(head, fmt.Sprintf(
"Procedure '%v' expects %v argument(s), but was given %v. Procedure parameter list: %v. Arguments: %v.",
f.Name,
len(f.Parameters),
len(unevaledArgs),
f.Parameters,
unevaledArgs))
}
}
// Create the lexical environment based on the procedure's lexical parent
lexicalEnv := NewMapEnv(f.Name, f.ParentEnv)
// Prepare the arguments for application
var args []ast.Node
if f.IsMacro {
args = unevaledArgs
} else {
args = evalEachNode(dynamicEnv, unevaledArgs)
}
// Map arguments to parameters
isMappingRestArgs := false
iarg := 0
for iparam, param := range f.Parameters {
paramName := toSymbolName(param)
if isMappingRestArgs {
restArgs := args[iarg:]
restList := ast.NewList(restArgs)
lexicalEnv.Set(paramName, restList)
} else if paramName == "&rest" {
isMappingRestArgs = true
} else {
lexicalEnv.Set(paramName, args[iparam])
iarg++
}
}
if f.IsMacro {
expandedMacro := trampoline(func() packet {
return evalNode(lexicalEnv, f.Body)
})
if shouldEvalMacros {
return bounce(func() packet {
// This is executed in the environment of its application, not the
// environment of its definition
return evalNode(dynamicEnv, expandedMacro)
})
} else {
return respond(expandedMacro)
}
} else {
// Evaluate the body in the new lexical environment
return bounce(func() packet {
return evalNode(lexicalEnv, f.Body)
})
}
}