Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
mkdir -p ${{ github.workspace }}/release
cp -v ${{ github.workspace }}/build/src/lisp ${{ github.workspace }}/release/
cp -v -r ${{ github.workspace }}/stdlib ${{ github.workspace }}/release/
cp -v -r ${{ github.workspace }}/src/stdlib ${{ github.workspace }}/release/
tar -czvf lisp-linux-amd64.tar.gz -C ${{ github.workspace }}/release lisp stdlib
pwd
ls -la
Expand Down
5 changes: 3 additions & 2 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ passing them to the macro. Arguments can be unquoted with `,` and `,@`.
| `and` , `or`, `not` | Boolean operators | |
| `print` , `println` | Print to command line | |
| `cons` | Create cons cell | `(cons 1 (cons 2 (cons 3 nil)))` |
| `car` | Access _car_ of _cons_ cell | `(car (cons 1 2))` |
| `cdr` | Access _cdr_ of _cons_ cell | `(cdr (cons 1 2))` |
| `car` | Access _car_ of _cons_ cell | `(car (cons 1 2))` returns `1` |
| `cdr` | Access _cdr_ of _cons_ cell | `(cdr (cons 1 2))` returns `2` |
| `append` | Concatinate lists | `(append (list 1 2 3) (list 4 5 6))` |
| `map` | Return list of elements with function applied | `(map (lambda (x) (* x x)) (list 1 2 3))` |
| `filter` `(filter pred lst)` | Return list of elements for wich pred is true | `(filter (lambda (x) (> x 1)) (list 1 2 3))` |
Expand All @@ -206,4 +206,5 @@ passing them to the macro. Arguments can be unquoted with `,` and `,@`.
| `strcmp` | Compare string | |
| `strlen` | Get length of string | |
| `strip` | Remove leading or trailing whitespace | |
| `split` | Split string on delimiteer | `(split " " "hello world")` |
| `getenv` | Get environment variable | `(getenv "HOME")` |
8 changes: 8 additions & 0 deletions src/builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,13 @@ Expr * f_symbol_name( Expr * arg, Context & context, const IO & io )

///////////////////////////////////////////////////////////////////////////////

Expr * f_dump( Expr * arg, Context & context, const IO & io )
{
return make_nil();
}

///////////////////////////////////////////////////////////////////////////////

void load( Context & ctx )
{
ctx.defvar( "+", make_native( builtin::f_add ) );
Expand Down Expand Up @@ -877,6 +884,7 @@ void load( Context & ctx )
ctx.defvar( "filter", make_native( builtin::f_filter ) );
ctx.defvar( "apply", make_native( builtin::f_apply ) );
ctx.defvar( "load", make_native( builtin::f_load ) );
ctx.defvar( "dump", make_native( builtin::f_dump ) );
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
23 changes: 8 additions & 15 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,7 @@ bool Context::is_root() const

///////////////////////////////////////////////////////////////////////////////

std::string init_script()
{
const char * home = getenv( "HOME" );
assert( home != nullptr );

std::string profile = ".profile.lsp";

return "(load \"" + std::string( home ) + "/" + profile + "\")";
}

///////////////////////////////////////////////////////////////////////////////

void eval_profile( Context & context, const IO & io )
void load_shell_macros( Context & context, const IO & io )
{
const std::string shell_macros = R"(
; test if a symbol is defined
Expand All @@ -165,6 +153,13 @@ void eval_profile( Context & context, const IO & io )
)";

( void ) eval( shell_macros, context, io );
}

///////////////////////////////////////////////////////////////////////////////

void eval_profile( Context & context, const IO & io )
{
load_shell_macros( context, io );

const char * home = getenv( "HOME" );
assert( home != nullptr );
Expand Down Expand Up @@ -730,8 +725,6 @@ int repl()

eval_profile( ctx, io );

std::cout << std::endl;

do
{
std::string line;
Expand Down
2 changes: 2 additions & 0 deletions src/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ int eval( const std::string & source, Flags flags = FLAG_NEWLINE | FLAG_INTERACT

Expr * eval_program( Expr * program, Context & context, const IO & io );

void load_shell_macros( Context & context, const IO & io );

int repl();

///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 0 additions & 2 deletions stdlib/profile.lsp → src/stdlib/profile.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
(progn
(load (strcat lib "util.lsp"))
(load (strcat lib "shell.lsp"))))

(println "Loaded profile.")
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/test_lisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,21 @@ TEST_F( LispTest, test_apply_1 )
EXPECT_EQ( err.str(), "" );
EXPECT_EQ( out.str(), "6" );
}

TEST_F( LispTest, test_split_01 )
{
std::string src = "(length (split \" \" \"this text if full of spaces\"))";
int r = eval( src, ctx, io );
EXPECT_EQ( r, 0 );
EXPECT_EQ( err.str(), "" );
EXPECT_EQ( out.str(), "6" );
}

TEST_F( LispTest, test_strip_01 )
{
std::string src = "(print (strip \" remove leading and trailing whitespace\n \"))";
int r = eval( src, ctx, io );
EXPECT_EQ( r, 0 );
EXPECT_EQ( err.str(), "" );
EXPECT_EQ( out.str(), "remove leading and trailing whitespace" );
}
27 changes: 15 additions & 12 deletions tests/test_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@

using namespace lisp;

class ShellTest : public LispTest
{
public:
void SetUp() override
{
load_shell_macros( ctx, io );
}
};

#ifdef __linux__
TEST_F( LispTest, test_shell_01 )
TEST_F( ShellTest, test_shell_01 )
{
std::string src = R"(
(load "stdlib/shell.lsp")

(defvar result
($
(pipe
(sh find "src")
(sh grep "lisp.h"))))
(sh ls "/")
(sh grep "var"))))

(print result)
)";
int r = eval( src, ctx, io );
EXPECT_EQ( err.str(), "" );
EXPECT_EQ( out.str(), "src/lisp.h" );
EXPECT_EQ( out.str(), "var" );
}

TEST_F( LispTest, test_shell_02 )
TEST_F( ShellTest, test_shell_02 )
{
std::string src = R"(
(load "stdlib/shell.lsp")

(defvar reversed
($
(pipe
Expand All @@ -41,11 +46,9 @@ TEST_F( LispTest, test_shell_02 )
EXPECT_EQ( out.str(), "dlrow olleh" );
}

TEST_F( LispTest, test_shell_03 )
TEST_F( ShellTest, test_shell_03 )
{
std::string src = R"(
(load "stdlib/shell.lsp")

(print ($ (sh uname -o)))
)";
int r = eval( src, ctx, io );
Expand Down
8 changes: 0 additions & 8 deletions tests/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ class LispTest : public ::testing::Test
{
}

void SetUp() override
{
}

void TearDown() override
{
}

protected:
Context ctx;
std::ostringstream out, err;
Expand Down
2 changes: 1 addition & 1 deletion tools/create-release.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(let ((tmp-dir (strip ($ (sh mktemp -d)))))
(and
(sh cp -v (strcat build-dir "/" "src/lisp") tmp-dir)
(sh cp -vr "stdlib" tmp-dir)
(sh cp -vr "src/stdlib" tmp-dir)
(sh tar -czvf archive-name -C tmp-dir "lisp" "stdlib")
(sh rm -rfv tmp-dir))))

Expand Down