Compare commits
2 Commits
a4f129b5a5
...
11d63c19f1
| Author | SHA1 | Date | |
|---|---|---|---|
| 11d63c19f1 | |||
| 9b47ce1a44 |
18
README.md
18
README.md
@@ -19,18 +19,6 @@ make release
|
||||
./scl.out
|
||||
```
|
||||
|
||||
### For Development
|
||||
|
||||
```bash
|
||||
git clone git@signorovitch.org:scl/scl --recurse-submodules && cd scl
|
||||
make all test
|
||||
./scl.out
|
||||
```
|
||||
|
||||
If you wish to run tests, make sure to run `git clone --recurse-submodules` to
|
||||
include the [Unity](https://github.com/ThrowTheSwitch/Unity) test framework.
|
||||
*Note that tests are currently in poor use. I hope to amend this in the future.*
|
||||
|
||||
## Syntax
|
||||
|
||||
SCL's syntax will feel familiar to other functional programming languages.
|
||||
@@ -41,10 +29,10 @@ SCL's syntax will feel familiar to other functional programming languages.
|
||||
> f(x) x + 1
|
||||
> f(1)
|
||||
= 2
|
||||
> (\(x) 2 * x)(5)
|
||||
= 10
|
||||
> \x, y 2 * x + y $ (2, 3)
|
||||
= 7
|
||||
> f(g) g(2)
|
||||
> f(\(x) 2 * x)
|
||||
> f(\x 2 * x)
|
||||
= 4
|
||||
```
|
||||
|
||||
|
||||
@@ -185,11 +185,12 @@ AST* builtin_eq(size_t argc, AST** argv, Scope* parent) {
|
||||
AST_TYPE_EXC, ast_exc_data_init("second was bad", second)
|
||||
);
|
||||
|
||||
if (second->type != type)
|
||||
return ast_init(
|
||||
AST_TYPE_EXC,
|
||||
ast_exc_data_init("apples and oranges or something idk", NULL)
|
||||
);
|
||||
if (second->type != type) {
|
||||
char* s = malloc(35);
|
||||
sprintf(s, "first type %d, second type %d", type, second->type);
|
||||
// free(s);
|
||||
return ast_init(AST_TYPE_EXC, ast_exc_data_init(s, NULL));
|
||||
}
|
||||
|
||||
// Later when I put together an anctual type system I'll have this
|
||||
// delegated to each type. For now this works.
|
||||
|
||||
12
src/exec.c
12
src/exec.c
@@ -3,6 +3,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "include/ast.h"
|
||||
#include "include/ast_print.h"
|
||||
#include "include/builtin.h"
|
||||
#include "include/exec.h"
|
||||
#include "include/htab.h"
|
||||
@@ -60,7 +61,9 @@ AST* exec_exp(AST* ast, Scope* parent) {
|
||||
case AST_TYPE_LAMBDA: return ast;
|
||||
case AST_TYPE_FORCE: return exec_force(ast, parent);
|
||||
case AST_TYPE_PRESERVE: return exec_preserve(ast, parent);
|
||||
default: printf("what\n"); exit(1);
|
||||
case AST_TYPE_EXC:
|
||||
return ast_init(AST_TYPE_EXC, ast_exc_data_init("Can't.", ast));
|
||||
default: printf("what : %d\n", ast->type); exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,12 +85,13 @@ AST* exec_call(AST* ast, Scope* parent) {
|
||||
|
||||
AST* exp = exec_exp(calldata->exp, parent);
|
||||
|
||||
if (exp->scope) exp->scope->inherit = parent;
|
||||
Scope* scope = scope_init(parent);
|
||||
exp->scope = scope;
|
||||
|
||||
switch (exp->type) {
|
||||
case AST_TYPE_BIF:
|
||||
return ((ASTBIFData)exp->data)(
|
||||
calldata->argc, calldata->argv, parent
|
||||
calldata->argc, calldata->argv, scope
|
||||
);
|
||||
case AST_TYPE_LAMBDA:
|
||||
return exec_lambda(
|
||||
@@ -151,7 +155,6 @@ AST* exec_ref(AST* ast, Scope* parent) {
|
||||
return ast_init(AST_TYPE_EXC, ast_exc_data_init(msg, NULL));
|
||||
}
|
||||
|
||||
// return exec_exp(found, ast->scope);
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -171,7 +174,6 @@ AST* exec_force(AST* ast, Scope* parent) {
|
||||
AST* body = ((ASTForceData*)ast->data)->body;
|
||||
|
||||
if (body->type == AST_TYPE_REF) {
|
||||
printf("forcing var\n");
|
||||
return exec_exp(exec_ref(body, parent), parent);
|
||||
} else return exec_exp(body, parent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user