Skip to content

Commit

Permalink
Merge pull request #7 from willcipriano/develop
Browse files Browse the repository at this point in the history
Create version 0.0.2
  • Loading branch information
willcipriano authored May 1, 2021
2 parents 2a1f8b8 + f245a59 commit 8db594d
Show file tree
Hide file tree
Showing 28 changed files with 481 additions and 159 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Project exclude paths
/cmake-build-debug/
.idea
/.idea/*
/.idea/*
cmake_install.cmake
CMakeCache.txt
Connery
Makefile
/CMakeFiles/
7 changes: 7 additions & 0 deletions .run/Connery [test.connery].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Connery [test.connery]" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="test.connery" REDIRECT_INPUT="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Connery" TARGET_NAME="Connery" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Connery" RUN_TARGET_NAME="Connery">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>
7 changes: 7 additions & 0 deletions .run/Connery.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Connery" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Connery" TARGET_NAME="Connery" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Connery" RUN_TARGET_NAME="Connery">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>
8 changes: 8 additions & 0 deletions .run/local.run.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="local.run" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Buildfile" target="local.run" workingDirectory="" arguments="">
<envs />
</makefile>
<method v="2" />
</configuration>
</component>
29 changes: 29 additions & 0 deletions Buildfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local.install:
sudo apt-get -y install build-essential
sudo apt-get -y install cmake
sudo apt-get -y install libcurl4-openssl-dev
sudo apt-get -y install libedit-dev

local.build:
cmake src/.
make Connery

local.clean:
make clean || true
rm cmake_install.cmake || true
rm CMakeCache.txt || true
rm -r CMakeFiles || true
rm -r stdlib || true
rm Makefile || true

local.run:
./Connery || cmake src/. && make Connery && ./Connery || sudo apt-get -y install build-essential; sudo apt-get -y install cmake; sudo apt-get -y install libcurl4-openssl-dev; sudo apt-get -y install libedit-dev; cmake src/. && make Connery && ./Connery || echo "There is nothing like a challenge to bring out the best in man."

docker.build:
docker build --tag connerylang .

docker.clean:
docker rmi connerylang --force

docker.run:
docker run -it connerylang || docker build --tag connerylang . && docker run -it connerylang
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ RUN apt-get -y install libedit-dev
WORKDIR /Connery
COPY src/. .
RUN cmake .
ENTRYPOINT "./cmake-build-debug/Connery" && /bin/bash
RUN cmake --build .
ENTRYPOINT "./Connery" && /bin/bash
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,23 @@
<img width="368" height="414.5" src="http://connerylang.org/img/ConneryLogo.jpg">
</p>
<p align="center">Connery is a experimental lisp-like interpreted programming language that is somewhat themed after veteran actor Sean Connery.</p>
<p align="center"><i>Version 0.0.1</i></p>
<p align="center"><a href="http://connerylang.org">ConneryLang.org</a></p>
<p align="center"><a href="http://connerylang.org">ConneryLang.org</a></p>

## Building and running Connery
The best way to get up and running is clone this repo and allow the Dockerfile to pull all the dependencies for you. This method will drop you right into the Connery REPL.
```
1. git clone https://github.com/willcipriano/Connery.git
2. cd Connery
3. docker build --tag connery .
4. docker run -it connery
```
## Documentation
All documentation is located at <a href="http://connerylang.org">ConneryLang.org</a>

## Credits
Connery is based on the work of [Daniel Holden](http://www.theorangeduck.com/page/about), his fantastic book [Build Your Own Lisp](http://www.buildyourownlisp.com/) and library [mpc](https://github.com/orangeduck/mpc). It is also inspired by [ArnoldC](https://lhartikk.github.io/ArnoldC/) as well as countless other joke programming languages. It was created by [Will Cipriano](https://thoughts.willcipriano.com/contact/).

![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/willcipriano/connery?style=for-the-badge)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/willcipriano/Connery?style=for-the-badge)
![Website](https://img.shields.io/website?style=for-the-badge&url=http%3A%2F%2Fconnerylang.org)
![Travis (.org)](https://img.shields.io/travis/willcipriano/Connery?style=for-the-badge)
30 changes: 30 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

connery_install_path=$(eval echo ~$user);
export CONNERY_INSTALL_PATH=$connery_install_path;
export CONNERY_PATH=$connery_install_path"/Connery"

pushd ./

cd "$CONNERY_INSTALL_PATH" || exit &&
git clone --single-branch --branch feature/traceback_system https://github.com/willcipriano/Connery.git


cd "$CONNERY_PATH" || exit &&
make -f Buildfile local.install ; make -f Buildfile local.build

rm Buildfile || true ;
rm CMakeCache.txt || true ;
rm -rf CMakeFiles || true ;
rm cmake_install.cmake || true ;
rm Dockerfile || true ;
rm -rf Makefile || true ;
rm -rf src || true ;

export PATH=$PATH:$CONNERY_PATH






2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_C_STANDARD 99)
set(CURL_LIBRARY "-lcurl")
find_package(CURL REQUIRED)

add_executable(Connery main.c mpc.c util.c util.h hashtable.c hashtable.h cval.h cval.c)
add_executable(Connery main.c mpc.c util.c util.h hashtable.c hashtable.h cval.h cval.c trace.c trace.h)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(Connery PRIVATE /usr/lib/x86_64-linux-gnu/libedit.so ${CURL_LIBRARIES})

Expand Down
80 changes: 67 additions & 13 deletions src/cval.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "cval.h"
#include "util.h"
#include "trace.h"
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>

#define ENV_HASH_TABLE_SIZE 10000
#define SYSTEM_LANG 1
Expand Down Expand Up @@ -39,6 +42,7 @@ char* ctype_name(int t) {
case CVAL_Q_EXPRESSION: return "Q-Expression";
case CVAL_STRING: return "String";
case CVAL_FLOAT: return "Float";
case CVAL_BOOLEAN: return "Boolean";
default: return "Unknown Type";
}
}
Expand All @@ -50,6 +54,15 @@ cval* cval_function(cbuiltin func) {
return v;
}

cval *cval_boolean(bool b) {
cval *value = malloc(sizeof(cval));
value->type = CVAL_BOOLEAN;
value->boolean = b;
value->count = 0;
value->cell = NULL;
return value;
}

cval* cval_number(long x) {
cval* value = malloc(sizeof(cval));
value->type = CVAL_NUMBER;
Expand Down Expand Up @@ -243,6 +256,11 @@ cval* cval_copy(cval* v) {
x->str = malloc(strlen(v->str) + 1);
strcpy(x->str, v->str);
break;


case CVAL_BOOLEAN:
x->boolean = v->boolean;
break;
}

return x;
Expand Down Expand Up @@ -347,11 +365,10 @@ cval* cval_evaluate_s_expression(cenv* env, cval* value) {

cval* f = cval_pop(value, 0);
if (f->type != CVAL_FUNCTION) {
cval* err = cval_error("S-Expression starts with incorrect type. Got %s, Expected %s", ctype_name(f->type), ctype_name(CVAL_FUNCTION));
cval_delete(f);
cval_delete(value);
return err;
}
if (f->type == CVAL_S_EXPRESSION) {
return cval_evaluate_s_expression(env, f);
}
}

cval* result = cval_call(env, f, value);
cval_delete(f);
Expand Down Expand Up @@ -392,6 +409,7 @@ void cenv_add_builtin(cenv* e, char* name, cbuiltin func) {
cval_delete(v);
}


void cenv_def(cenv* e, cval* k, cval* v) {
while (e->par) {
e = e->par;
Expand Down Expand Up @@ -441,6 +459,13 @@ cval* cval_join(cval* x, cval* y) {
return x;
}

cval *cval_read_boolean(mpc_ast_t *t) {
if (strstr(t->contents, "True")) {
return cval_boolean(true);
}
return cval_boolean(false);
}

cval* cval_read_num(mpc_ast_t* t) {
errno = 0;
long x = strtol(t->contents, NULL, 10);
Expand All @@ -465,8 +490,23 @@ cval* cval_read_string(mpc_ast_t* t) {
return str;
}

cval *cval_read_symbol(char *symbol) {

if (strcmp(symbol, "True") == 0) {
return cval_boolean(true);
} else if (strcmp(symbol, "False") == 0) {
return cval_boolean(false);
} else {
return cval_symbol(symbol);
}
}

cval* cval_read(mpc_ast_t* t) {

if (strstr(t->tag, "boolean")) {
return cval_read_boolean(t);
}

if (strstr(t->tag, "number")) {
return cval_read_num(t);
}
Expand All @@ -476,7 +516,7 @@ cval* cval_read(mpc_ast_t* t) {
}

if (strstr(t->tag, "symbol")) {
return cval_symbol(t->contents);
return cval_read_symbol(t->contents);
}

cval* x = NULL;
Expand Down Expand Up @@ -522,7 +562,7 @@ void cval_print_str(cval* v) {
char* escaped = malloc(strlen(v->str)+1);
strcpy(escaped, v->str);
escaped = mpcf_escape(escaped);
printf("\"%s\"", escaped);
printf("%s", v->str);
free(escaped);
}

Expand All @@ -534,7 +574,8 @@ void cval_print_ht_str(cval* v, char* key) {
free(escaped);
}

void cval_expr_print(cval* value, char open, char close) {
bool cval_expr_print(cval* value, char open, char close) {
if (value->count >= 1) {
putchar(open);
for (int i = 0; i < value->count; i++) {
cval_print(value->cell[i]);
Expand All @@ -543,6 +584,8 @@ void cval_expr_print(cval* value, char open, char close) {
}
}
putchar(close);
return true;}
return false;
}

void cval_expr_ht_print(cval* value, char open, char close, char* key) {
Expand All @@ -559,8 +602,18 @@ void cval_expr_ht_print(cval* value, char open, char close, char* key) {
}


void cval_print(cval* value) {
bool cval_print(cval* value) {
switch (value->type) {

case CVAL_BOOLEAN:
if (value->boolean) {
printf("True");
} else {
printf("False");
}
break;


case CVAL_NUMBER:
printf("%li", value->num);
break;
Expand Down Expand Up @@ -594,8 +647,7 @@ void cval_print(cval* value) {
break;

case CVAL_S_EXPRESSION:
cval_expr_print(value, '(', ')');
break;
return cval_expr_print(value, '(', ')');

case CVAL_Q_EXPRESSION:
cval_expr_print(value, '{', '}');
Expand All @@ -605,9 +657,11 @@ void cval_print(cval* value) {
cval_print_str(value);
break;
}

return true;
}
void cval_print_line(cval* value) {
cval_print(value);
putchar('\n');
if (cval_print(value)) {
putchar('\n'); }
}

11 changes: 8 additions & 3 deletions src/cval.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CONNERY_CVAL_H
#define CONNERY_CVAL_H

#include <stdbool.h>
#include "mpc.h"
#include "hashtable.h"

Expand All @@ -11,7 +12,8 @@ typedef cval *(*cbuiltin)(cenv *, cval *);

enum {
CVAL_NUMBER, CVAL_ERROR, CVAL_SYMBOL, CVAL_FUNCTION,
CVAL_S_EXPRESSION, CVAL_Q_EXPRESSION, CVAL_STRING, CVAL_FLOAT
CVAL_S_EXPRESSION, CVAL_Q_EXPRESSION, CVAL_STRING, CVAL_FLOAT,
CVAL_BOOLEAN
};

struct cval {
Expand All @@ -22,6 +24,7 @@ struct cval {
char *err;
char *sym;
char *str;
bool boolean;
hash_table *ht;

cbuiltin builtin;
Expand Down Expand Up @@ -52,6 +55,8 @@ cval *cval_error(char *fmt, ...);

cval *cval_symbol(char *s);

cval *cval_boolean(bool b);

cval *cval_s_expression(void);

cval *cval_q_expression(void);
Expand Down Expand Up @@ -82,9 +87,9 @@ cval *cval_read(mpc_ast_t *t);

void cval_print_line(cval *value);

void cval_expr_print(cval *value, char open, char close);
bool cval_expr_print(cval *value, char open, char close);

void cval_print(cval *value);
bool cval_print(cval *value);

void cval_print_ht_str(cval *v, char *key);

Expand Down
Loading

0 comments on commit 8db594d

Please sign in to comment.