1
0
Fork 0

Rename project

This commit is contained in:
Alex Kotov 2023-05-06 22:31:07 +04:00
parent 1b7ffcfaad
commit 1e76dd59a5
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
16 changed files with 116 additions and 114 deletions

4
.gitignore vendored
View file

@ -1,5 +1,5 @@
/arcane-scheme-lisp /arcana-lisp
/arcane-scheme-lisp-test /arcana-lisp-test
/src/*.o /src/*.o
/tests/*.out /tests/*.out

View file

@ -21,7 +21,7 @@ TEST_OUTS = \
tests/arithm_ops.out \ tests/arithm_ops.out \
tests/basic_data_structs.out \ tests/basic_data_structs.out \
tests/hello.out \ tests/hello.out \
tests/arcane.out \ tests/arcana.out \
tests/equiv.out \ tests/equiv.out \
tests/logic_ops.out \ tests/logic_ops.out \
tests/syntax.out \ tests/syntax.out \
@ -31,15 +31,15 @@ TEST_OUTS = \
MAIN_OBJS = $(OBJS) src/main.c.o MAIN_OBJS = $(OBJS) src/main.c.o
TEST_OBJS = $(OBJS) src/main-test.c.o TEST_OBJS = $(OBJS) src/main-test.c.o
repl: arcane-scheme-lisp repl: arcana-lisp
./arcane-scheme-lisp ./arcana-lisp
test: arcane-scheme-lisp-test $(TEST_OUTS) test: arcana-lisp-test $(TEST_OUTS)
./arcane-scheme-lisp-test ./arcana-lisp-test
$(DIFF_Q) tests/arithm_ops.txt tests/arithm_ops.out $(DIFF_Q) tests/arithm_ops.txt tests/arithm_ops.out
$(DIFF_Q) tests/basic_data_structs.txt tests/basic_data_structs.out $(DIFF_Q) tests/basic_data_structs.txt tests/basic_data_structs.out
$(DIFF_Q) tests/hello.txt tests/hello.out $(DIFF_Q) tests/hello.txt tests/hello.out
$(DIFF_Q) tests/arcane.txt tests/arcane.out $(DIFF_Q) tests/arcana.txt tests/arcana.out
$(DIFF_Q) tests/equiv.txt tests/equiv.out $(DIFF_Q) tests/equiv.txt tests/equiv.out
$(DIFF_Q) tests/logic_ops.txt tests/logic_ops.out $(DIFF_Q) tests/logic_ops.txt tests/logic_ops.out
$(DIFF_Q) tests/syntax.txt tests/syntax.out $(DIFF_Q) tests/syntax.txt tests/syntax.out
@ -47,16 +47,16 @@ test: arcane-scheme-lisp-test $(TEST_OUTS)
$(DIFF_Q) tests/type_preds.txt tests/type_preds.out $(DIFF_Q) tests/type_preds.txt tests/type_preds.out
clean: clean:
$(RM_F) arcane-scheme-lisp arcane-scheme-lisp-test $(MAIN_OBJS) $(TEST_OBJS) $(TEST_OUTS) $(RM_F) arcana-lisp arcana-lisp-test $(MAIN_OBJS) $(TEST_OBJS) $(TEST_OUTS)
arcane-scheme-lisp: $(MAIN_OBJS) arcana-lisp: $(MAIN_OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(CC) -o $@ $^ $(CFLAGS)
arcane-scheme-lisp-test: $(TEST_OBJS) arcana-lisp-test: $(TEST_OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(CC) -o $@ $^ $(CFLAGS)
%.c.o: %.c %.c.o: %.c
$(CC) -c $< -o $@ $(CFLAGS) $(CC) -c $< -o $@ $(CFLAGS)
tests/%.out: tests/%.scm arcane-scheme-lisp tests/%.out: tests/%.scm arcana-lisp
$(CAT) $< | ./arcane-scheme-lisp > $@ $(CAT) $< | ./arcana-lisp > $@

View file

@ -11,10 +11,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// Arcane Scheme Lisp internals // Arcana Lisp internals
static struct Object *func_arcane_SLASH_parse(size_t args_count, struct Object **args_array); static struct Object *func_arcana_SLASH_parse(size_t args_count, struct Object **args_array);
static struct Object *func_arcane_SLASH_tokenize(size_t args_count, struct Object **args_array); static struct Object *func_arcana_SLASH_tokenize(size_t args_count, struct Object **args_array);
static struct Object *func_arcane_SLASH_typeof(size_t args_count, struct Object **args_array); static struct Object *func_arcana_SLASH_typeof(size_t args_count, struct Object **args_array);
// Basic data structures // Basic data structures
static struct Object *func_car(size_t args_count, struct Object **args_array); static struct Object *func_car(size_t args_count, struct Object **args_array);
static struct Object *func_cdr(size_t args_count, struct Object **args_array); static struct Object *func_cdr(size_t args_count, struct Object **args_array);
@ -47,10 +47,10 @@ static struct Object *func_displayln(size_t args_count, struct Object **args_arr
static struct Object *func_newline(size_t args_count, struct Object **args_array); static struct Object *func_newline(size_t args_count, struct Object **args_array);
static struct Object builtins[] = { static struct Object builtins[] = {
// Arcane Scheme Lisp internals // Arcana Lisp internals
{ .type = TYPE_PROCEDURE, .procedure = { "arcane/parse", func_arcane_SLASH_parse } }, { .type = TYPE_PROCEDURE, .procedure = { "arcana/parse", func_arcana_SLASH_parse } },
{ .type = TYPE_PROCEDURE, .procedure = { "arcane/tokenize", func_arcane_SLASH_tokenize } }, { .type = TYPE_PROCEDURE, .procedure = { "arcana/tokenize", func_arcana_SLASH_tokenize } },
{ .type = TYPE_PROCEDURE, .procedure = { "arcane/typeof", func_arcane_SLASH_typeof } }, { .type = TYPE_PROCEDURE, .procedure = { "arcana/typeof", func_arcana_SLASH_typeof } },
// Basic data structures // Basic data structures
{ .type = TYPE_PROCEDURE, .procedure = { "car", func_car } }, { .type = TYPE_PROCEDURE, .procedure = { "car", func_car } },
{ .type = TYPE_PROCEDURE, .procedure = { "cdr", func_cdr } }, { .type = TYPE_PROCEDURE, .procedure = { "cdr", func_cdr } },
@ -96,11 +96,11 @@ struct Object *builtins_get(const char *name)
return NULL; return NULL;
} }
/******************************** /*************************
* Arcane Scheme Lisp internals * * Arcana Lisp internals *
********************************/ *************************/
struct Object *func_arcane_SLASH_parse( struct Object *func_arcana_SLASH_parse(
size_t args_count, size_t args_count,
struct Object **args_array struct Object **args_array
) { ) {
@ -162,7 +162,7 @@ struct Object *func_arcane_SLASH_parse(
return program; return program;
} }
struct Object *func_arcane_SLASH_tokenize( struct Object *func_arcana_SLASH_tokenize(
const size_t args_count, const size_t args_count,
struct Object **const args_array struct Object **const args_array
) { ) {
@ -222,7 +222,7 @@ struct Object *func_arcane_SLASH_tokenize(
return list; return list;
} }
struct Object *func_arcane_SLASH_typeof( struct Object *func_arcana_SLASH_typeof(
const size_t args_count, const size_t args_count,
struct Object **const args_array struct Object **const args_array
) { ) {

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_BUILTINS_H__ #ifndef __ARCANA_LISP_BUILTINS_H__
#define __ARCANE_SCHEME_LISP_BUILTINS_H__ #define __ARCANA_LISP_BUILTINS_H__
#include "object.h" #include "object.h"

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_CTYPE_H__ #ifndef __ARCANA_LISP_CTYPE_H__
#define __ARCANE_SCHEME_LISP_CTYPE_H__ #define __ARCANA_LISP_CTYPE_H__
#include <stdbool.h> #include <stdbool.h>

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_EVAL_H__ #ifndef __ARCANA_LISP_EVAL_H__
#define __ARCANE_SCHEME_LISP_EVAL_H__ #define __ARCANA_LISP_EVAL_H__
#include "object.h" #include "object.h"

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_LEXER_H__ #ifndef __ARCANA_LISP_LEXER_H__
#define __ARCANE_SCHEME_LISP_LEXER_H__ #define __ARCANA_LISP_LEXER_H__
#include "tokens.h" #include "tokens.h"

View file

@ -11,9 +11,9 @@ static struct Object *result = NULL;
static void test_begin(); static void test_begin();
static void test_if(); static void test_if();
static void test_quote(); static void test_quote();
// Arcane Scheme Lisp internals // Arcana Lisp internals
static void test_arcane_SLASH_tokenize(); static void test_arcana_SLASH_tokenize();
static void test_arcane_SLASH_typeof(); static void test_arcana_SLASH_typeof();
// Basic data structures // Basic data structures
static void test_car(); static void test_car();
static void test_cdr(); static void test_cdr();
@ -44,9 +44,9 @@ int main()
test_begin(); test_begin();
test_if(); test_if();
test_quote(); test_quote();
// Arcane Scheme Lisp internals // Arcana Lisp internals
test_arcane_SLASH_tokenize(); test_arcana_SLASH_tokenize();
test_arcane_SLASH_typeof(); test_arcana_SLASH_typeof();
// Basic data structures // Basic data structures
test_car(); test_car();
test_cdr(); test_cdr();
@ -259,15 +259,15 @@ void test_quote()
assert(result->pair.cdr->pair.cdr->pair.car->number.i64 == 456); assert(result->pair.cdr->pair.cdr->pair.car->number.i64 == 456);
} }
/******************************** /*************************
* Arcane Scheme Lisp internals * * Arcana Lisp internals *
********************************/ *************************/
void test_arcane_SLASH_tokenize() void test_arcana_SLASH_tokenize()
{ {
// (arcane/tokenize "(") // (arcana/tokenize "(")
// ((TOKEN_ROUND_OPEN . "")) // ((TOKEN_ROUND_OPEN . ""))
result = eval_str("(arcane/tokenize \"(\")"); result = eval_str("(arcana/tokenize \"(\")");
assert(Object_is_pair(result)); assert(Object_is_pair(result));
assert(OBJECT_IS_NULL(result->pair.cdr)); assert(OBJECT_IS_NULL(result->pair.cdr));
assert(Object_is_pair(result->pair.car)); assert(Object_is_pair(result->pair.car));
@ -276,9 +276,9 @@ void test_arcane_SLASH_tokenize()
assert(strcmp(result->pair.car->pair.car->s, "TOKEN_ROUND_OPEN") == 0); assert(strcmp(result->pair.car->pair.car->s, "TOKEN_ROUND_OPEN") == 0);
assert(strcmp(result->pair.car->pair.cdr->s, "(") == 0); assert(strcmp(result->pair.car->pair.cdr->s, "(") == 0);
// (arcane/tokenize "#false") // (arcana/tokenize "#false")
// ((TOKEN_TAG . "false")) // ((TOKEN_TAG . "false"))
result = eval_str("(arcane/tokenize \"#false\")"); result = eval_str("(arcana/tokenize \"#false\")");
assert(Object_is_pair(result)); assert(Object_is_pair(result));
assert(OBJECT_IS_NULL(result->pair.cdr)); assert(OBJECT_IS_NULL(result->pair.cdr));
assert(Object_is_pair(result->pair.car)); assert(Object_is_pair(result->pair.car));
@ -287,11 +287,11 @@ void test_arcane_SLASH_tokenize()
assert(strcmp(result->pair.car->pair.car->s, "TOKEN_TAG") == 0); assert(strcmp(result->pair.car->pair.car->s, "TOKEN_TAG") == 0);
assert(strcmp(result->pair.car->pair.cdr->s, "false") == 0); assert(strcmp(result->pair.car->pair.cdr->s, "false") == 0);
// (arcane/tokenize "\"\"") // (arcana/tokenize "\"\"")
// ((TOKEN_STRING . "")) // ((TOKEN_STRING . ""))
result = eval(Object_build_list( result = eval(Object_build_list(
2, 2,
Object_new_symbol("arcane/tokenize"), Object_new_symbol("arcana/tokenize"),
Object_new_string("\"\"") Object_new_string("\"\"")
)); ));
assert(Object_is_pair(result)); assert(Object_is_pair(result));
@ -302,11 +302,11 @@ void test_arcane_SLASH_tokenize()
assert(strcmp(result->pair.car->pair.car->s, "TOKEN_STRING") == 0); assert(strcmp(result->pair.car->pair.car->s, "TOKEN_STRING") == 0);
assert(strcmp(result->pair.car->pair.cdr->s, "") == 0); assert(strcmp(result->pair.car->pair.cdr->s, "") == 0);
// (arcane/tokenize "\"qwe\"") // (arcana/tokenize "\"qwe\"")
// ((TOKEN_STRING . "")) // ((TOKEN_STRING . ""))
result = eval(Object_build_list( result = eval(Object_build_list(
2, 2,
Object_new_symbol("arcane/tokenize"), Object_new_symbol("arcana/tokenize"),
Object_new_string("\"qwe\"") Object_new_string("\"qwe\"")
)); ));
assert(Object_is_pair(result)); assert(Object_is_pair(result));
@ -317,9 +317,9 @@ void test_arcane_SLASH_tokenize()
assert(strcmp(result->pair.car->pair.car->s, "TOKEN_STRING") == 0); assert(strcmp(result->pair.car->pair.car->s, "TOKEN_STRING") == 0);
assert(strcmp(result->pair.car->pair.cdr->s, "qwe") == 0); assert(strcmp(result->pair.car->pair.cdr->s, "qwe") == 0);
// (arcane/tokenize "(displayln (list 1))") // (arcana/tokenize "(displayln (list 1))")
// ((TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "displayln") (TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "list") (TOKEN_NUM . "1") (TOKEN_ROUND_CLOSE . ")") (TOKEN_ROUND_CLOSE . ")")) // ((TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "displayln") (TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "list") (TOKEN_NUM . "1") (TOKEN_ROUND_CLOSE . ")") (TOKEN_ROUND_CLOSE . ")"))
result = eval_str("(arcane/tokenize \"(displayln (list 1))\")"); result = eval_str("(arcana/tokenize \"(displayln (list 1))\")");
{ {
assert(Object_is_pair(result)); assert(Object_is_pair(result));
assert(Object_is_pair(result->pair.cdr)); assert(Object_is_pair(result->pair.cdr));
@ -380,57 +380,57 @@ void test_arcane_SLASH_tokenize()
} }
} }
void test_arcane_SLASH_typeof() void test_arcana_SLASH_typeof()
{ {
// (arcane/typeof '()) // (arcana/typeof '())
// null // null
result = eval_str("(arcane/typeof '())"); result = eval_str("(arcana/typeof '())");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "null") == 0); assert(strcmp(result->s, "null") == 0);
// (arcane/typeof +) // (arcana/typeof +)
// procedure // procedure
result = eval_str("(arcane/typeof +)"); result = eval_str("(arcana/typeof +)");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "procedure") == 0); assert(strcmp(result->s, "procedure") == 0);
// (arcane/typeof (cons 123 456)) // (arcana/typeof (cons 123 456))
// pair // pair
result = eval_str("(arcane/typeof (cons 123 456))"); result = eval_str("(arcana/typeof (cons 123 456))");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "pair") == 0); assert(strcmp(result->s, "pair") == 0);
// (arcane/typeof #false) // (arcana/typeof #false)
// boolean // boolean
result = eval_str("(arcane/typeof #false)"); result = eval_str("(arcana/typeof #false)");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "boolean") == 0); assert(strcmp(result->s, "boolean") == 0);
// (arcane/typeof #\n) // (arcana/typeof #\n)
// char // char
result = eval(Object_build_list( result = eval(Object_build_list(
2, 2,
Object_new_symbol("arcane/typeof"), Object_new_symbol("arcana/typeof"),
Object_new_char('\n') Object_new_char('\n')
)); ));
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "char") == 0); assert(strcmp(result->s, "char") == 0);
// (arcane/typeof 'foo) // (arcana/typeof 'foo)
// symbol // symbol
result = eval_str("(arcane/typeof 'foo)"); result = eval_str("(arcana/typeof 'foo)");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "symbol") == 0); assert(strcmp(result->s, "symbol") == 0);
// (arcane/typeof "foo") // (arcana/typeof "foo")
// string // string
result = eval_str("(arcane/typeof \"foo\")"); result = eval_str("(arcana/typeof \"foo\")");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "string") == 0); assert(strcmp(result->s, "string") == 0);
// (arcane/typeof 123) // (arcana/typeof 123)
// number // number
result = eval_str("(arcane/typeof 123)"); result = eval_str("(arcana/typeof 123)");
assert(Object_is_symbol(result)); assert(Object_is_symbol(result));
assert(strcmp(result->s, "number") == 0); assert(strcmp(result->s, "number") == 0);
} }

