Przeglądaj źródła

we can now quote with '

master
FelixBrendel 7 lat temu
rodzic
commit
d55e71396a
3 zmienionych plików z 45 dodań i 23 usunięć
  1. +16
    -6
      bin/pre.slime
  2. +19
    -4
      src/parse.c
  3. +10
    -13
      todo.org

+ 16
- 6
bin/pre.slime Wyświetl plik

@@ -5,12 +5,22 @@
"Checks if the argument is nil." "Checks if the argument is nil."
(= x nil))) (= x nil)))


(define append
(lambda (obj sequence)
(if (nil? sequence)
(list obj)
(if (nil? (rest sequence))
))))
(define last
(lambda (seq)
"Returns the last element of the given sequence."
(if (nil? seq)
seq
(if (not (= (type (rest seq)) :pair))
(first seq)
(last (rest seq))))))

(define n-times
(lambda (times action)
(if (<= times 0)
nil
(prog
(eval action)
(n-times (- 1 times) action)))))


(define range (define range
(lambda (:keys from :defaults-to 0 to) (lambda (:keys from :defaults-to 0 to)


+ 19
- 4
src/parse.c Wyświetl plik

@@ -164,12 +164,27 @@ Ast_Node* parse_atom(char* text, int* index_in_text) {
} }


Ast_Node* parse_expression(char* text, int* index_in_text) { Ast_Node* parse_expression(char* text, int* index_in_text) {
// okay we know the text under the index is '('
if (text[*index_in_text] == '\'') {
++(*index_in_text);
Ast_Node* result;
if (text[*index_in_text] == '(' || text[*index_in_text] == '\'' ) {
try {
result = parse_expression(text, index_in_text);
}
} else {
try {
result = parse_atom(text, index_in_text);
}
}
return create_ast_node_pair(
create_ast_node_symbol("quote"),
create_ast_node_pair(result, create_ast_node_nil()));
}
++(*index_in_text); ++(*index_in_text);


eat_whitespace(text, index_in_text); eat_whitespace(text, index_in_text);


// if there was actually nothing in the list return nil
// if there was actually nothing in the list, return nil
if (text[(*index_in_text)] == ')') { if (text[(*index_in_text)] == ')') {
++(*index_in_text); ++(*index_in_text);
return create_ast_node_nil(); return create_ast_node_nil();
@@ -182,7 +197,7 @@ Ast_Node* parse_expression(char* text, int* index_in_text) {
Ast_Node* expression = head; Ast_Node* expression = head;


while (true) { while (true) {
if (text[(*index_in_text)] == '(') {
if (text[(*index_in_text)] == '(' || text[(*index_in_text)] == '\'' ) {
head->value.pair->first = parse_expression(text, index_in_text); head->value.pair->first = parse_expression(text, index_in_text);
} else { } else {
head->value.pair->first = parse_atom(text, index_in_text); head->value.pair->first = parse_atom(text, index_in_text);
@@ -226,7 +241,7 @@ Ast_Node* parse_single_expression(char* text) {
int index_in_text = 0; int index_in_text = 0;
Ast_Node* result; Ast_Node* result;
eat_until_code(text, &index_in_text); eat_until_code(text, &index_in_text);
if (text[(index_in_text)] == '(')
if (text[(index_in_text)] == '(' || text[(index_in_text)] == '\'' )
result = parse_expression(text, &index_in_text); result = parse_expression(text, &index_in_text);
else else
result = parse_atom(text, &index_in_text); result = parse_atom(text, &index_in_text);


+ 10
- 13
todo.org Wyświetl plik

@@ -208,8 +208,8 @@ set to see if we are in an errornious state.
CLOSED: [2018-09-18 Di 12:14] CLOSED: [2018-09-18 Di 12:14]
** TODO > ** TODO >
** TODO < ** TODO <
** TODO =
** DONE =
CLOSED: [2018-10-21 So 00:25]
** DONE if ** DONE if
CLOSED: [2018-09-18 Di 12:14] CLOSED: [2018-09-18 Di 12:14]
** DONE and (short circuiting) ** DONE and (short circuiting)
@@ -235,11 +235,16 @@ set to see if we are in an errornious state.
** DONE pair (cons) ** DONE pair (cons)
CLOSED: [2018-10-08 Mo 20:28] CLOSED: [2018-10-08 Mo 20:28]


** TODO load (import)
** DONE load (import)
CLOSED: [2018-10-21 So 00:25]
** DONE define ** DONE define
CLOSED: [2018-10-08 Mo 20:28] CLOSED: [2018-10-08 Mo 20:28]
** TODO lambda
** TODO progn
** TODO mutateW
** DONE lambda
CLOSED: [2018-10-21 So 00:25]
** TODO macro
** DONE prog
CLOSED: [2018-10-21 So 00:25]
** DONE eval ** DONE eval
CLOSED: [2018-10-08 Mo 20:28] CLOSED: [2018-10-08 Mo 20:28]


@@ -276,11 +281,3 @@ set to see if we are in an errornious state.
CLOSED: [2018-10-08 Mo 21:30] CLOSED: [2018-10-08 Mo 21:30]


** TODO info ** TODO info

* Types
- Symbol
- Number
- String
- pair (cons-cell)
- lambda function lambda
- built-in function

Ładowanie…
Anuluj
Zapisz