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

Dbgi Type Speciations #1404

Merged
merged 19 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix quoting arguments
Return List<OtpErlangObject>, so that caller decides whether to wrap in
OtpErlangList or not.
  • Loading branch information
KronicDeth committed Feb 28, 2019
commit 29db33ccd82dc75e28845bc88506d02533b96c47
6 changes: 6 additions & 0 deletions src/org/elixir_lang/Macro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ object Macro {
fun expr(function: String, vararg arguments: OtpErlangObject) =
expr(function, OtpErlangList(arguments))

fun expr(function: String, argumentList: List<OtpErlangObject>) =
expr(function, otpErlangList(argumentList))

fun expr(function: OtpErlangAtom, vararg arguments: OtpErlangObject) =
expr(function = function, metadata = OtpErlangList(), arguments = OtpErlangList(arguments))

fun expr(function: String, arguments: OtpErlangList) =
expr(function = OtpErlangAtom(function), metadata = OtpErlangList(), arguments = arguments)

fun expr(function: OtpErlangObject, metadata: OtpErlangList = OtpErlangList(), argumentList: List<OtpErlangObject>) =
expr(function, metadata, arguments = otpErlangList(argumentList))

fun expr(function: OtpErlangObject, metadata: OtpErlangList = OtpErlangList(), arguments: OtpErlangList) =
otpErlangTuple(function, metadata, arguments)

Expand Down
1 change: 1 addition & 0 deletions src/org/elixir_lang/MailBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.concurrent.ExecutionException
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException

fun otpErlangTuple(elementList: kotlin.collections.List<OtpErlangObject>) = OtpErlangList(elementList.toTypedArray())
fun otpErlangTuple(vararg elements: OtpErlangObject) = OtpErlangTuple(elements)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ sealed class TypeSpecification {
companion object {
private const val FORM_TYPE = "attribute"

fun argumentsToQuoted(arguments: OtpErlangList): OtpErlangList =
fun argumentsToQuoted(arguments: OtpErlangList): List<OtpErlangObject> =
arguments
.elements()
.withIndex()
.map { indexedTypeToQuoted(it) }
.let { otpErlangList(it) }

fun argumentsToString(arguments: OtpErlangList): String =
arguments.elements().withIndex().joinToString(", ") { indexedTypeToString(it) }
Expand Down Expand Up @@ -582,11 +581,11 @@ sealed class TypeSpecification {
if (moduleName is OtpErlangAtom && functionName is OtpErlangAtom) {
// `:elixir` module types are built-in types in Elixir, but not Erlang
if (moduleName.atomValue() == "elixir") {
expr(functionName, argumentsToQuoted(arguments))
expr(function = functionName, argumentList = argumentsToQuoted(arguments))
} else {
expr(
expr(".", otpErlangList(moduleName, functionName)),
arguments = argumentsToQuoted(arguments)
function = expr(".", otpErlangList(moduleName, functionName)),
argumentList = argumentsToQuoted(arguments)
)
}
} else {
Expand Down Expand Up @@ -663,8 +662,7 @@ sealed class TypeSpecification {
if (arguments is OtpErlangList) {
expr(
function = name,
metadata = OtpErlangList(),
arguments = argumentsToQuoted(arguments)
argumentList = argumentsToQuoted(arguments)
)
} else {
logger.error("""
Expand Down Expand Up @@ -948,7 +946,7 @@ sealed class TypeSpecification {
if (arguments.arity() == 0) {
expr("list")
} else {
argumentsToQuoted(arguments)
otpErlangList(argumentsToQuoted(arguments))
}
} else {
logger.error("""
Expand Down Expand Up @@ -1280,7 +1278,7 @@ sealed class TypeSpecification {
if (arguments.arity() == 2) {
otpErlangTuple(argumentsToQuoted(arguments))
} else {
expr("{}", arguments = argumentsToQuoted(arguments))
expr(function ="{}", argumentList = argumentsToQuoted(arguments))
}
} else {
logger.error("""
Expand Down Expand Up @@ -1357,8 +1355,7 @@ sealed class TypeSpecification {
if (name is OtpErlangAtom && arguments is OtpErlangList) {
expr(
function = name,
metadata = OtpErlangList(),
arguments = argumentsToQuoted(arguments)
argumentList = argumentsToQuoted(arguments)
)
} else {
logger.error("""
Expand Down