Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature infering as a new command in swam cli #12

Merged
merged 6 commits into from
Aug 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions cli/src/swam/cli/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,38 @@ object Main extends CommandIOApp(name = "swam-cli", header = "Swam from the comm
val functionName =
compiled.names.flatMap(_.subsections.collectFirstSome {
case FunctionNames(names) =>

val mapList = names.values
val check = mapList.exists(j => {j == func_name})
if(!check){
System.err.println("Function name does not exists.")
sys.exit(1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at how this is handled in a CommandIOApp. You never should directly exit in this way

Copy link

@tareq97-zz tareq97-zz Aug 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked with ExitCode.Error but probably in my code, it was not stopping the execution at that point. But checked you refactored code and understood that the exit code needs to return so that CommandIOApp can capture it and tell the status whether the status of execution is Success or Error

}
names.get(typeIndex)
case _ =>
None
})
functionName match {
case Some(x) => {
if(x == func_name){
println(s"This is function name : $func_name")
println(s"This is param names : ${tpe.params}")
val mapping = tpe.params.map(y => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lambda body can be replaced by removing the y => part

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed lambda body as part of the commit 2022710

y match {
case ValType.I32 => "Int32"
case ValType.I64 => "Int64"
case ValType.F32 => "Float32"
case ValType.F64 => "Float64"
}
})
val resultParams = mapping.mkString(",")
if(resultParams == ""){
println("void")
}
println(resultParams)
}
}
case None => {
println(s"The function name does not exists.")
}
}

case _ => None
}
})
_ <- IO(Infer)
//_ <- IO(println(module))
} yield ExitCode.Success
case Compile(file, out, debug) =>
for {
Expand Down