add & float, init tok map

This commit is contained in:
zongor 2023-03-04 13:20:59 -05:00
parent 02d37d3bcc
commit ef263d9cc4
8 changed files with 924 additions and 676 deletions

View File

@ -1 +1 @@
BasedOnStyle: GNU
BasedOnStyle: Mozilla

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/varaq",
"args": ["tests/add.vq", "public/module.wasm"],
"cwd": "${workspaceFolder}"
}
]
}

View File

@ -1,9 +1,7 @@
CC = gcc
CCFLAGS= -g
all: varaq
varaq:
all:
$(CC) $(CCFLAGS) -o varaq main.c compiler.c tokenizer.c
clean:

145
compile_test.c Normal file
View File

@ -0,0 +1,145 @@
#include "compiler.h"
#include "common.h"
#include "tokenizer.h"
Code *
demo_function_compile ()
{
Code *add_args_code = (Code *)calloc (1, sizeof (Code));
append_byte (add_args_code, f32);
append_byte (add_args_code, f32);
Code *add_return_code = (Code *)calloc (1, sizeof (Code));
append_byte (add_return_code, f32);
Code *add_function_type = (Code *)calloc (1, sizeof (Code));
append_byte (add_function_type, FUNCTION);
append (add_function_type, encodeVector (add_args_code));
append (add_function_type, encodeVector (add_return_code));
add_function_type->override = true;
add_function_type->override_count = 1;
Code *type_section = createSection (TYPE, encodeVector (add_function_type));
Code *return_type_code = (Code *)calloc (1, sizeof (Code));
append_byte (return_type_code, 0x00);
return_type_code->override = true;
return_type_code->override_count = 1;
Code *func_section = createSection (FUNC, encodeVector (return_type_code));
Code *exp = encodeString ("main");
append_byte (exp, EXPORT_FUNC);
append_byte (exp, 0x00);
exp->override = true;
exp->override_count = 1;
Code *export_section = createSection (EXPORT, encodeVector (exp));
Code *code = (Code *)calloc (1, sizeof (Code));
append_byte (code, LOCAL_GET);
append (code, unsignedLEB128 (0));
append_byte (code, LOCAL_GET);
append (code, unsignedLEB128 (1));
append_byte (code, F32_ADD);
Code *body = (Code *)calloc (1, sizeof (Code));
append_byte (body, EMPTY_ARRAY);
append (body, code);
append_byte (body, END);
Code *function_body = (Code *)calloc (1, sizeof (Code));
append (function_body, encodeVector (body));
function_body->override = true;
function_body->override_count = 1;
Code *code_section = createSection (CODE, encodeVector (function_body));
Code *tape = (Code *)malloc (sizeof (Code));
tape->cells = calloc (8, sizeof (uint8_t));
tape->cells[0] = 0;
tape->cells[1] = 'a';
tape->cells[2] = 's';
tape->cells[3] = 'm';
tape->cells[4] = 1;
tape->cells[5] = 0;
tape->cells[6] = 0;
tape->cells[7] = 0;
tape->count = 8;
append (tape, type_section);
append (tape, func_section);
append (tape, export_section);
append (tape, code_section);
return tape;
}
Code *
demo_add_compile ()
{
Code *add_args_code = (Code *)calloc (1, sizeof (Code));
Code *add_return_code = (Code *)calloc (1, sizeof (Code));
append_byte (add_return_code, f64);
Code *add_function_type = (Code *)calloc (1, sizeof (Code));
append_byte (add_function_type, FUNCTION);
append (add_function_type, encodeVector (add_args_code));
append (add_function_type, encodeVector (add_return_code));
add_function_type->override = true;
add_function_type->override_count = 1;
Code *type_section = createSection (TYPE, encodeVector (add_function_type));
Code *return_type_code = (Code *)calloc (1, sizeof (Code));
append_byte (return_type_code, 0x00);
return_type_code->override = true;
return_type_code->override_count = 1;
Code *func_section = createSection (FUNC, encodeVector (return_type_code));
Code *exp = encodeString ("main");
append_byte (exp, EXPORT_FUNC);
append_byte (exp, 0x00);
exp->override = true;
exp->override_count = 1;
Code *export_section = createSection (EXPORT, encodeVector (exp));
Code *code = (Code *)calloc (1, sizeof (Code));
append_byte (code, F64_CONST);
append_f64 (code, 6.7);
append_byte (code, F64_CONST);
append_f64 (code, 8.5);
append_byte (code, F64_ADD);
Code *body = (Code *)calloc (1, sizeof (Code));
append_byte (body, EMPTY_ARRAY);
append (body, code);
append_byte (body, END);
Code *function_body = (Code *)calloc (1, sizeof (Code));
append (function_body, encodeVector (body));
function_body->override = true;
function_body->override_count = 1;
Code *code_section = createSection (CODE, encodeVector (function_body));
Code *tape = (Code *)malloc (sizeof (Code));
tape->cells = calloc (8, sizeof (uint8_t));
tape->cells[0] = 0;
tape->cells[1] = 'a';
tape->cells[2] = 's';
tape->cells[3] = 'm';
tape->cells[4] = 1;
tape->cells[5] = 0;
tape->cells[6] = 0;
tape->cells[7] = 0;
tape->count = 8;
append (tape, type_section);
append (tape, func_section);
append (tape, export_section);
append (tape, code_section);
return tape;
}

