Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
work on extension language, misc
Browse files Browse the repository at this point in the history
  • Loading branch information
GeneralGuy4872 committed Sep 27, 2019
1 parent 1319def commit 50f7fd6
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 33 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Doc Depends:
- <CODE>man</CODE>
- <CODE>info</CODE>

Doc Meta-depends:
- <CODE>mandb</CODE>
- <CODE>install-info</CODE>
- <CODE>cp</CODE>

Doc Recommends:
- <CODE>xdvi</CODE>

Expand Down
4 changes: 2 additions & 2 deletions manual/html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions src/extensionlanguage/docprelim
Original file line number Diff line number Diff line change
@@ -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 <EOF>

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.
27 changes: 16 additions & 11 deletions src/extensionlanguage/extensionlang.lex
Original file line number Diff line number Diff line change
@@ -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]+
Expand All @@ -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 ("<<"|"«")
Expand Down Expand Up @@ -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);
<STRING>{ENDQUOTE} yy_pop_state();
Expand All @@ -77,21 +76,28 @@ FI [Ff][Ii]
<CHARVAL>{CHAR} yyval.number = *yytext;return(NUMBER);
<CHARVAL>{UTF8} yyval.string = strdup(yytext);return(UTF8);

"`" yy_push_state(TYPE);
<TYPE>"`" yy_pop_state()
<TYPE>"{`" yy_pop_state();return(LSTRUCT);
<TYPE>{NAME} yyval.string = strdup(yytext);return(TYPENAME);
<TYPE>'*' return(TYPEPTR);
<TYPE>'&' return(DEREF);

"/*" yy_push_state(COMMENT);
<TYPE>"/*" yy_push_state(COMMENT);
<COMMENT>"*/" yy_pop_state();
<COMMENT>{TEXT};

<EXPR>{WHITESPACE} return ' ';

"(" yy_push_state(FUNC); return '(';
"(" yy_push_state(EXPR); return '(';
<EXPR>")" yy_pop_state(); return ')';
/*s-expressions and lists*/
"{" yy_push_state(EXPR); return '{';

"{" yy_push_state(ARR); return '{';
<ARR>"}" yy_pop_state(); return '}';
/*infix*/
"[" yy_push_state(ARR); return '[';

"[" yy_push_state(FUNC); return '[';
<FUNC>"]" 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);
Expand Down Expand Up @@ -141,7 +147,6 @@ FI [Ff][Ii]
"." return '.';
";" return ';';
"," return ',';
"`" return '`';
"\\" return '\\';
{SWITCH} return(SWITCH)
{CASE} return(CASE);
Expand Down
51 changes: 44 additions & 7 deletions src/extensionlanguage/extensionlang.y
Original file line number Diff line number Diff line change
@@ -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 <number> BOOLEAN RAW NUMBER SIGNED ERRVAL
%token <string> NAME VAR TEXT UTF8
%token <string> NAME VAR TEXT UTF8 TYPENAME
%token <dval> FLOAT NANTOK

%top {
Expand All @@ -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)}
Expand Down Expand Up @@ -98,6 +130,7 @@ expression
: anything
| literalexpression
| expression
| typecast
;
/* more later */

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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)}
Expand Down
17 changes: 17 additions & 0 deletions src/extensionlanguage/precedanceprelim
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/game_default_header.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const char* GAMEDIR = "default/"
#define GAMEDIR "default/"
27 changes: 20 additions & 7 deletions src/iwannaflycurses.messy
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down
33 changes: 28 additions & 5 deletions src/paths.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 50f7fd6

Please sign in to comment.