From 50f7fd611fe922b72528319321fb9253c25d2465 Mon Sep 17 00:00:00 2001
From: GeneralGuy4872
Date: Fri, 27 Sep 2019 01:09:20 -0500
Subject: [PATCH] work on extension language, misc
---
README.md | 5 +++
manual/html/style.css | 4 +-
src/extensionlanguage/docprelim | 31 +++++++++++++++
src/extensionlanguage/extensionlang.lex | 27 +++++++------
src/extensionlanguage/extensionlang.y | 51 +++++++++++++++++++++----
src/extensionlanguage/precedanceprelim | 17 +++++++++
src/game_default_header.h | 2 +-
src/iwannaflycurses.messy | 27 +++++++++----
src/paths.h | 33 +++++++++++++---
9 files changed, 164 insertions(+), 33 deletions(-)
create mode 100644 src/extensionlanguage/docprelim
create mode 100644 src/extensionlanguage/precedanceprelim
diff --git a/README.md b/README.md
index 4687f15..d4bc565 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,11 @@ Doc Depends:
- man
- info
+Doc Meta-depends:
+- mandb
+- install-info
+- cp
+
Doc Recommends:
- xdvi
diff --git a/manual/html/style.css b/manual/html/style.css
index 0886c1e..b6e1056 100644
--- a/manual/html/style.css
+++ b/manual/html/style.css
@@ -7,8 +7,8 @@ body {
color: black;
}
blockquote {
- border-left-style: solid;
- border-width: 2px;
+ border-style: solid;
+ border-width: 1px 1px 1px 2px;
}
code {
display: inline;
diff --git a/src/extensionlanguage/docprelim b/src/extensionlanguage/docprelim
new file mode 100644
index 0000000..7f994c7
--- /dev/null
+++ b/src/extensionlanguage/docprelim
@@ -0,0 +1,31 @@
+The extension language runtime executor works in the following way:
+
+1. As code is collected, literal numbers with primative operators are optimized out bottom-up
+2. remaining collected code is used to build an execution tree, top-down
+3. ALL remaining code in a BEGIN-END block is passed to the runtime, where it is then:
+ executed from start to finish
+ freed bottom-up
+4. each BEGIN-END block is processed thus until
+
+if code is to be transpiled instead of interpreted,
+C code could will be emitted at step 3
+instead of executing the runtime.
+
+because of how the parser is constructed, it is extreamly bulky,
+and probably always will be, even if moved away from a lex/yacc toolchain.
+(so what's the point?)
+
+to reduce it's parser overhead, a program should be broken into as many
+BEGIN-END blocks as possible, as the allocated program is flushed and
+executed after END.
+
+The parser is designed to generate calls from syntactically valid code;
+this early version cares not if this code is programatically sane, however,
+leading to the probability that untested code will crash games which call
+it in varying and spectacular fashion.
+
+aside from silently dropping invalid tokens, this language has very little
+error checking, as a result of a copious use of void*. most garbage data
+would be passed streight through to the running game, where it might catch
+in the clockwork. especially bogus data might even cause the language's
+runtime to throw hard errors.
diff --git a/src/extensionlanguage/extensionlang.lex b/src/extensionlanguage/extensionlang.lex
index aaca5d6..9330ca2 100644
--- a/src/extensionlanguage/extensionlang.lex
+++ b/src/extensionlanguage/extensionlang.lex
@@ -1,7 +1,6 @@
BOOLEAN ("T"|[Tt]("RUE"|"rue")|[Nn]("IL"|"il")|[Ff]("ALSE"|"alse"))
/*not lowercase t, that might be needed*/
NAME [A-Za-z_\xC2-\xF4][A-Za-z0-9_\x80-\xBF\xC2-\xF4]*
-FUNC `[A-Za-z_\xC2-\xF4][A-Za-z0-9_\x80-\xBF\xC2-\xF4]*
VAR $([A-SU-Za-z]|[A-Za-z_\xC2-\xF4][A-Za-z0-9_\x80-\xBF\xC2-\xF4]+)
PTRVAR [\*&]+([A-SU-Za-z]|[A-Za-z_\xC2-\xF4][A-Za-z0-9_\x80-\xBF\xC2-\xF4]+)
NUMBER [0-9]+
@@ -14,8 +13,8 @@ ENDQUOTE [^\\]"
ENDPRIME [^\\]'
TEXT [.]+
CHAR [\0-\x7F]
-UTF8 ([\0xB0-\0xCF][\0x80-\0xAF]|[\0x70-\0x7F][\0x80-\0xAF][\0x80-\0xAF]|[\0xF0-\0xF7][\0x80-\0xAF][\0x80-\0xAF][\0x80-\0xAF])
-ERRVAL ([Oo][Kk]("AY"|"ay")?|[Ee]("RR"|"rr"))
+UTF8 ("\xC0\x80"|[\xC2-\xDF][\x80-\xBF]|[\x70-\x7F][\x80-\xBF][\x80-\xBF]|[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF]|[\xF8-\xFB][\x80-\xBF][\x80-\xBF][\x80-\xBF][\x80-\xBF]|[\xFC\xFD][\x80-\xBF][\x80-\xBF][\x80-\xBF][\x80-\xBF][\x80-\xBF])
+ERRVAL ([Oo][Kk]("AY"|"ay")?|[Ee]("RR"|"rr"))
STRUCTPTR ("->"|"→")
BITLEFT ("<<"|"«")
@@ -66,7 +65,7 @@ FI [Ff][Ii]
#include "y.tab.h"
%}
%s FUNC EXPR ARR
-%x STRING COMMENT CHARVAL
+%x STRING COMMENT CHARVAL TYPE
%%
"\"" yy_push_state(STRING);
{ENDQUOTE} yy_pop_state();
@@ -77,21 +76,28 @@ FI [Ff][Ii]
{CHAR} yyval.number = *yytext;return(NUMBER);
{UTF8} yyval.string = strdup(yytext);return(UTF8);
+"`" yy_push_state(TYPE);
+"`" yy_pop_state()
+"{`" yy_pop_state();return(LSTRUCT);
+{NAME} yyval.string = strdup(yytext);return(TYPENAME);
+'*' return(TYPEPTR);
+'&' return(DEREF);
+
"/*" yy_push_state(COMMENT);
+"/*" yy_push_state(COMMENT);
"*/" yy_pop_state();
{TEXT};
{WHITESPACE} return ' ';
-"(" yy_push_state(FUNC); return '(';
+"(" yy_push_state(EXPR); return '(';
")" yy_pop_state(); return ')';
- /*s-expressions and lists*/
-"{" yy_push_state(EXPR); return '{';
+
+"{" yy_push_state(ARR); return '{';
"}" yy_pop_state(); return '}';
- /*infix*/
-"[" yy_push_state(ARR); return '[';
+
+"[" yy_push_state(FUNC); return '[';
"]" yy_pop_state(); return ']';
- /*c-like functions, structs, and arrays*/
{NAME} yyval.string = strdup(yytext);return(NAME);
{VAR} yyval.string = strdup(&(yytext[1]));return(VAR);
@@ -141,7 +147,6 @@ FI [Ff][Ii]
"." return '.';
";" return ';';
"," return ',';
-"`" return '`';
"\\" return '\\';
{SWITCH} return(SWITCH)
{CASE} return(CASE);
diff --git a/src/extensionlanguage/extensionlang.y b/src/extensionlanguage/extensionlang.y
index 0ee4c84..d743e6c 100644
--- a/src/extensionlanguage/extensionlang.y
+++ b/src/extensionlanguage/extensionlang.y
@@ -1,6 +1,6 @@
-%token STRUCTPTR BITLEFT LE BITRIGHT GE LOGAND LOGOR LOGNAND LOGNOR LOGIFF LOGXOR EQ EQUALS APPROX BITNOR NE ASSIGN NULLTOK HUP SWITCH CASE IF THEN ELSE WHILE UNTIL FOR FOREVER DO AFTER BREAK RETURN FI BEGIN END
+%token LSTRUCT STRUCTPTR BITLEFT LE BITRIGHT GE LOGAND LOGOR LOGNAND LOGNOR LOGIFF LOGXOR EQ EQUALS APPROX BITNOR NE ASSIGN NULLTOK HUP SWITCH CASE IF THEN ELSE WHILE UNTIL FOR FOREVER DO AFTER BREAK RETURN FI BEGIN END
%token BOOLEAN RAW NUMBER SIGNED ERRVAL
-%token NAME VAR TEXT UTF8
+%token NAME VAR TEXT UTF8 TYPENAME
%token FLOAT NANTOK
%top {
@@ -16,6 +16,38 @@
}
%%
+cast
+ : TYPENAME {
+ $$ = malloc(sizeof(stringlistyp))
+ $$→prev = $$
+ $$→next = NULL
+ $$→text = $1
+ }
+ | cast TYPENAME {
+ $$ = $1
+ foo = malloc(sizeof(stringlistyp))
+ $$→prev→next = foo
+ foo→prev = $$→prev
+ $$→prev = foo
+ foo→next = NULL
+ foo→text = $2
+ }
+ | cast TYPEPTR {
+ $$ = $1
+ foo = malloc(sizeof(stringlistyp))
+ $$→prev→next = foo
+ foo→prev = $$→prev
+ $$→prev = foo
+ foo→next = NULL
+ foo→text = "*"
+ }
+ ;
+
+typecast
+ : cast anything {$$ = runtime__cast($1,$2)}
+ | DEREF anything {$$ = runtime__deref($2)}
+ ;
+
variable
: VAR {$$ = runtime__fetch($1)}
| variable STRUCTPTR NAME {$$ = runtime__struct_pointer($1,$3)}
@@ -98,6 +130,7 @@ expression
: anything
| literalexpression
| expression
+ | typecast
;
/* more later */
@@ -123,7 +156,7 @@ commalist
$$ = malloc(sizeof(struct runtime__list));
$$->next = malloc(sizeof(struct runtime__list));
$$->prev = $$->next;
- $$->next->next = $$;
+ $$->next->next = NULL;
$$->next->prev = $$;
$$->string = $1->string;
$$->number = $1->number;
@@ -138,7 +171,7 @@ commalist
$$->prev->next = foo;
foo->prev = $$->prev;
$$->prev = foo;
- foo->next = $$;
+ foo->next = NULL;
foo->string = $3->string;
foo->number = $3->number;
foo->ddval = $3->ddval;
@@ -174,9 +207,14 @@ spacelist
}
;
+structure
+ : cast LSTRUCT commalist '}' {$$ = runtime__queue_struct($1,$3)}
+ ;
+
array
: '{' commalist '}' {$$ = runtime__makearray($2)}
- | TEXT
+ | TEXT {$$ = $1}
+ | TEXT TEXT {$$ = strcat($1,$2)}
;
literalparenth
@@ -191,8 +229,7 @@ parenth
;
function
- : '`' NAME '`' {$$ = runtime__queue_noargs($2)}
- | NAME '[' ']' {$$ = runtime__queue_noargs($1)}
+ : NAME '[' ']' {$$ = runtime__queue_noargs($1)}
| NAME '[' anything ']' {$$ = runtime__queue($1,$3)}
| NAME '[' commalist ']' {$$ = runtime__queue_list($1,$3)}
| '(' optsp NAME optsp ')' {$$ = runtime__queue_noargs($3)}
diff --git a/src/extensionlanguage/precedanceprelim b/src/extensionlanguage/precedanceprelim
new file mode 100644
index 0000000..bc32a38
--- /dev/null
+++ b/src/extensionlanguage/precedanceprelim
@@ -0,0 +1,17 @@
+(because trees grow top-down, precedence is listed here from bottom up)
+
+← typecast
+→ postfix ++, --
+→ boolean logic
+→ equality
+→ bitwise xor, eq
+→ bitwise nand, nor
+→ addition, subtraction, bitwise or
+→ division
+→ multiplication, bitwise and
+← modulo
+← tetriation, expotentiation
+← negative, not, bitwise not, prefix ++, --
+X functions, parenthases
+
+(note: pointers and derefs are either a cast or part of the variable token itself)
\ No newline at end of file
diff --git a/src/game_default_header.h b/src/game_default_header.h
index d355a7f..0cc1814 100644
--- a/src/game_default_header.h
+++ b/src/game_default_header.h
@@ -1 +1 @@
-const char* GAMEDIR = "default/"
+#define GAMEDIR "default/"
diff --git a/src/iwannaflycurses.messy b/src/iwannaflycurses.messy
index aa1cb6b..a7459a0 100644
--- a/src/iwannaflycurses.messy
+++ b/src/iwannaflycurses.messy
@@ -325,15 +325,28 @@ char* TERM
*/
//anonomous pointers, could be anything. they're anonomous.
-void* cachedrum = malloc(1024 * sizeof(char))
-uchar cachenext = 0
+struct drum {
+ char data[FLOPPYDISK]
+ smint top
+ }
-ushort cachealloc (amount)
-uchar amount
+void* drumalloc (ptr,amount)
+struct drum ptr
+size_t amount
+{
+if ((ptr→top + amount) ≤ (FLOPPYDISK + 1)) {
+ void* output = ptr→data[ptr→top]
+ ptr→top += amount
+ return output
+ }
+else {return NULL}
+}
+
+drumpop (ptr,amount)
+struct drum ptr
+size_t amount
{
-ushort private = (((amount + cachesubscr) % 128) < cachesubscr) ? 0 : cachesubscr
-cachesubscr = private + amount
-return private
+ptr→top = MAX(ptr→top - amount,0)
}
setlocale(LC_ALL, "");
diff --git a/src/paths.h b/src/paths.h
index 0c0dba7..a311a56 100644
--- a/src/paths.h
+++ b/src/paths.h
@@ -1,7 +1,30 @@
-#define STATIC_PATH "/usr/lib/games/iwannaflycurses/"
+#define LIB_PATH "/usr/local/lib/iwannaflycurses/"
+#define SHARE_LIB_PATH "/usr/local/share/lib/iwannaflycurses"
+ //the engine's private resources
#define VAR_PATH "/var/games/iwannaflycurses/"
-#define GLOBAL_PATH "/etc/iwannaflycurses.d/"
-#define SHARE_PATH "/usr/share/games/iwannaflycurses/"
-#define DOC_PATH "/usr/share/doc/iwannaflycurses/"
-#define GAMES_PATH "/usr/games/iwannaflycurses/"
+ //saved games and high scores
+#define GLOBAL_PATH "/usr/local/share/etc/iwannaflycurses.d/"
+ //default config files
+#define LIB_GAMES_PATH "/usr/local/lib/games/iwannaflycurses/"
+#define SHARE_LIB_GAMES_PATH "/usr/local/share/lib/games/iwannaflycurses/"
+ //each game's private resources
+#define INSTALL_MAN 1
+#define MAN_PATH "/usr/local/share/man/"
+ //manpages
+#define INSTALL_INFO 1
+ //install info pages
+#define INSTALL_DOC 1
+#define DOC_PATH "/usr/local/share/doc/iwannaflycurses/"
+ //documentation that is niether texinfo nor manpages
+#define INSTALL_HTML 1
+#define HTML_PATH "/usr/local/share/doc/iwannaflycurses/"
+ //HTML-optimized versions of the info pages
+#define INSTALL_SRC 1
+#define SRC_PATH "/usr/local/share/src/iwannaflycurses/"
+ //where to put the source, should you choose to install it
+#define GAMES_PATH "/usr/local/games/"
+ //where games are installed
+#define BIN_PATH "/usr/local/bin/"
+ //where non-game executables are installed
#define DOT_PATH "~/.iwannaflycurses/"
+ //where the config files are found