Increased token size! Added more doc comments.
This commit is contained in:
parent
73bfffcf55
commit
944d9287dc
|
@ -182,7 +182,7 @@ void code_window_load(Window *window)
|
||||||
GRect result_bounds = GRect(6, 128, 132, 132);
|
GRect result_bounds = GRect(6, 128, 132, 132);
|
||||||
s_result_text_layer = text_layer_create(result_bounds);
|
s_result_text_layer = text_layer_create(result_bounds);
|
||||||
text_layer_set_text(s_result_text_layer, "R: ");
|
text_layer_set_text(s_result_text_layer, "R: ");
|
||||||
text_layer_set_font(s_result_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
|
text_layer_set_font(s_result_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
|
||||||
text_layer_set_text_alignment(s_result_text_layer, GTextAlignmentRight);
|
text_layer_set_text_alignment(s_result_text_layer, GTextAlignmentRight);
|
||||||
layer_add_child(window_get_root_layer(s_code_window), text_layer_get_layer(s_result_text_layer));
|
layer_add_child(window_get_root_layer(s_code_window), text_layer_get_layer(s_result_text_layer));
|
||||||
|
|
||||||
|
|
82
src/object.c
82
src/object.c
|
@ -56,7 +56,11 @@ Object *itemAt(const Object *listObj, int n)
|
||||||
return march;
|
return march;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns last object in list (->forward == NULL)
|
/**
|
||||||
|
* Returns a pointer to the last Object in the given list.
|
||||||
|
* @param listObj The list to find the tail of
|
||||||
|
* @return A pointer to the last Object if it is found, or NULL on an error
|
||||||
|
*/
|
||||||
Object *tail(const Object *listObj)
|
Object *tail(const Object *listObj)
|
||||||
{
|
{
|
||||||
if(!listObj || listObj->type != TYPE_LIST)
|
if(!listObj || listObj->type != TYPE_LIST)
|
||||||
|
@ -70,11 +74,13 @@ Object *tail(const Object *listObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given object is empty
|
* Checks if a given object is empty.
|
||||||
|
*
|
||||||
* BOOL, NUMBER, and ERROR types return true only when 0
|
* BOOL, NUMBER, and ERROR types return true only when 0
|
||||||
* LIST, LAMBDA, and FUNC types return true only when NULL
|
* LIST, LAMBDA, and FUNC types return true only when NULL
|
||||||
* SYMBOL returns true only when it begins with a nullchar
|
* SYMBOL returns true only when it begins with a nullchar
|
||||||
* Returns false if obj is NULL
|
* @param obj A pointer to the object to check
|
||||||
|
* @return True only if the non-null Object is empty/non-zero
|
||||||
*/
|
*/
|
||||||
inline int isEmpty(const Object *obj)
|
inline int isEmpty(const Object *obj)
|
||||||
{
|
{
|
||||||
|
@ -100,6 +106,12 @@ inline int isEmpty(const Object *obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate a copy of a given object into the given pointer.
|
||||||
|
* Does nothing if `spot` is NULL
|
||||||
|
* @param spot A pointer to the Object pointer that needs allocating
|
||||||
|
* @param src The Object to copy from
|
||||||
|
*/
|
||||||
void allocObject(Object **spot, const Object src)
|
void allocObject(Object **spot, const Object src)
|
||||||
{
|
{
|
||||||
if(!spot)
|
if(!spot)
|
||||||
|
@ -109,12 +121,21 @@ void allocObject(Object **spot, const Object src)
|
||||||
(*spot)->forward = NULL;
|
(*spot)->forward = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert `src` into list `dest` before index `ind`
|
/**
|
||||||
// Adds to the end if the index is too high.
|
* Inserts a given Object into a list at the given index.
|
||||||
void insertIntoList(Object *dest, int ind, const Object src)
|
* Immediately returns if `dest` is NULL or not a list type
|
||||||
|
* Adds to the end of the list if the index is higher than the list length
|
||||||
|
|
||||||
|
* @param dest The list to insert into
|
||||||
|
* @param ind The index to insert at
|
||||||
|
* @param src The Object to add to the list
|
||||||
|
|
||||||
|
* @warning UNTESTED
|
||||||
|
*/
|
||||||
|
void insertIntoList(Object *dest, unsigned ind, const Object src)
|
||||||
{
|
{
|
||||||
// Only work with non-null list types
|
// Only work with non-null list types
|
||||||
if(!dest || dest->type != TYPE_LIST || ind < 0)
|
if(!dest || dest->type != TYPE_LIST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(isEmpty(dest)) {
|
if(isEmpty(dest)) {
|
||||||
|
@ -125,7 +146,7 @@ void insertIntoList(Object *dest, int ind, const Object src)
|
||||||
// TODO Check for off-by-one errors
|
// TODO Check for off-by-one errors
|
||||||
// ensure pointers connect old and new
|
// ensure pointers connect old and new
|
||||||
Object *march = dest->list;
|
Object *march = dest->list;
|
||||||
for(int i = 1; i < ind; i++) {
|
for(unsigned i = 1; i < ind; i++) {
|
||||||
if(march->forward == NULL) {
|
if(march->forward == NULL) {
|
||||||
allocObject(&march->forward, src);
|
allocObject(&march->forward, src);
|
||||||
return;
|
return;
|
||||||
|
@ -139,15 +160,30 @@ void insertIntoList(Object *dest, int ind, const Object src)
|
||||||
march->forward->forward = oldForward;
|
march->forward->forward = oldForward;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace an object in a list at a given index with a given object
|
||||||
|
* Attempts to clean the replaced Object before adding the new one
|
||||||
|
* Immediately returns if `list` is NULL or not a list type
|
||||||
|
* @param list The list Object to replace an element of
|
||||||
|
* @param i The index of the element to replace
|
||||||
|
* @param src The Object to copy into the list
|
||||||
|
*/
|
||||||
void replaceListing(Object *list, int i, const Object src)
|
void replaceListing(Object *list, int i, const Object src)
|
||||||
{
|
{
|
||||||
if(!list)
|
if(!list || list->type != TYPE_LIST)
|
||||||
return;
|
return;
|
||||||
list[i] = src;
|
Object *replace = itemAt(list, i);
|
||||||
list[i].forward = NULL;
|
cleanObject(replace);
|
||||||
|
*replace = src;
|
||||||
|
replace->forward = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an object to the end of a list object
|
/**
|
||||||
|
* Adds an Object to the end of a list
|
||||||
|
* Does nothing if `dest` is NULL or not a list type
|
||||||
|
* @param dest The list to append to
|
||||||
|
* @param src The Object to copy into the list
|
||||||
|
*/
|
||||||
void nf_addToList(Object *dest, const Object src)
|
void nf_addToList(Object *dest, const Object src)
|
||||||
{
|
{
|
||||||
if(!dest || dest->type != TYPE_LIST)
|
if(!dest || dest->type != TYPE_LIST)
|
||||||
|
@ -158,8 +194,7 @@ void nf_addToList(Object *dest, const Object src)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *end = tail(dest);
|
allocObject(&tail(dest)->forward, src);
|
||||||
allocObject(&end->forward, src);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printErr(const Object *obj)
|
void printErr(const Object *obj)
|
||||||
|
@ -302,24 +337,27 @@ void printAndClean(Object *target)
|
||||||
// Frees all objects in a list
|
// Frees all objects in a list
|
||||||
void deleteList(const Object *dest)
|
void deleteList(const Object *dest)
|
||||||
{
|
{
|
||||||
|
if(!dest)
|
||||||
|
return;
|
||||||
|
|
||||||
if(dest->type != TYPE_LIST) {
|
if(dest->type != TYPE_LIST) {
|
||||||
printf("Tried to delete something other than a list\n");
|
printf("Tried to delete something other than a list\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *tail = dest->list;
|
Object *march = dest->list;
|
||||||
while(tail != NULL) {
|
while(march != NULL) {
|
||||||
Object *prevTail = tail;
|
Object *prevMarch = march;
|
||||||
tail = tail->forward;
|
march = march->forward;
|
||||||
cleanObject(prevTail);
|
cleanObject(prevMarch);
|
||||||
free(prevTail);
|
free(prevMarch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies all items from `src` to `dest`
|
* Copies all items from `src` to `dest`
|
||||||
* Does nothing if either is NULL, or neither are lists
|
* Does nothing if either is NULL, or not a list type
|
||||||
* First deletes all items from `dest`
|
* Deletes all items from `dest` before copying
|
||||||
*/
|
*/
|
||||||
void copyList(Object *dest, const Object *src)
|
void copyList(Object *dest, const Object *src)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef OBJECT_H
|
#ifndef OBJECT_H
|
||||||
#define OBJECT_H
|
#define OBJECT_H
|
||||||
|
|
||||||
#define MAX_TOK_LEN 4 // 11
|
#define MAX_TOK_LEN 10 // 11
|
||||||
#define MAX_TOK_CNT 128 // 128
|
#define MAX_TOK_CNT 128 // 128
|
||||||
#define MAX_ENV_ELM 15 // 50
|
#define MAX_ENV_ELM 15 // 50
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ int getType(const Object *obj);
|
||||||
|
|
||||||
int isEmpty(const Object *obj);
|
int isEmpty(const Object *obj);
|
||||||
Object *tail(const Object *listObj);
|
Object *tail(const Object *listObj);
|
||||||
void insertIntoList(Object *dest, int ind, const Object src);
|
void insertIntoList(Object *dest, unsigned ind, const Object src);
|
||||||
void replaceListing(Object *list, int i, const Object src);
|
void replaceListing(Object *list, int i, const Object src);
|
||||||
void nf_addToList(Object *dest, Object src);
|
void nf_addToList(Object *dest, Object src);
|
||||||
void deleteList(const Object *dest);
|
void deleteList(const Object *dest);
|
||||||
|
|
Loading…
Reference in New Issue