Add asserts to check for the first element of the list in def and fn forms
This commit is contained in:
parent
573550ca07
commit
7c35f6a95e
|
@ -53,6 +53,9 @@ public:
|
||||||
maybe_node analyze(reader::SemanticContext &);
|
maybe_node analyze(reader::SemanticContext &);
|
||||||
|
|
||||||
static bool classof(const Expression *e);
|
static bool classof(const Expression *e);
|
||||||
|
|
||||||
|
/// Create a Def node out a list. The list should contain the
|
||||||
|
/// correct `def` form like `(def blah value)`.
|
||||||
static maybe_node make(List *);
|
static maybe_node make(List *);
|
||||||
~Def() = default;
|
~Def() = default;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,6 +57,10 @@ public:
|
||||||
maybe_node analyze(reader::SemanticContext &);
|
maybe_node analyze(reader::SemanticContext &);
|
||||||
|
|
||||||
static bool classof(const Expression *e);
|
static bool classof(const Expression *e);
|
||||||
|
|
||||||
|
/// Creates a function node out of a function definition
|
||||||
|
/// in a list. the list has to contain the correct definition
|
||||||
|
/// of a function, for exmaple: `(fn (args1 arg2) body)`
|
||||||
static maybe_node make(List *);
|
static maybe_node make(List *);
|
||||||
~Fn() = default;
|
~Fn() = default;
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,6 +54,10 @@ maybe_node Def::make(List *list) {
|
||||||
&errors::DefWrongNumberOfArgs, list->elements[0], msg));
|
&errors::DefWrongNumberOfArgs, list->elements[0], msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Symbol *defSym = llvm::dyn_cast<Symbol>(list->elements[0].get());
|
||||||
|
assert((defSym && defSym->name == "def") &&
|
||||||
|
"The first element of the list should be a 'def'.");
|
||||||
|
|
||||||
Symbol *binding = llvm::dyn_cast<Symbol>(list->elements[1].get());
|
Symbol *binding = llvm::dyn_cast<Symbol>(list->elements[1].get());
|
||||||
|
|
||||||
if (!binding) {
|
if (!binding) {
|
||||||
|
|
|
@ -56,6 +56,10 @@ maybe_node Fn::make(List *list) {
|
||||||
&errors::FnNoArgsList, list->elements[0], msg));
|
&errors::FnNoArgsList, list->elements[0], msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Symbol *fnSym = llvm::dyn_cast<Symbol>(list->elements[0].get());
|
||||||
|
assert((fnSym && fnSym->name == "fn") &&
|
||||||
|
"The first element of the list should be a 'fn'.");
|
||||||
|
|
||||||
List *args = llvm::dyn_cast<List>(list->elements[1].get());
|
List *args = llvm::dyn_cast<List>(list->elements[1].get());
|
||||||
|
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
|
Loading…
Reference in New Issue