View file

@ -30,6 +30,8 @@ int main()
void repl() void repl()
{ {
printf("Lisp by Causa Arcana\n\n");
while (true) { while (true) {
Tokens tokens = Tokens_new(); Tokens tokens = Tokens_new();
assert(tokens); assert(tokens);

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_OBJECT_H__ #ifndef __ARCANA_LISP_OBJECT_H__
#define __ARCANE_SCHEME_LISP_OBJECT_H__ #define __ARCANA_LISP_OBJECT_H__
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_PARSER_H__ #ifndef __ARCANA_LISP_PARSER_H__
#define __ARCANE_SCHEME_LISP_PARSER_H__ #define __ARCANA_LISP_PARSER_H__
#include "object.h" #include "object.h"
#include "tokens.h" #include "tokens.h"

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_SYNTAX_H__ #ifndef __ARCANA_LISP_SYNTAX_H__
#define __ARCANE_SCHEME_LISP_SYNTAX_H__ #define __ARCANA_LISP_SYNTAX_H__
#include "object.h" #include "object.h"

View file

@ -1,5 +1,5 @@
#ifndef __ARCANE_SCHEME_LISP_TOKENS_H__ #ifndef __ARCANA_LISP_TOKENS_H__
#define __ARCANE_SCHEME_LISP_TOKENS_H__ #define __ARCANA_LISP_TOKENS_H__
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>

31
tests/arcana.scm Normal file
View file

@ -0,0 +1,31 @@
(begin
(displayln "--- TEST: arcana/parse -----------------------------------------")
(displayln
(arcana/parse
(list
(cons 'TOKEN_ROUND_OPEN "(")
(cons 'TOKEN_IDENT "displayln")
(cons 'TOKEN_ROUND_OPEN "(")
(cons 'TOKEN_IDENT "+")
(cons 'TOKEN_NUM "123")
(cons 'TOKEN_NUM "456")
(cons 'TOKEN_ROUND_CLOSE ")")
(cons 'TOKEN_ROUND_CLOSE ")"))))
(newline)
(displayln "--- TEST: arcana/tokenize --------------------------------------")
(displayln (arcana/tokenize "("))
(displayln (arcana/tokenize "#false"))
;(displayln (arcana/tokenize "\"\""))
;(displayln (arcana/tokenize "\"qwe\""))
(displayln (arcana/tokenize "(displayln (list 1))"))
(newline)
(displayln "--- TEST: arcana/typeof ----------------------------------------")
(displayln (arcana/typeof '()))
(displayln (arcana/typeof +))
(displayln (arcana/typeof (cons 123 456)))
(displayln (arcana/typeof #false))
;(displayln (arcana/typeof #\n))
(displayln (arcana/typeof 'foo))
(displayln (arcana/typeof "foo"))
(displayln (arcana/typeof 123))
)

View file

@ -1,12 +1,12 @@
"--- TEST: arcane/parse -----------------------------------------" "--- TEST: arcana/parse -----------------------------------------"
(displayln (+ 123 456)) (displayln (+ 123 456))
"--- TEST: arcane/tokenize --------------------------------------" "--- TEST: arcana/tokenize --------------------------------------"
((TOKEN_ROUND_OPEN . "(")) ((TOKEN_ROUND_OPEN . "("))
((TOKEN_TAG . "false")) ((TOKEN_TAG . "false"))
((TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "displayln") (TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "list") (TOKEN_NUM . "1") (TOKEN_ROUND_CLOSE . ")") (TOKEN_ROUND_CLOSE . ")")) ((TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "displayln") (TOKEN_ROUND_OPEN . "(") (TOKEN_IDENT . "list") (TOKEN_NUM . "1") (TOKEN_ROUND_CLOSE . ")") (TOKEN_ROUND_CLOSE . ")"))
"--- TEST: arcane/typeof ----------------------------------------" "--- TEST: arcana/typeof ----------------------------------------"
null null
procedure procedure
pair pair

View file

@ -1,31 +0,0 @@
(begin
(displayln "--- TEST: arcane/parse -----------------------------------------")
(displayln
(arcane/parse
(list
(cons 'TOKEN_ROUND_OPEN "(")
(cons 'TOKEN_IDENT "displayln")
(cons 'TOKEN_ROUND_OPEN "(")
(cons 'TOKEN_IDENT "+")
(cons 'TOKEN_NUM "123")
(cons 'TOKEN_NUM "456")
(cons 'TOKEN_ROUND_CLOSE ")")
(cons 'TOKEN_ROUND_CLOSE ")"))))
(newline)
(displayln "--- TEST: arcane/tokenize --------------------------------------")
(displayln (arcane/tokenize "("))
(displayln (arcane/tokenize "#false"))
;(displayln (arcane/tokenize "\"\""))
;(displayln (arcane/tokenize "\"qwe\""))
(displayln (arcane/tokenize "(displayln (list 1))"))
(newline)
(displayln "--- TEST: arcane/typeof ----------------------------------------")
(displayln (arcane/typeof '()))
(displayln (arcane/typeof +))
(displayln (arcane/typeof (cons 123 456)))
(displayln (arcane/typeof #false))
;(displayln (arcane/typeof #\n))
(displayln (arcane/typeof 'foo))
(displayln (arcane/typeof "foo"))
(displayln (arcane/typeof 123))
)