Commit f71c6693 authored by Chris Müller's avatar Chris Müller
Browse files

Big changes

parent 49fd10de
......@@ -12,7 +12,7 @@ set(CHERRY_VERSION 0.1)
include_directories(crystal/include)
include_directories(include)
add_subdirectory(source)
#add_subdirectory(bootstrap)
#add_subdirectory(source)
add_subdirectory(bootstrap)
#add_subdirectory(test)
......@@ -6,9 +6,8 @@ set(BOOTSTRAP_SOURCES
value.c
unicode.c
tables.c
runtime.c
primitives.c)
runtime.c)
add_executable(bootstrap-cherry ${BOOTSTRAP_SOURCES})
target_link_libraries(bootstrap-cherry readline gc ssl crypto)
target_link_libraries(bootstrap-cherry readline gc)
......@@ -171,11 +171,10 @@ main(int argc, char** argv)
arguments = cherry_list_cons(cherry_string(argv[optind++]), arguments);
}
if(filename)
cherry_process_file(filename, method, cherry_list_reverse(arguments));
else
cherry_start_repl();
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
......@@ -192,57 +192,6 @@ extern struct cherry_value* cherry_symbol_begin;
extern struct cherry_value* cherry_symbol_try;
extern struct cherry_value* cherry_symbol_catch;
// org.cherry.core
struct cherry_value* cherry_core_type(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_raise(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_cons(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_list(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_is_null(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_head(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_tail(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_length(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_nth(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_map(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_list_to_string(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_list_to_tuple(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_make_list(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_make_tuple(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_string_to_list(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_string_to_fixnum(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_string_to_tuple(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_string_equal(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_tuple(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_add(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_sub(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_mul(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_div(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_not(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_and(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_or(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_greater(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_less(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_greater_equal(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_less_equal(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_core_equal(struct cherry_environment* env, struct cherry_value* args);
// org.cherry.io
struct cherry_value* cherry_io_println(struct cherry_environment* env, struct cherry_value* args);
// org.cherry.crypto
struct cherry_value* cherry_crypto_md5(struct cherry_environment* env, struct cherry_value* args);
// org.cherry.system
struct cherry_value* cherry_system_exit(struct cherry_environment* env, struct cherry_value* args);
struct cherry_value* cherry_system_time(struct cherry_environment* env, struct cherry_value* args);
// ----------------------------------------------------------------------------
// Evaluation
......
This diff is collapsed.
......@@ -58,7 +58,9 @@ cherry_error(struct cherry_context* context, const char* format, ...)
va_list args;
va_start(args, format);
if(context->filename != 0)
if(context == 0)
fprintf(stderr, "ERROR");
else if(context->filename != 0)
fprintf(stderr, "ERROR (%s:%d)", context->filename, context->line);
else
fprintf(stderr, "ERROR (console:%d)", context->line);
......
This diff is collapsed.
# Cherry bootstrap interpreter
add_executable(bootstrap-cherry bootstrap.c)
target_link_libraries(bootstrap-cherry gc)
This diff is collapsed.
/*
* Cherry programming language
* Copyright (C) 2013 Christoph Mueller
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
struct value;
#define TRUE 1
#define FALSE 0
typedef void* pointer_t;
typedef const void* const_pointer_t;
typedef uint8_t byte_t;
typedef int64_t fixnum_t;
typedef double float_t;
typedef char boolean_t;
typedef uint32_t unicode_t;
typedef struct value* (*primitive_t)(struct value* env, struct value* args);
enum tag {
EMPTYLIST, BOOLEAN, DOT, FIXNUM, FLOAT, STRING, CHARACTER,
PAIR, TUPLE, SYMBOL, PRIMITIVE, PROCEDURE, FOREIGN
};
struct value {
enum tag tag;
union {
fixnum_t fixnum_value;
float_t float_value;
unicode_t character_value;
primitive_t fun_value;
const byte_t* string_value;
const byte_t* symbol_value;
pointer_t foreign_value;
struct {
struct value* head;
struct value* tail;
} pair;
struct {
struct value** data;
size_t size;
} tuple;
struct {
struct value* env;
struct value* param;
struct value* body;
} procedure;
};
};
#define TYPE(value) (value->tag)
#define IS_NULL(value) (value->tag == EMPTYLIST)
#define IS_BOOLEAN(value) (value->tag == BOOLEAN)
#define IS_DOT(value) (value->tag == DOT)
#define IS_FIXNUM(value) (value->tag == FIXNUM)
#define IS_STRING(value) (value->tag == STRING)
#define IS_SYMBOL(value) (value->tag == SYMBOL)
#define IS_FLOAT(value) (value->tag == FLOAT)
#define IS_CHARACTER(value) (value->tag == CHARACTER)
#define IS_PAIR(value) (value->tag == PAIR)
#define IS_PRIMITIVE(value) (value->tag == PRIMITIVE)
#define IS_PROCEDURE(value) (value->tag == PROCEDURE)
#define HEAD(obj) (obj->pair.head)
#define TAIL(obj) (obj->pair.tail)
#define TUPLE_DATA(obj) (obj->tuple.data)
#define TUPLE_SIZE(obj) (obj->tuple.size)
#define PROC_PARAM(obj) (obj->procedure.param)
#define PROC_BODY(obj) (obj->procedure.body)
extern struct value* True;
extern struct value* False;
extern struct value* Emptylist;
extern struct value* Dot;
extern struct value* Let;
extern struct value* Lambda;
extern struct value* If;
extern struct value* Begin;
struct value* dup(struct value* value);
struct value* alloc_value(void);
struct value* symbol(const byte_t* symbol_value);
struct value* fixnum(fixnum_t fixnum_value);
struct value* floatpoint(float_t float_value);
struct value* character(unicode_t character_value);
struct value* string(const byte_t* string_value);
struct value* primitive(const primitive_t fun_value);
struct value* procedure(struct value* env, struct value* param, struct value* body);
struct value* foreign(pointer_t value);
struct value* tuple(size_t size, ...);
struct value* cons(struct value* head, struct value* tail);
#define list2(A, B) cons(A, cons(B, Emptylist))
#define list3(A, B, C) cons(A, cons(B, cons(C, Emptylist)))
#define list4(A, B, C, D) cons(A, cons(B, cons(C, cons(D, Emptylist))))
#define SYMBOL_ENTRY(sym, left, right) cons(sym, cons(left, right))
#define SYMBOL_LEFT(node) HEAD(TAIL(node))
#define SYMBOL_RIGHT(node) TAIL(TAIL(node))
#define EXTEND_ENV(env) cons(cons(Emptylist,Emptylist), env)
#define INITIAL_ENV EXTEND_ENV(Emptylist)
#define FIRST_FRAME(env) HEAD(env)
#define PARENT_FRAMES(env) TAIL(env)
#define FRAME_VARIABLES(frame) HEAD(frame)
#define FRAME_VALUES(frame) TAIL(frame)
struct value* env_lookup(struct value* env, struct value* var);
struct value* env_set(struct value* env, struct value* var, struct value* val);
struct value* env_let(struct value* env, struct value* var, struct value* val);
#define IS_FALSE(val) (IS_BOOLEAN(val) && !val->fixnum_value)
#define IS_TRUE(val) (!IS_FALSE(val))
#define IS_SELF_EVALUATING(val) \
(IS_BOOLEAN(val) || IS_FIXNUM(val) || IS_CHARACTER(val) || IS_STRING(val) || IS_FLOAT(val))
#define IS_TAGGED(value, symbol) \
(IS_PAIR(value) && IS_SYMBOL(HEAD(value)) && HEAD(value) == symbol)
#define IS_VARIABLE(val) IS_SYMBOL(val)
void cherry_initialize(void);
struct value* cherry_read(byte_t** begin, byte_t* buffer, size_t buffer_size);
struct value* cherry_transform(struct value* code);
struct value* cherry_eval(struct value* env, struct value* code);
void cherry_write(FILE* out, struct value* v);
void cherry_writeln(FILE* out, struct value* v);
struct value* core_println(struct value* env, struct value* args);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment