Merge branch 'master' of https://gitlab.lrz.de/FelixBrendel/slime
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
(set-type obj type)
|
(set-type obj type)
|
||||||
obj)
|
obj)
|
||||||
|
|
||||||
(define-syntax defclass (name members :rest body)
|
(define-syntax (defclass name members :rest body)
|
||||||
"Macro for creating classes."
|
"Macro for creating classes."
|
||||||
(define (underscore sym)
|
(define (underscore sym)
|
||||||
(string->symbol (concat-strings "_" (symbol->string sym))))
|
(string->symbol (concat-strings "_" (symbol->string sym))))
|
||||||
|
|||||||
+15
-1
@@ -122,7 +122,6 @@ struct {
|
|||||||
Memory::get_or_create_lisp_object_keyword(keyword), \
|
Memory::get_or_create_lisp_object_keyword(keyword), \
|
||||||
__VA_ARGS__)
|
__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
#define create_out_of_memory_error(...) \
|
#define create_out_of_memory_error(...) \
|
||||||
__create_error("out-of-memory", __VA_ARGS__)
|
__create_error("out-of-memory", __VA_ARGS__)
|
||||||
|
|
||||||
@@ -148,6 +147,13 @@ struct {
|
|||||||
"Wrong number of arguments: expected %d, got %d", \
|
"Wrong number of arguments: expected %d, got %d", \
|
||||||
expected, actual)
|
expected, actual)
|
||||||
|
|
||||||
|
#define assert_arguments_length(expected, actual) \
|
||||||
|
do { \
|
||||||
|
if (expected != actual) { \
|
||||||
|
create_wrong_number_of_arguments_error(expected, actual); \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
#define assert_type(_node, _type) \
|
#define assert_type(_node, _type) \
|
||||||
do { \
|
do { \
|
||||||
@@ -156,6 +162,14 @@ struct {
|
|||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
#define assert_arguments_length(expected, actual) \
|
||||||
|
do { \
|
||||||
|
if (expexted != actual) { \
|
||||||
|
create_wrong_number_of_arguments_error(expected, actual); \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
#define assert(condition) \
|
#define assert(condition) \
|
||||||
do { \
|
do { \
|
||||||
if (!(condition)) { \
|
if (!(condition)) { \
|
||||||
|
|||||||
+1
-1
@@ -180,7 +180,7 @@ namespace Memory {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc create_lisp_object_string(char* str) -> Lisp_Object* {
|
proc create_lisp_object_string(const char* str) -> Lisp_Object* {
|
||||||
Lisp_Object* node = create_lisp_object();
|
Lisp_Object* node = create_lisp_object();
|
||||||
set_type(node, Lisp_Object_Type::String);
|
set_type(node, Lisp_Object_Type::String);
|
||||||
node->value.string = create_string(str);
|
node->value.string = create_string(str);
|
||||||
|
|||||||
+15
-19
@@ -356,25 +356,25 @@ namespace Parser {
|
|||||||
if (string_equal("define-syntax", expression->value.pair.first->value.identifier)) {
|
if (string_equal("define-syntax", expression->value.pair.first->value.identifier)) {
|
||||||
// create a new macro
|
// create a new macro
|
||||||
Lisp_Object* arguments = expression->value.pair.rest;
|
Lisp_Object* arguments = expression->value.pair.rest;
|
||||||
|
Lisp_Object* body;
|
||||||
int arguments_length;
|
int arguments_length;
|
||||||
|
|
||||||
// HACK(Felix): almost code duplicate from
|
// HACK(Felix): almost code duplicate from
|
||||||
// `built_ins.cpp`: special-lambda
|
// `built_ins.cpp`: special-lambda
|
||||||
try {
|
try arguments_length = list_length(arguments);
|
||||||
arguments_length = list_length(arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
// (define-syntax defun (name args :rest body) (...))
|
// (define-syntax (defun name args :rest body) (...))
|
||||||
if (arguments_length < 2) {
|
if (arguments_length < 2) {
|
||||||
create_wrong_number_of_arguments_error(3, arguments_length);
|
create_wrong_number_of_arguments_error(3, arguments_length);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_type(arguments->value.pair.first, Lisp_Object_Type::Symbol);
|
assert_type(arguments->value.pair.first, Lisp_Object_Type::Pair);
|
||||||
|
|
||||||
// extract the name
|
// extract the name
|
||||||
Lisp_Object* symbol_for_macro = arguments->value.pair.first;
|
Lisp_Object* symbol_for_macro = arguments->value.pair.first->value.pair.first;
|
||||||
arguments = arguments->value.pair.rest;
|
body = arguments->value.pair.rest;
|
||||||
|
arguments = arguments->value.pair.first->value.pair.rest;
|
||||||
|
|
||||||
// Function* function = new(Function);
|
// Function* function = new(Function);
|
||||||
Lisp_Object* macro = Memory::create_lisp_object();
|
Lisp_Object* macro = Memory::create_lisp_object();
|
||||||
@@ -383,24 +383,20 @@ namespace Parser {
|
|||||||
macro->value.function.type = Function_Type::Macro;
|
macro->value.function.type = Function_Type::Macro;
|
||||||
|
|
||||||
// if parameters were specified
|
// if parameters were specified
|
||||||
if (Memory::get_type(arguments->value.pair.first) != Lisp_Object_Type::Nil) {
|
if (arguments != Memory::nil) {
|
||||||
try {
|
try assert_type(arguments, Lisp_Object_Type::Pair);
|
||||||
assert_type(arguments->value.pair.first, Lisp_Object_Type::Pair);
|
try parse_argument_list(arguments, ¯o->value.function);
|
||||||
}
|
|
||||||
try {
|
|
||||||
parse_argument_list(arguments->value.pair.first, ¯o->value.function);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
macro->value.function.positional_arguments = create_positional_argument_list(1);
|
macro->value.function.positional_arguments = create_positional_argument_list(1);
|
||||||
macro->value.function.keyword_arguments = create_keyword_argument_list(1);
|
macro->value.function.keyword_arguments = create_keyword_argument_list(1);
|
||||||
macro->value.function.rest_argument = nullptr;
|
macro->value.function.rest_argument = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments = arguments->value.pair.rest;
|
// arguments = arguments->value.pair.rest;
|
||||||
// if there is a docstring, use it
|
// if there is a docstring, use it
|
||||||
if (Memory::get_type(arguments->value.pair.first) == Lisp_Object_Type::String) {
|
if (Memory::get_type(body->value.pair.first) == Lisp_Object_Type::String) {
|
||||||
macro->value.function.docstring = arguments->value.pair.first->value.string;
|
macro->value.function.docstring = body->value.pair.first->value.string;
|
||||||
arguments = arguments->value.pair.rest;
|
body = body->value.pair.rest;
|
||||||
} else {
|
} else {
|
||||||
macro->value.function.docstring = nullptr;
|
macro->value.function.docstring = nullptr;
|
||||||
}
|
}
|
||||||
@@ -409,7 +405,7 @@ namespace Parser {
|
|||||||
// implicit prog
|
// implicit prog
|
||||||
macro->value.function.body = Memory::create_lisp_object_pair(
|
macro->value.function.body = Memory::create_lisp_object_pair(
|
||||||
Memory::get_or_create_lisp_object_symbol("prog"),
|
Memory::get_or_create_lisp_object_symbol("prog"),
|
||||||
arguments);
|
body);
|
||||||
|
|
||||||
// macro->value.function = function;
|
// macro->value.function = function;
|
||||||
define_symbol(symbol_for_macro, macro, environment_for_macros);
|
define_symbol(symbol_for_macro, macro, environment_for_macros);
|
||||||
|
|||||||
Reference in New Issue
Block a user