View File

@ -3,338 +3,416 @@
#include "common.h"
#include "tokenizer.h"
Code *
signedLEB128 (size_t num)
Code*
signedLEB128(size_t num)
{
bool more = true;
Code *buffer = (Code *)malloc (sizeof (Code));
Code* buffer = (Code*)malloc(sizeof(Code));
buffer->count = 0;
int n = (int)num;
while (more)
{
uint8_t byte = n & 0x7f;
n >>= 7;
if ((n == 0 && (byte & 0x40) == 0) || (n == -1 && (byte & 0x40) != 0))
{
more = false;
}
else
{
byte |= 0x80;
}
size_t old_count = buffer->count;
uint8_t *tmp = (uint8_t *)calloc (
(old_count + 1),
sizeof (uint8_t)); // really slow and bad refactor later
memcpy (tmp, buffer->cells, buffer->count * sizeof (uint8_t));
if (tmp)
{
buffer->cells = tmp;
}
buffer->cells[old_count] = byte;
buffer->count += 1;
while (more) {
uint8_t byte = n & 0x7f;
n >>= 7;
if ((n == 0 && (byte & 0x40) == 0) || (n == -1 && (byte & 0x40) != 0)) {
more = false;
} else {
byte |= 0x80;
}
size_t old_count = buffer->count;
uint8_t* tmp =
(uint8_t*)calloc((old_count + 1),
sizeof(uint8_t)); // really slow and bad refactor later
memcpy(tmp, buffer->cells, buffer->count * sizeof(uint8_t));
if (tmp) {
buffer->cells = tmp;
}
buffer->cells[old_count] = byte;
buffer->count += 1;
}
return buffer;
}
Code *
unsignedLEB128 (size_t num)
Code*
unsignedLEB128(size_t num)
{
Code *buffer = (Code *)malloc (sizeof (Code));
Code* buffer = (Code*)malloc(sizeof(Code));
buffer->count = 0;
int n = (int)num;
do
{
uint8_t byte = n & 0x7f;
n >>= 7;
if (n != 0)
{
byte |= 0x80;
}
size_t old_count = buffer->count;
uint8_t *tmp = (uint8_t *)calloc (
(old_count + 1),
sizeof (uint8_t)); // really slow and bad refactor later
memcpy (tmp, buffer->cells, buffer->count * sizeof (uint8_t));
if (tmp)
{
buffer->cells = tmp;
}
buffer->cells[old_count] = byte;
buffer->count += 1;
do {
uint8_t byte = n & 0x7f;
n >>= 7;
if (n != 0) {
byte |= 0x80;
}
while (n != 0);
size_t old_count = buffer->count;
uint8_t* tmp =
(uint8_t*)calloc((old_count + 1),
sizeof(uint8_t)); // really slow and bad refactor later
memcpy(tmp, buffer->cells, buffer->count * sizeof(uint8_t));
if (tmp) {
buffer->cells = tmp;
}
buffer->cells[old_count] = byte;
buffer->count += 1;
} while (n != 0);
return buffer;
}
Code *
append_byte (Code *tape, uint8_t data)
Code*
generic_append(Code* tape, void* data, size_t data_size)
{
size_t old_count = tape->count;
uint8_t *tmp = (uint8_t *)calloc ((old_count + 1), sizeof (uint8_t));
if (old_count > 0)
{
memcpy (tmp, tape->cells, tape->count * sizeof (uint8_t));
}
if (tmp)
{
tape->cells = tmp;
}
tape->cells[old_count] = data;
tape->count += 1;
return tape;
}
Code *
append_f64 (Code *tape, double data)
{
size_t old_count = tape->count;
uint8_t* tmp = (uint8_t*)calloc((old_count + data_size), sizeof(uint8_t));
if (old_count > 0) {
memcpy(tmp, tape->cells, tape->count * sizeof(uint8_t));
}
if (tmp) {
tape->cells = tmp;
}
uint8_t *tmp
= (uint8_t *)calloc ((old_count + sizeof (data)), sizeof (uint8_t));
if (old_count > 0)
{
memcpy (tmp, tape->cells, tape->count * sizeof (uint8_t));
}
if (tmp)
{
tape->cells = tmp;
}
memcpy ((tape->cells + old_count), (unsigned char *)&data, sizeof (data));
tape->count += sizeof (data);
memcpy((tape->cells + old_count), (unsigned char*)data, data_size);
tape->count += data_size;
return tape;
}
Code *
append (Code *tape, Code *data)
Code*
append_byte(Code* tape, uint8_t data)
{
return generic_append(tape, &data, sizeof(uint8_t));
}
Code*
append_f64(Code* tape, double data)
{
return generic_append(tape, &data, sizeof(double));
}
Code*
append(Code* tape, Code* data)
{
size_t old_count = tape->count;
uint8_t *tmp
= (uint8_t *)calloc ((old_count + data->count), sizeof (uint8_t));
memcpy (tmp, tape->cells, tape->count * sizeof (uint8_t));
if (tmp)
{
tape->cells = tmp;
}
uint8_t* tmp = (uint8_t*)calloc((old_count + data->count), sizeof(uint8_t));
memcpy(tmp, tape->cells, tape->count * sizeof(uint8_t));
if (tmp) {
tape->cells = tmp;
}
memcpy ((tape->cells + old_count), data->cells,
data->count * sizeof (uint8_t));
memcpy((tape->cells + old_count), data->cells, data->count * sizeof(uint8_t));
tape->count += data->count;
return tape;
}
Code *
encodeString (char *string)
Code*
encodeString(char* string)
{
Code *buffer = (Code *)malloc (sizeof (Code));
buffer->cells = (uint8_t *)malloc (sizeof (uint8_t));
buffer->cells[0] = strlen (string);
Code* buffer = (Code*)malloc(sizeof(Code));
buffer->cells = (uint8_t*)malloc(sizeof(uint8_t));
buffer->cells[0] = strlen(string);
buffer->count = 1;
uint8_t *tmp = (uint8_t *)malloc ((1 + strlen (string)) * sizeof (char));
memcpy (tmp, buffer->cells, buffer->count * sizeof (uint8_t));
if (tmp)
{
buffer->cells = tmp;
}
uint8_t* tmp = (uint8_t*)malloc((1 + strlen(string)) * sizeof(char));
memcpy(tmp, buffer->cells, buffer->count * sizeof(uint8_t));
if (tmp) {
buffer->cells = tmp;
}
memcpy ((buffer->cells + 1), string, strlen (string) * sizeof (char));
buffer->count += strlen (string);
memcpy((buffer->cells + 1), string, strlen(string) * sizeof(char));
buffer->count += strlen(string);
return buffer;
}
Code *
encodeVector (Code *data)
Code*
encodeVector(Code* data)
{
size_t count = data->override ? data->override_count : data->count;
Code *buffer = unsignedLEB128 (count);
append (buffer, data);
Code* buffer = unsignedLEB128(count);
append(buffer, data);
return buffer;
}
Code *
createSection (uint8_t section, Code *data)
Code*
createSection(uint8_t section, Code* data)
{
Code *buffer = (Code *)malloc (sizeof (Code));
buffer->cells = (uint8_t *)malloc (sizeof (uint8_t));
Code* buffer = (Code*)malloc(sizeof(Code));
buffer->cells = (uint8_t*)malloc(sizeof(uint8_t));
buffer->cells[0] = section;
buffer->count = 1;
return append (buffer, encodeVector (data));
return append(buffer, encodeVector(data));
}
Code *
demo_function_compile ()
Code*
compile(char* buffer)
{
Code *add_args_code = (Code *)calloc (1, sizeof (Code));
append_byte (add_args_code, f32);
append_byte (add_args_code, f32);
char number[100];
Code *add_return_code = (Code *)calloc (1, sizeof (Code));
append_byte (add_return_code, f32);
Code* add_args_code = (Code*)calloc(1, sizeof(Code));
Code* add_return_code = (Code*)calloc(1, sizeof(Code));
append_byte(add_return_code, f64);
Code *add_function_type = (Code *)calloc (1, sizeof (Code));
append_byte (add_function_type, FUNCTION);
Code* add_function_type = (Code*)calloc(1, sizeof(Code));
append_byte(add_function_type, FUNCTION);
append (add_function_type, encodeVector (add_args_code));
append (add_function_type, encodeVector (add_return_code));
append(add_function_type, encodeVector(add_args_code));
append(add_function_type, encodeVector(add_return_code));
add_function_type->override = true;
add_function_type->override_count = 1;
Code *type_section = createSection (TYPE, encodeVector (add_function_type));
Code* type_section = createSection(TYPE, encodeVector(add_function_type));
Code *return_type_code = (Code *)calloc (1, sizeof (Code));
append_byte (return_type_code, 0x00);
Code* return_type_code = (Code*)calloc(1, sizeof(Code));
append_byte(return_type_code, 0x00);
return_type_code->override = true;
return_type_code->override_count = 1;
Code *func_section = createSection (FUNC, encodeVector (return_type_code));
Code* func_section = createSection(FUNC, encodeVector(return_type_code));
Code *exp = encodeString ("main");
append_byte (exp, EXPORT_FUNC);
append_byte (exp, 0x00);
Code* exp = encodeString("main");
append_byte(exp, EXPORT_FUNC);
append_byte(exp, 0x00);
exp->override = true;
exp->override_count = 1;
Code *export_section = createSection (EXPORT, encodeVector (exp));
Code* export_section = createSection(EXPORT, encodeVector(exp));
Code *code = (Code *)calloc (1, sizeof (Code));
append_byte (code, LOCAL_GET);
append (code, unsignedLEB128 (0));
append_byte (code, LOCAL_GET);
append (code, unsignedLEB128 (1));
append_byte (code, F32_ADD);
// Code* code = (Code*)calloc(1, sizeof(Code));
// append_byte(code, F64_CONST);
// append_f64(code, 1.0);
// append_byte(code, F64_CONST);
// append_f64(code, 2.0);
// append_byte(code, F64_ADD);
Code *body = (Code *)calloc (1, sizeof (Code));
append_byte (body, EMPTY_ARRAY);
append (body, code);
append_byte (body, END);
Code *function_body = (Code *)calloc (1, sizeof (Code));
append (function_body, encodeVector (body));
function_body->override = true;
function_body->override_count = 1;
Code *code_section = createSection (CODE, encodeVector (function_body));
Code *tape = (Code *)malloc (sizeof (Code));
tape->cells = calloc (8, sizeof (uint8_t));
tape->cells[0] = 0;
tape->cells[1] = 'a';
tape->cells[2] = 's';
tape->cells[3] = 'm';
tape->cells[4] = 1;
tape->cells[5] = 0;
tape->cells[6] = 0;
tape->cells[7] = 0;
tape->count = 8;
append (tape, type_section);
append (tape, func_section);
append (tape, export_section);
append (tape, code_section);
return tape;
}
Code *
demo_add_compile ()
{
Code *add_args_code = (Code *)calloc (1, sizeof (Code));
Code *add_return_code = (Code *)calloc (1, sizeof (Code));
append_byte (add_return_code, f64);
Code *add_function_type = (Code *)calloc (1, sizeof (Code));
append_byte (add_function_type, FUNCTION);
append (add_function_type, encodeVector (add_args_code));
append (add_function_type, encodeVector (add_return_code));
add_function_type->override = true;
add_function_type->override_count = 1;
Code *type_section = createSection (TYPE, encodeVector (add_function_type));
Code *return_type_code = (Code *)calloc (1, sizeof (Code));
append_byte (return_type_code, 0x00);
return_type_code->override = true;
return_type_code->override_count = 1;
Code *func_section = createSection (FUNC, encodeVector (return_type_code));
Code *exp = encodeString ("main");
append_byte (exp, EXPORT_FUNC);
append_byte (exp, 0x00);
exp->override = true;
exp->override_count = 1;
Code *export_section = createSection (EXPORT, encodeVector (exp));
Code *code = (Code *)calloc (1, sizeof (Code));
append_byte (code, F64_CONST);
append_f64 (code, 6.7);
append_byte (code, F64_CONST);
append_f64 (code, 8.5);
append_byte (code, F64_ADD);
Code *body = (Code *)calloc (1, sizeof (Code));
append_byte (body, EMPTY_ARRAY);
append (body, code);
append_byte (body, END);
Code *function_body = (Code *)calloc (1, sizeof (Code));
append (function_body, encodeVector (body));
function_body->override = true;
function_body->override_count = 1;
Code *code_section = createSection (CODE, encodeVector (function_body));
Code *tape = (Code *)malloc (sizeof (Code));
tape->cells = calloc (8, sizeof (uint8_t));
tape->cells[0] = 0;
tape->cells[1] = 'a';
tape->cells[2] = 's';
tape->cells[3] = 'm';
tape->cells[4] = 1;
tape->cells[5] = 0;
tape->cells[6] = 0;
tape->cells[7] = 0;
tape->count = 8;
append (tape, type_section);
append (tape, func_section);
append (tape, export_section);
append (tape, code_section);
return tape;
}
Code *
compile (char *buffer)
{
Code *tape = (Code *)malloc (sizeof (Code));
tape->cells = calloc (8, sizeof (uint8_t));
tape->cells[0] = 0;
tape->cells[1] = 'a';
tape->cells[2] = 's';
tape->cells[3] = 'm';
tape->cells[4] = 1;
tape->cells[5] = 0;
tape->cells[6] = 0;
tape->cells[7] = 0;
tape->count = 8;
initTokenizer (buffer);
Token t = nextToken ();
while (t.type != TOKEN_EOF)
{
debug_printToken (t);
t = nextToken ();
Code* code = (Code*)calloc(1, sizeof(Code));
initTokenizer(buffer);
Token t = nextToken();
do {
// debug_printToken(t);
switch (t.type) {
case TOKEN_LEFT_PAREN:
break;
case TOKEN_RIGHT_PAREN:
break;
case TOKEN_LEFT_BRACE:
break;
case TOKEN_RIGHT_BRACE:
break;
case TOKEN_TILDE:
break;
case TOKEN_SLASH:
break;
case TOKEN_MINUS:
break;
case TOKEN_IDENTIFIER:
break;
case TOKEN_STRING:
break;
case TOKEN_FLOAT:
strncpy(number, t.start, t.length);
number[t.length + 1] = '\0';
append_byte(code, F64_CONST);
append_f64(code, strtod(number, NULL));
break;
case TOKEN_LIST:
break;
case TOKEN_ERROR:
break;
case TOKEN_FALSE:
break;
case TOKEN_TRUE:
break;
case TOKEN_PI:
break;
case TOKEN_E:
break;
case TOKEN_EOF:
break;
case TOKEN_POP:
break;
case TOKEN_DUP:
break;
case TOKEN_EXCH:
break;
case TOKEN_CLEAR:
break;
case TOKEN_REMEMBER:
break;
case TOKEN_FORGET:
break;
case TOKEN_DUMP:
break;
case TOKEN_NAME:
break;
case TOKEN_SET:
break;
case TOKEN_IFYES:
break;
case TOKEN_IFNO:
break;
case TOKEN_CHOOSE:
break;
case TOKEN_EVAL:
break;
case TOKEN_ESCAPE:
break;
case TOKEN_REPEAT:
break;
case TOKEN_SPLIT:
break;
case TOKEN_CONS:
break;
case TOKEN_SHATTER:
break;
case TOKEN_EMPTY:
break;
case TOKEN_COMPOSE:
break;
case TOKEN_STREQ:
break;
case TOKEN_STRCUT:
break;
case TOKEN_STRMEASURE:
break;
case TOKEN_STRTIE:
break;
case TOKEN_EXPLODE:
break;
case TOKEN_ADD:
append_byte(code, F64_ADD);
break;
case TOKEN_SUB:
break;
case TOKEN_MUL:
break;
case TOKEN_DIV:
break;
case TOKEN_IDIV:
break;
case TOKEN_MOD:
break;
case TOKEN_POW:
break;
case TOKEN_SQRT:
break;
case TOKEN_ADD1:
break;
case TOKEN_SUB1:
break;
case TOKEN_SIN:
break;
case TOKEN_COS:
break;
case TOKEN_TAN:
break;
case TOKEN_ATAN:
break;
case TOKEN_LN:
break;
case TOKEN_LOG:
break;
case TOKEN_LOG3:
break;
case TOKEN_CLIP:
break;
case TOKEN_SMOOTH:
break;
case TOKEN_HOWMUCH:
break;
case TOKEN_SETRAND:
break;
case TOKEN_RAND:
break;
case TOKEN_INT:
break;
case TOKEN_NUMBERIZE:
break;
case TOKEN_ISOLATE:
break;
case TOKEN_MIX:
break;
case TOKEN_CONTRADICT:
break;
case TOKEN_COMPL:
break;
case TOKEN_SHIFTRIGHT:
break;
case TOKEN_SHIFTLEFT:
break;
case TOKEN_GT:
break;
case TOKEN_LT:
break;
case TOKEN_EQ:
break;
case TOKEN_GE:
break;
case TOKEN_LE:
break;
case TOKEN_NE:
break;
case TOKEN_NULL:
break;
case TOKEN_NEGATIVE:
break;
case TOKEN_ISNULL:
break;
case TOKEN_ISINT:
break;
case TOKEN_ISNUMBER:
break;
case TOKEN_AND:
break;
case TOKEN_OR:
break;
case TOKEN_XOR:
break;
case TOKEN_DISP:
break;
case TOKEN_LISTEN:
break;
case TOKEN_COMPLAIN:
break;
case TOKEN_TIME:
break;
case TOKEN_GARBAGE_COLLECT:
break;
}
t = nextToken();
} while (t.type != TOKEN_EOF);
Code* body = (Code*)calloc(1, sizeof(Code));
append_byte(body, EMPTY_ARRAY);
append(body, code);
append_byte(body, END);
Code* function_body = (Code*)calloc(1, sizeof(Code));
append(function_body, encodeVector(body));
function_body->override = true;
function_body->override_count = 1;
Code* code_section = createSection(CODE, encodeVector(function_body));
Code* tape = (Code*)malloc(sizeof(Code));
tape->cells = calloc(8, sizeof(uint8_t));
tape->cells[0] = 0;
tape->cells[1] = 'a';
tape->cells[2] = 's';
tape->cells[3] = 'm';
tape->cells[4] = 1;
tape->cells[5] = 0;
tape->cells[6] = 0;
tape->cells[7] = 0;
tape->count = 8;
append(tape, type_section);
append(tape, func_section);
append(tape, export_section);
append(tape, code_section);
return tape;
}

42
main.c
View File

@ -3,35 +3,33 @@
#include "tokenizer.h"
int
main (int argc, char **argv)
main(int argc, char** argv)
{
if (argc != 3)
{
printf ("usage: varaq input.vq output.wasm");
return EXIT_FAILURE;
}
if (argc != 3) {
printf("usage: varaq input.vq output.wasm");
return EXIT_FAILURE;
}
char *buffer;
char* buffer;
int length = 0;
int sp = open (argv[1], O_RDONLY);
int sp = open(argv[1], O_RDONLY);
if (sp)
{
length = lseek (sp, (size_t)0, SEEK_END);
lseek (sp, (size_t)0, SEEK_SET);
buffer = malloc (length);
if (buffer)
{
read (sp, buffer, length * sizeof (char));
}
close (sp);
if (sp) {
length = lseek(sp, (size_t)0, SEEK_END);
lseek(sp, (size_t)0, SEEK_SET);
buffer = malloc(length);
if (buffer) {
read(sp, buffer, length * sizeof(char));
}
close(sp);
}
Code *prog = compile (buffer);
initMap();
Code* prog = compile(buffer);
int tp = open (argv[2], O_CREAT | O_WRONLY, S_IRWXU | S_IRGRP | S_IROTH);
write (tp, prog->cells, prog->count);
close (tp);
int tp = open(argv[2], O_CREAT | O_WRONLY, S_IRWXU | S_IRGRP | S_IROTH);
write(tp, prog->cells, prog->count);
close(tp);
return EXIT_SUCCESS;
}

19
mkfile Normal file
View File

@ -0,0 +1,19 @@
</$objtype/mkfile
prog: main.$O compiler.$O tokenizer.$O
$LD $LDFLAGS -o $target $prereq
%.$O: %.c
$CC $CFLAGS $stem.c
install: $O.out
cp $O.out /$objtype/bin/varaq
installall:
for(objtype in $CPUS) mk install
clean:V:
rm -f [$OS].out *.[$OS] y.tab.?

File diff suppressed because it is too large Load Diff