Compare commits
No commits in common. "7232f95f7afc10cd7bde6ad43f35c797a181f94f" and "0ab7ef872bce0e44ea3f475823bc727220d68d5b" have entirely different histories.
7232f95f7a
...
0ab7ef872b
50
bmin.ul
50
bmin.ul
|
|
@ -1,50 +0,0 @@
|
||||||
str code = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
|
|
||||||
byte[10000] memory;
|
|
||||||
|
|
||||||
nat mp = 0; // memory pointer
|
|
||||||
nat ip = 0; // instruction pointer
|
|
||||||
|
|
||||||
while (ip < code.length) {
|
|
||||||
if (code[ip] == '>') {
|
|
||||||
mp = mp + 1;
|
|
||||||
} else if (code[ip] == '<') {
|
|
||||||
mp = mp - 1;
|
|
||||||
} else if (code[ip] == '+') {
|
|
||||||
memory[mp] = memory[mp] + 1;
|
|
||||||
} else if (code[ip] == '-') {
|
|
||||||
memory[mp] = memory[mp] - 1;
|
|
||||||
} else if (code[ip] == '.') {
|
|
||||||
// console.write = memory[mp];
|
|
||||||
write = memory[mp];
|
|
||||||
} else if (code[ip] == ',') {
|
|
||||||
// memory[mp] = console.read;
|
|
||||||
memory[mp] = read;
|
|
||||||
} else if (code[ip] == '[') {
|
|
||||||
if(!memory[mp]) {
|
|
||||||
nat nc = 1;
|
|
||||||
while (nc > 0) {
|
|
||||||
ip = ip + 1;
|
|
||||||
if (code[ip] == '[') {
|
|
||||||
nc = nc + 1;
|
|
||||||
} else if (code[ip] == ']') {
|
|
||||||
nc = nc - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (code[ip] == ']') {
|
|
||||||
if (memory[mp]) {
|
|
||||||
nat nc = 1;
|
|
||||||
while (nc > 0) {
|
|
||||||
ip = ip - 1;
|
|
||||||
if (code[ip] == ']') {
|
|
||||||
nc = nc + 1;
|
|
||||||
} else if (code[ip] == '[') {
|
|
||||||
nc = nc - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ip = ip + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
halt;
|
|
||||||
73
compiler.c
73
compiler.c
|
|
@ -291,8 +291,7 @@ calculate_strides(List *dims, List *strides)
|
||||||
if (num){
|
if (num){
|
||||||
current_stride *= (*num);
|
current_stride *= (*num);
|
||||||
} else {
|
} else {
|
||||||
emitter->error("Tried to get a dimension that did not exist", 43,
|
emitter->error("Tried to get a dimension that did not exist", 43, parser->previous.line);
|
||||||
parser->previous.line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -335,8 +334,9 @@ define_array(void)
|
||||||
void
|
void
|
||||||
define_string(void)
|
define_string(void)
|
||||||
{
|
{
|
||||||
scope_add_symbol(parser->current.start, parser->current.length, SYMBOL_STR,
|
scope_add_symbol(parser->current.start,
|
||||||
0);
|
parser->current.length,
|
||||||
|
SYMBOL_STR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -358,13 +358,14 @@ build_symbol_table(char *source)
|
||||||
define_plex();
|
define_plex();
|
||||||
} else if(match(TOKEN_KEYWORD_TRAIT)) {
|
} else if(match(TOKEN_KEYWORD_TRAIT)) {
|
||||||
define_trait();
|
define_trait();
|
||||||
} else if(parser->previous.type != TOKEN_KEYWORD_AS &&
|
} else if (parser->previous.type != TOKEN_KEYWORD_AS && match(TOKEN_TYPE_STR)) {
|
||||||
match(TOKEN_TYPE_STR)) {
|
|
||||||
define_string();
|
define_string();
|
||||||
} else if (parser->current.type >= TOKEN_TYPE_I8 &&
|
} else if (parser->current.type >= TOKEN_TYPE_I8 &&
|
||||||
parser->current.type <= TOKEN_TYPE_PTR) {
|
parser->current.type <= TOKEN_TYPE_PTR) {
|
||||||
advance();
|
advance();
|
||||||
if(check(TOKEN_LBRACKET)) define_array();
|
if (check(TOKEN_LBRACKET)) {
|
||||||
|
define_array();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* in binary bytecode output mode we need to count the bytes here */
|
/* in binary bytecode output mode we need to count the bytes here */
|
||||||
/* otherwise ignore everything */
|
/* otherwise ignore everything */
|
||||||
|
|
@ -388,8 +389,10 @@ variable_declaration(Symbol *def)
|
||||||
Symbol *variable;
|
Symbol *variable;
|
||||||
List *array_literal;
|
List *array_literal;
|
||||||
|
|
||||||
|
|
||||||
if (tt == TOKEN_TYPE_STR) {
|
if (tt == TOKEN_TYPE_STR) {
|
||||||
variable = scope_get_symbol(parser->current_scope, parser->current.start,
|
variable = scope_get_symbol(parser->current_scope,
|
||||||
|
parser->current.start,
|
||||||
parser->current.length);
|
parser->current.length);
|
||||||
if (!variable) {
|
if (!variable) {
|
||||||
emitter->error("cannot find str symbol", 23, parser->current.line);
|
emitter->error("cannot find str symbol", 23, parser->current.line);
|
||||||
|
|
@ -400,8 +403,7 @@ variable_declaration(Symbol *def)
|
||||||
if (match(TOKEN_EQ)) {
|
if (match(TOKEN_EQ)) {
|
||||||
expect(TOKEN_LITERAL_STR);
|
expect(TOKEN_LITERAL_STR);
|
||||||
variable->size = parser->previous.length - 2;
|
variable->size = parser->previous.length - 2;
|
||||||
emitter->emit_str(arena, memory, variable, parser->previous.start,
|
emitter->emit_str(arena, memory, variable, parser->previous.start, parser->previous.length);
|
||||||
parser->previous.length);
|
|
||||||
expect(TOKEN_SEMICOLON);
|
expect(TOKEN_SEMICOLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,10 +412,13 @@ variable_declaration(Symbol *def)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser->current.type == TOKEN_LBRACKET) {
|
if (parser->current.type == TOKEN_LBRACKET) {
|
||||||
while(!check(TOKEN_RBRACKET)) advance();
|
while(!check(TOKEN_RBRACKET)) {
|
||||||
|
advance();
|
||||||
|
}
|
||||||
advance();
|
advance();
|
||||||
|
|
||||||
variable = scope_get_symbol(parser->current_scope, parser->current.start,
|
variable = scope_get_symbol(parser->current_scope,
|
||||||
|
parser->current.start,
|
||||||
parser->current.length);
|
parser->current.length);
|
||||||
if (!variable) {
|
if (!variable) {
|
||||||
emitter->error("cannot find array symbol", 25, parser->current.line);
|
emitter->error("cannot find array symbol", 25, parser->current.line);
|
||||||
|
|
@ -440,9 +445,7 @@ variable_declaration(Symbol *def)
|
||||||
expect(TOKEN_SEMICOLON);
|
expect(TOKEN_SEMICOLON);
|
||||||
|
|
||||||
emitter->emit_array(arena, memory, variable, nil);
|
emitter->emit_array(arena, memory, variable, nil);
|
||||||
emitter->emit_zero_block(arena, memory,
|
emitter->emit_zero_block(arena, memory, variable->size * emitter->get_size(variable->secondary_type));
|
||||||
variable->size *
|
|
||||||
emitter->get_size(variable->secondary_type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->current_type = st;
|
parser->current_type = st;
|
||||||
|
|
@ -452,8 +455,7 @@ variable_declaration(Symbol *def)
|
||||||
if(st != SYMBOL_UNDEFINED) {
|
if(st != SYMBOL_UNDEFINED) {
|
||||||
size = emitter->get_size(st);
|
size = emitter->get_size(st);
|
||||||
|
|
||||||
variable = scope_add_symbol(parser->current.start, parser->current.length,
|
variable = scope_add_symbol(parser->current.start, parser->current.length, st, size);
|
||||||
st, size);
|
|
||||||
|
|
||||||
if(!def && (parser->pass == 0)) return size;
|
if(!def && (parser->pass == 0)) return size;
|
||||||
|
|
||||||
|
|
@ -628,9 +630,7 @@ variable(void)
|
||||||
if (sleq("length", parser->current.start, parser->current.length)) {
|
if (sleq("length", parser->current.start, parser->current.length)) {
|
||||||
emitter->emit_deref(arena, code, 2);
|
emitter->emit_deref(arena, code, 2);
|
||||||
} else {
|
} else {
|
||||||
emitter->error("arrays currently can only get their length, don't do "
|
emitter->error("arrays currently can only get their length, don't do anything fancy yet...", 75, parser->current.line);
|
||||||
"anything fancy yet...",
|
|
||||||
75, parser->current.line);
|
|
||||||
}
|
}
|
||||||
parser->current_type = SYMBOL_NAT;
|
parser->current_type = SYMBOL_NAT;
|
||||||
advance();
|
advance();
|
||||||
|
|
@ -679,9 +679,7 @@ variable(void)
|
||||||
if (sleq("length", parser->current.start, parser->current.length)) {
|
if (sleq("length", parser->current.start, parser->current.length)) {
|
||||||
emitter->emit_deref(arena, code, size);
|
emitter->emit_deref(arena, code, size);
|
||||||
} else {
|
} else {
|
||||||
emitter->error("arrays currently can only get their length, don't do "
|
emitter->error("arrays currently can only get their length, don't do anything fancy yet...", 75, parser->current.line);
|
||||||
"anything fancy yet...",
|
|
||||||
75, parser->current.line);
|
|
||||||
}
|
}
|
||||||
parser->current_type = SYMBOL_NAT;
|
parser->current_type = SYMBOL_NAT;
|
||||||
advance();
|
advance();
|
||||||
|
|
@ -791,16 +789,14 @@ cast_type(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
emitter->error("Type cast not implemented for this type (oops)", 46,
|
emitter->error("Type cast not implemented for this type (oops)", 46, parser->previous.line);
|
||||||
parser->previous.line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
declaration(void)
|
declaration(void)
|
||||||
{
|
{
|
||||||
if(is_type() && (parser->current.type == TOKEN_IDENTIFIER ||
|
if(is_type() && (parser->current.type == TOKEN_IDENTIFIER || parser->current.type == TOKEN_LBRACKET) )
|
||||||
parser->current.type == TOKEN_LBRACKET))
|
|
||||||
variable_declaration(nil);
|
variable_declaration(nil);
|
||||||
else
|
else
|
||||||
statement();
|
statement();
|
||||||
|
|
@ -830,8 +826,7 @@ if_statement(void)
|
||||||
statement();
|
statement();
|
||||||
emitter->else_if_depth--;
|
emitter->else_if_depth--;
|
||||||
}
|
}
|
||||||
if(emitter->else_if_depth == 0)
|
if(emitter->else_if_depth == 0) emitter->emit_patch_if_done(arena, code, emitter->ifs++);
|
||||||
emitter->emit_patch_if_done(arena, code, emitter->ifs++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -935,33 +930,19 @@ grouping(void)
|
||||||
void
|
void
|
||||||
number(void)
|
number(void)
|
||||||
{
|
{
|
||||||
switch(parser->current_type) {
|
emitter->emit_int(arena, code, parser->previous.start, parser->previous.length);
|
||||||
case SYMBOL_BOOL:
|
|
||||||
case SYMBOL_BYTE:
|
|
||||||
case SYMBOL_U8:
|
|
||||||
case SYMBOL_I8:
|
|
||||||
emitter->emit_char(arena, code, parser->previous.start,
|
|
||||||
parser->previous.length);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
emitter->emit_nat(arena, code, parser->previous.start,
|
|
||||||
parser->previous.length);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
string(void)
|
string(void)
|
||||||
{
|
{
|
||||||
emitter->emit_inline_str(arena, code, parser->previous.start,
|
emitter->emit_inline_str(arena, code, parser->previous.start, parser->previous.length);
|
||||||
parser->previous.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
character(void)
|
character(void)
|
||||||
{
|
{
|
||||||
emitter->emit_char(arena, code, parser->previous.start,
|
emitter->emit_char(arena, code, parser->previous.start, parser->previous.length);
|
||||||
parser->previous.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue