Skip to content

Commit

Permalink
Align with Joy
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Aug 21, 2023
1 parent 9f68026 commit 15223b7
Show file tree
Hide file tree
Showing 52 changed files with 1,323 additions and 853 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# module : CMakeLists.txt
# version : 1.8
# date : 07/18/23
# version : 1.10
# date : 08/21/23
#
cmake_minimum_required(VERSION 3.0)
project(Moy VERSION 1.0)
Expand All @@ -21,10 +21,11 @@ else()
FLEX_TARGET(MyScanner ${CMAKE_SOURCE_DIR}/lexr.l ${CMAKE_SOURCE_DIR}/lexr.c)
endif()
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)
add_definitions(-DCOPYRIGHT -DJVERSION="${CMAKE_BUILD_TYPE} ${CMAKE_PROJECT_VERSION}")
add_definitions(-DSYMBOLS -DCOPYRIGHT -DJVERSION="${CMAKE_BUILD_TYPE} ${CMAKE_PROJECT_VERSION}")
add_executable(joy arty.c comp.c dtim.c eval.c ${FLEX_MyScanner_OUTPUTS} main.c
manl.c modl.c parm.c ${BISON_MyParser_OUTPUTS} prog.c read.c
repl.c save.c scan.c syml.c undo.c util.c writ.c)
repl.c save.c scan.c syml.c undo.c util.c writ.c ylex.c
tokl.c)
add_dependencies(joy always)
add_custom_target(always
COMMAND sh ${CMAKE_SOURCE_DIR}/tabl.sh ${CMAKE_SOURCE_DIR}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ Directives borrowed from [42minjoy](https://github.com/Wodan58/42minjoy) are:
`%INCLUDE`, `%PUT`, and `%LISTING`.
The build system requires new builtins in only one location: as a .c file in
the src-directory.

Use cases
---------

[projecteuler.net](https://projecteuler.net), that's why the BIGNUM arithmetic
was needed. This is commented out, because it is still in development.
The stackless approach makes idiomatic Joy possible on big datasets.
103 changes: 52 additions & 51 deletions arty.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
module : arty.c
version : 1.2
date : 07/17/23
version : 1.3
date : 08/21/23
*/
#include "globals.h"

Expand All @@ -21,60 +21,61 @@ PUBLIC int arity(pEnv env, NodeList *quot, int num)
int i, j = vec_size(quot);

if (j)
vec_init(list);
vec_init(list);
for (i = 0; i < j; i++) {
node = vec_at(quot, i);
vec_push(list, node);
node = vec_at(quot, i);
vec_push(list, node);
}
prev.op = 0;
prev.u.lis = 0;
while (vec_size(list)) {
node = vec_pop(list);
switch (node.op) {
case USR_:
ent = sym_at(env->symtab, node.u.ent);
if (ent.u.body && !vec_used(ent.u.body)) {
for (i = 0, j = vec_size(ent.u.body); i < j; i++) {
node = vec_at(ent.u.body, i);
vec_push(list, node);
}
vec_setused(ent.u.body);
}
break;
case ANON_FUNCT_:
str = operarity(node.u.proc); /* problem: lineair search */
for (; *str; str++)
if (*str == 'A') /* add */
num++;
else if (*str == 'D') { /* delete */
if (--num < 0)
return -1;
} else if (*str == 'P') { /* previous */
if (prev.op == LIST_) {
for (i = 0, j = vec_size(prev.u.lis); i < j; i++) {
node = vec_at(prev.u.lis, i);
vec_push(list, node);
}
break;
}
return -1;
} else if (*str == 'U') /* unknown */
return -1;
break;
case USR_PRIME_:
case ANON_PRIME_:
case BOOLEAN_:
case CHAR_:
case INTEGER_:
case SET_:
case STRING_:
case LIST_:
case FLOAT_:
case FILE_:
num++;
break;
}
prev = node;
node = vec_pop(list);
switch (node.op) {
case USR_:
ent = sym_at(env->symtab, node.u.ent);
if (ent.u.body && !vec_used(ent.u.body)) {
for (i = 0, j = vec_size(ent.u.body); i < j; i++) {
node = vec_at(ent.u.body, i);
vec_push(list, node);
}
vec_setused(ent.u.body);
}
break;
case ANON_FUNCT_:
str = operarity(node.u.proc); /* problem: lineair search */
for (; *str; str++)
if (*str == 'A') /* add */
num++;
else if (*str == 'D') { /* delete */
if (--num < 0)
return -1;
} else if (*str == 'P') { /* previous */
if (prev.op == LIST_) {
for (i = 0, j = vec_size(prev.u.lis); i < j; i++) {
node = vec_at(prev.u.lis, i);
vec_push(list, node);
}
break;
}
return -1;
} else if (*str == 'U') /* unknown */
return -1;
break;
case USR_PRIME_:
case ANON_PRIME_:
case BOOLEAN_:
case CHAR_:
case INTEGER_:
case SET_:
case STRING_:
case LIST_:
case FLOAT_:
case FILE_:
case BIGNUM_:
num++;
break;
}
prev = node;
}
return num;
}
Loading

0 comments on commit 15223b7

Please sign in to comment.