Code Monkey home page Code Monkey logo

corewar's People

Contributors

gjsteyn avatar kcuns avatar philipstubbs avatar wseegers avatar

Stargazers

 avatar

corewar's Issues

void write_to_bin(char *path, t_header *header), //t_code *code)

void write_to_bin(char *path, t_header *header), //t_code *code)

** parm: path - path of the bin **
** parm: header - header to be written to binary. nb Size to changed to big endian **

This function will write to a file the bytecode for the corewar vm.

Suggestion create a char bin[max_program_size] and do a single write call.

big endian to little endian

int big_to_little_endian(char big[4])

param: big - The value to be converted to little endian
return - the little endian value

This will be the opposite conversion to its counter part

little endian to big endian

void little_to_big_endian(int little, char big[4])

Parm: little - the value to be converted
Parm: big - the result of the conversion is to be placed in this array

For you own knowledge please research the topic, it an incredibly simply function to convert a little endian value as it is represented in C to be converted to a big endian number as should be used for the VM

Token Structure

PROGRAM =
HEADER {CODE}

HEADER =
<.name> TEXT "\n" <.comment> TEXT "\n"

CODE =
[{<label_chars>} ":"] OP <whitespace - \n> " ARG { ARG}"\n"

OP =
"live"
| "ld"
| "st"
| "add"
| "sub"
| "and"
| "or"
| "xor"
| "zjmp"
| "ldi"
| "sti"
| "fork"
| "lld"
| "lldi"
| "lfork"
| "aff"

ARG =
["%"] [":"] {number}

TEXT =
{ascci}

token type = value

e_keyword;
e_op;
e_arg;

[KEY WORD] = name
[TEXT] = "zork"
[KEY WORD] = comment
[TEXT] = "..."
[LABEL] = "l2"
[OP] = <e_opcode>
[ARG] = <e_arg_code>

[ARG_LABEL] =
[NUMBER] =
[EOL]

[NUMBER] =
[ARITH] = {+, *, -, /, %}
[BRAKET] = 1, 2

f_putstr_err

void f_putstr_err(char *str)

parm : str - string to be printed

Function to print null terminated char* to stderr, fd=2.

List structure

i suggest we discuss a basic list structure. To make it simpler we could create a que structure and associated functions as we'll require them to manage and parse tokens.

Example of my IO system

#include "f_io.h"
#include "f_print.h"

void file_example(void)
{
char *file_name;
char mode;
t_file *file;

mode = 'r';   // r - read, w - write, a - appened
file_name = "path/to/file.txt";

file = f_openf(file_name, mode);

char	*line;
int		ret;

t_file	*out_file;

out_file = f_openf("out.txt", 'w');

int i = 0;
// To get a line from stdin replace file wth STDIN
while (f_next_line(&line, file))
{
	f_fprintf(out_file, "[%d] %s\n", i++, line);
	//f_fprintf can also take STDOUT or STDERR
	free(line);
}
f_closef(file);
f_closef(out_file);

}

put_nbr

void put_nbr_err(int nbr)

parm: nbr - number to be written to stderr, fd=2

f_atoi

long f_atoi(char *nbr, int *error)

parm: nbr - string of number to be converted
parm: error - this value is to be set incase of error else it should be set to 0.

A standard atoi function, please note it should convert any number until a non digit value is reached. eg. "12345abc" -> 12345

Error should include char* not starting with a digit or "-".
Function SHOULD segfault in cases where nbr is NULL

Get next line

Get next line still requires some "libft" functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.