Skip to content

Commit 140efe4

Browse files
committed
Splitting strings into vectors
1 parent 44dafdd commit 140efe4

12 files changed

+108
-44
lines changed

ObjectTree.c

+1
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ void writeFunction(FILE * outh, Object * tree, int indent, bool sigOnly)
732732

733733
compilerDebugPrintf ("Looking up category %s\n",tree->returnType);
734734

735+
735736
if (rType) {
736737
compilerDebugPrintf("Line%d %s\n",__LINE__, tree->fullname);
737738
if (getFlag(rType, FLAG_PRIMITIVE)) {

ObjectTree.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ struct _Object {
8989
OBJ_TYPE category; //What is this? (Variable, Function, Class)
9090
char *returnType; //What value category?(int, int, NULL)
9191
char *genericType; //What value category if the returnType is Generic?(int, int, NULL)
92-
int genericTypeArgPos; //What value category if the returnType is Generic?(int, int, NULL)
92+
int genericTypeArgPos; //What position of the returnType is Generic?(int, int, NULL)
93+
char *resolvedSpecificType; //Generic type resolved as specific
9394
ListString *paramTypes; //parameters? (NULL, [int, int], NULL)
9495
ListObject *definedSymbols; //Things inside? (NULL, [Rectangle "r1", Rectangle "r2", int "a1", int "a2"], [int "w", int "h", Constructor "Rectangle", Function "Area"])
9596
ListString *code; //CodeBlock (NULL, "int ...calcTotalArea...(...) {...", "typedef struct...")

crsl.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void defineRSLSymbols(Object * root, bool waferSupport)
195195
addSymbol(root, rslFunc);
196196
rslFunc =
197197
CreateObject("getObjectAtIndex", "String" COMPILER_SEP "getObjectAtIndex" COMPILER_SEP "int", 0,
198-
Function, "Char");
198+
Function, "char");
199199
setFlags(rslFunc, FLAG_EXTERNAL);
200200
addParam(rslFunc, "String");
201201
addParam(rslFunc, "int");
@@ -329,7 +329,7 @@ void defineRSLSymbols(Object * root, bool waferSupport)
329329
addSymbol(root, rslFunc);
330330
// ============== Print Functions ===============
331331
rslFunc =
332-
CreateObject("print", "print" COMPILER_SEP "Char", 0, Function, "int");
332+
CreateObject("print", "print" COMPILER_SEP "char", 0, Function, "int");
333333
setFlags(rslFunc, FLAG_EXTERNAL);
334334
addParam(rslFunc, "int");
335335
addSymbol(root, rslFunc);
@@ -349,7 +349,7 @@ void defineRSLSymbols(Object * root, bool waferSupport)
349349
addSymbol(root, rslFunc);
350350

351351
rslFunc =
352-
CreateObject("echo", "echo" COMPILER_SEP "Char", 0, Function, "int");
352+
CreateObject("echo", "echo" COMPILER_SEP "char", 0, Function, "int");
353353
setFlags(rslFunc, FLAG_EXTERNAL);
354354
addParam(rslFunc, "int");
355355
addSymbol(root, rslFunc);

errors.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ int errorMsg(const char *format, ...)
1717
{
1818
int ret;
1919
fprintf(stderr, ANSI_COLOR_RED);
20-
fprintf(stderr, "Line %d: Column:%d - ", g_lineNum-g_headerLines, g_lineCol);
20+
//fprintf(stderr, "Line %d: Column:%d - ", g_lineNum-g_headerLines, g_lineCol);
21+
fprintf(stderr, "Line %d: Column:%d - ", g_lineNum, g_lineCol);
2122
va_list arg;
2223
va_start(arg, format);
2324
ret = vfprintf(stderr, format, arg);

ext/BetterString/BetterString.c

+50-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#include "ext/BetterString/BetterString.h"
2+
#include "rsl/RSL_Vector.h"
3+
4+
IDENT_MPTR_RAW * BetterString_$_BetterString_$_BetterString_$_ (BetterString * b, IDENT_MPTR_RAW * $_mptr_in)
5+
{
6+
return _$_returnAppointer($_mptr_in,b,BetterString_$_destructor_$_);
7+
}
8+
29

310
IDENT_MPTR_RAW * BetterString_$_BetterString_$_ (IDENT_MPTR_RAW * $_mptr_in)
411
{
@@ -96,10 +103,29 @@ void BetterString_$_destructor_$_(IDENT_MPTR_RAW * b_)
96103
}
97104
}
98105

99-
IDENT_MPTR_RAW * BetterString_$_split_$_Char(IDENT_MPTR_RAW * b_, char c, IDENT_MPTR_RAW * $_mptr_in)
106+
IDENT_MPTR_RAW * BetterString_$_split_$_char(IDENT_MPTR_RAW * b_, char c, IDENT_MPTR_RAW * $_mptr_in)
100107
{
108+
_$_VARIABLE(_$_temp_vector);
109+
_$_VARIABLE(_$_temp_vector_item);
110+
_$_VARIABLE(_$_temp_betterstring);
101111
const_bstring b = b_->obj;
102-
return _$_returnAppointer($_mptr_in,bsplit(b,c),BetterStringList_$_destructor_$_);
112+
struct bstrList * result = bsplit(b,c);
113+
//printf("Parts %d ",result->qty);
114+
Vector_$_Vector_$_int(result->qty, _$_temp_vector, false, BetterString);
115+
/*
116+
Vector_$_putObjectAtIndex_$_Generic_$$_$_Generic_$$(_$v$_arr, _$v$_idx, _$v$_primIdx, _$v$_elem, _$v$_primElem,\
117+
_$v$_mptr, _$v$_primRet, _$v$_typeRet) */
118+
int i;
119+
120+
for (i=0;i<result->qty;i++) {
121+
BetterString_$_BetterString_$_BetterString_$_(bstrcpy(result->entry[i]),_$_temp_betterstring);
122+
Vector_$_putObjectAtIndex_$_Generic_$$_$_Generic_$$(_$_temp_vector, i, true,
123+
_$_temp_betterstring,
124+
false, _$_temp_vector_item, false, _$_mptr);
125+
}
126+
_$_mptr_prepare(_$_temp_vector,$_mptr_in);
127+
bstrListDestroy(result);
128+
return $_mptr_in;
103129
}
104130

105131
IDENT_MPTR_RAW * BetterString_$_split_$_String(IDENT_MPTR_RAW * b_, IDENT_MPTR_RAW * s_, IDENT_MPTR_RAW * $_mptr_in)
@@ -108,11 +134,31 @@ IDENT_MPTR_RAW * BetterString_$_split_$_String(IDENT_MPTR_RAW * b_, IDENT_MPTR_
108134
String * s = s_->obj;
109135
bstring sBstring = bfromcstr(s->buffer);
110136
struct bstrList * result = bsplitstr(b,sBstring);
137+
138+
_$_VARIABLE(_$_temp_vector);
139+
_$_VARIABLE(_$_temp_vector_item);
140+
_$_VARIABLE(_$_temp_betterstring);
141+
142+
//printf("Parts %d ",result->qty);
143+
Vector_$_Vector_$_int(result->qty, _$_temp_vector, false, BetterString);
144+
/*
145+
Vector_$_putObjectAtIndex_$_Generic_$$_$_Generic_$$(_$v$_arr, _$v$_idx, _$v$_primIdx, _$v$_elem, _$v$_primElem,\
146+
_$v$_mptr, _$v$_primRet, _$v$_typeRet) */
147+
int i;
148+
149+
for (i=0;i<result->qty;i++) {
150+
BetterString_$_BetterString_$_BetterString_$_(bstrcpy(result->entry[i]),_$_temp_betterstring);
151+
Vector_$_putObjectAtIndex_$_Generic_$$_$_Generic_$$(_$_temp_vector, i, true,
152+
_$_temp_betterstring,
153+
false, _$_temp_vector_item, false, _$_mptr);
154+
}
155+
_$_mptr_prepare(_$_temp_vector,$_mptr_in);
111156
bdestroy(sBstring);
112-
return _$_returnAppointer($_mptr_in,result,BetterStringList_$_destructor_$_);
157+
bstrListDestroy(result);
158+
return $_mptr_in;
113159
}
114160

115-
IDENT_MPTR_RAW * BetterString_$_splits_$_Char(IDENT_MPTR_RAW * b_, IDENT_MPTR_RAW * s_, IDENT_MPTR_RAW * $_mptr_in)
161+
IDENT_MPTR_RAW * BetterString_$_splits_$_String(IDENT_MPTR_RAW * b_, IDENT_MPTR_RAW * s_, IDENT_MPTR_RAW * $_mptr_in)
116162
{
117163
const_bstring b = b_->obj;
118164
String * s = s_->obj;

ext/BetterString/BetterString.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
typedef struct tagbstring BetterString;
1010
typedef struct bstrList BetterStringList;
1111

12+
IDENT_MPTR_RAW * BetterString_$_BetterString_$_BetterString_$_ (BetterString * b, IDENT_MPTR_RAW * $_mptr_in);
13+
IDENT_MPTR_RAW * BetterString_$_BetterString_$_ (IDENT_MPTR_RAW * $_mptr_in);
1214
IDENT_MPTR_RAW * BetterString_$_BetterString_$_String(IDENT_MPTR_RAW * s_, IDENT_MPTR_RAW * $_mptr_in);
1315
IDENT_MPTR_RAW * BetterString_$_toString_$_(IDENT_MPTR_RAW * b, IDENT_MPTR_RAW * $_mptr_in);
1416
void BetterString_$_destructor_$_(IDENT_MPTR_RAW * b_);
1517

16-
IDENT_MPTR_RAW * BetterString_$_split_$_Char(IDENT_MPTR_RAW * b, char c, IDENT_MPTR_RAW * $_mptr_in);
18+
IDENT_MPTR_RAW * BetterString_$_split_$_char(IDENT_MPTR_RAW * b, char c, IDENT_MPTR_RAW * $_mptr_in);
1719
IDENT_MPTR_RAW * BetterString_$_split_$_String(IDENT_MPTR_RAW * b_, IDENT_MPTR_RAW * s_, IDENT_MPTR_RAW * $_mptr_in);
20+
IDENT_MPTR_RAW * BetterString_$_splits_$_String(IDENT_MPTR_RAW * b_, IDENT_MPTR_RAW * s_, IDENT_MPTR_RAW * $_mptr_in);
1821
IDENT_MPTR_RAW * BetterStringList_$_getObjectAtIndex_$_int(IDENT_MPTR_RAW * bList_, int i, IDENT_MPTR_RAW * $_mptr_in);
1922
void BetterStringList_$_destructor_$_(IDENT_MPTR_RAW * bList_);
2023

ext/BetterString/BetterString.rix

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import ("rsl/Vector.rix")
2+
13
##external "ext/BetterString/BetterString.h"
24
##addsource "ext/BetterString/BetterString.c"
35
##addsource "ext/BetterString/bstrlib.c"
4-
import ("rsl/Vector.rix")
6+
57
BetterString::String
68
$(String string)
79
//virtual
@@ -15,13 +17,13 @@ BetterString::String
1517
toUpper->BetterString()
1618
//virtual
1719

18-
split->Vector (Char __c__)
20+
split->Vector{BetterString} (char c)
1921
//extern struct bstrList * bsplit (bstring str, unsigned char splitChar);
2022

21-
split->Vector (String __s__)
23+
split->Vector{BetterString} (String s)
2224
//extern struct bstrList * bsplit (bstring str, unsigned char splitChar);
2325

24-
splits->Vector (String __s__)
26+
splits->Vector{BetterString} (String s)
2527
//extern struct bstrList * bsplit (bstring str, unsigned char splitChar);
26-
28+
2729
##external ""

rix.y

+3-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ anyIdentOrVerb:
241241
;
242242

243243
function_definition:
244-
anyIdentOrVerb RETURN TYPE LPAREN parameters RPAREN { compilerDebugPrintf("parser: func-def\n"); $$ = beginFunction($3, $1, $5); }
245-
| anyIdentOrVerb RETURN LPAREN parameters RPAREN { compilerDebugPrintf("parser: func-void\n"); $$ = beginFunction("void", $1, $4); }
244+
anyIdentOrVerb RETURN TYPE LPAREN parameters RPAREN { compilerDebugPrintf("parser: func-def\n"); $$ = beginFunction($1, $3, 0, $5); }
245+
| anyIdentOrVerb RETURN LPAREN parameters RPAREN { compilerDebugPrintf("parser: func-void\n"); $$ = beginFunction($1, "void", 0, $4); }
246+
| anyIdentOrVerb RETURN TYPE LBRACE TYPE RBRACE LPAREN parameters RPAREN { compilerDebugPrintf("parser: func-def-gen\n"); $$ = beginFunction($1, $3, $5, $8); }
246247
;
247248

248249
parameters:

rixc.c

+32-23
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void doneClass(Object * tree)
133133
scope_pop();
134134
}
135135

136-
Object *beginFunction(char *returnType, char *funcName, Object * parameters)
136+
Object *beginFunction(char *funcName, char *returnType, char *resolvedSpecificType, Object * parameters)
137137
{
138138
if (returnType == 0) {
139139
criticalError(ERROR_ParseError, "Return category mustn't be null.\n");
@@ -206,7 +206,7 @@ Object *beginFunction(char *returnType, char *funcName, Object * parameters)
206206
}
207207
//add parameters to the function
208208
types = parameters->paramTypes;
209-
//assuming for every category there is a name
209+
//assuming for every Type there is a name
210210
while (types != 0) {
211211
if (!external) {
212212
addSymbol(result,
@@ -217,6 +217,11 @@ Object *beginFunction(char *returnType, char *funcName, Object * parameters)
217217
types = types->next;
218218
}
219219

220+
//If the return type is a generic type...
221+
if (resolvedSpecificType) {
222+
compilerDebugPrintf("Setting generic ytype (%s)\n", resolvedSpecificType);
223+
result->resolvedSpecificType=resolvedSpecificType;
224+
}
220225

221226
addSymbol(parentScope, result);
222227
scope_push(result);
@@ -1029,6 +1034,7 @@ Object *conjugate(Object * subject, Object * verb, Object * objects)
10291034
if (!realVerb) {
10301035
realVerb = findFunctionByFullName(genericVerbName);
10311036
genericVerb = true;
1037+
compilerDebugPrintf("%s is a Generic Verb\n",genericVerbName);
10321038
}
10331039

10341040
if (!realVerb && subject) {
@@ -1211,27 +1217,30 @@ Object *conjugate(Object * subject, Object * verb, Object * objects)
12111217
//== Generic shenanigans ==
12121218
//compilerDebugPrintf("Conjverb Generic type %s\n",verb->genericType);
12131219

1214-
if (verb->genericType) {
1215-
// if (hasParams) {
1216-
// invoke_pos += snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, "/* verb is generic */");
1217-
// }
1218-
result->genericType = strdup(verb->genericType);
1220+
if (verb->resolvedSpecificType) {
1221+
result->genericType = strdup(verb->resolvedSpecificType);
1222+
} else if (verb->genericType) {
1223+
result->genericType = strdup(verb->genericType);
12191224

1220-
Object * pType = findByName(result->genericType);
1221-
if (pType&&getFlag(pType,FLAG_PRIMITIVE)) {
1222-
invoke_pos +=
1223-
snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, ",true");
1224-
} else {
1225+
if (hasParams) {
1226+
invoke_pos += snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, ", ");
1227+
}
1228+
1229+
Object *pType = findByName(result->genericType);
1230+
if (pType && getFlag(pType, FLAG_PRIMITIVE)) {
1231+
invoke_pos +=
1232+
snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, "true");
1233+
} else {
1234+
invoke_pos +=
1235+
snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, "false");
1236+
}
12251237
invoke_pos +=
1226-
snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, ",false");
1227-
}
1228-
invoke_pos +=
1229-
snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, ",%s",result->genericType);
1238+
snprintf(&invocation[invoke_pos], BUFFLEN - invoke_pos, ",%s", result->genericType);
12301239
}
12311240

12321241

12331242

1234-
if (!strcmp(realVerb->returnType, "Generic_$$")) {
1243+
if (!strcmp(realVerb->returnType, GENERIC_PARAM)) {
12351244
if (realVerb->genericType) {
12361245
result->returnType = strdup(realVerb->genericType);
12371246
addParam(result, realVerb->genericType);
@@ -1426,7 +1435,7 @@ Object *sVerbIdent(char *staticVerb)
14261435
return result;
14271436
}
14281437

1429-
Object *verbCtor(char *type, char *ytype)
1438+
Object *verbCtor(char *type, char *genericType)
14301439
{
14311440
compilerDebugPrintf("verbCtor(%s)\n", type);
14321441
Object *result = findByName(type);
@@ -1435,9 +1444,9 @@ Object *verbCtor(char *type, char *ytype)
14351444
sprintf(error, "Cannot find Class \"%s\".\n", type);
14361445
criticalError(ERROR_UndefinedVerb, error);
14371446
}
1438-
if (ytype) {
1439-
compilerDebugPrintf("Setting generic ytype (%s)\n", ytype);
1440-
result->genericType=ytype;
1447+
if (genericType) {
1448+
compilerDebugPrintf("Setting generic ytype (%s)\n", genericType);
1449+
result->genericType=genericType;
14411450
}
14421451
return result;
14431452
}
@@ -1587,9 +1596,9 @@ Object *objectChar(char *c)
15871596
compilerDebugPrintf("objectInt(%c)\n", c[1]);
15881597
char buffer[4]; // 20 = (log10(2^64))
15891598
snprintf(buffer, 4, "%s", c);
1590-
Object *result = CreateObject(0, 0, 0, Expression, "Char");
1599+
Object *result = CreateObject(0, 0, 0, Expression, "char");
15911600
addCode(result, buffer);
1592-
addParam(result, "Char");
1601+
addParam(result, "char");
15931602
return result;
15941603
}
15951604

rixc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void decPrev();
3131

3232
Object *beginClass(char *className, char *parentName, Object *typeArgs, bool isPrimitive);
3333
void doneClass(Object * tree);
34-
Object *beginFunction(char *returnType, char *funcName, Object * parameters);
34+
Object *beginFunction(char *funcName, char *returnType, char *returnGenericType, Object * parameters);
3535
void doneFunction(Object * tree);
3636
Object *beginConstructor(Object * parameters);
3737
void doneConstructor(Object * tree);

rsl/RSL_String.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ IDENT_MPTR_RAW * String_$_plus_$_int(IDENT_MPTR_RAW * left_, int right, IDENT_MP
8585
{
8686

8787
debugPrintf("String_$_plus_$_int %s -> %s\n",left_->debugName, $_mptr_in->debugName);
88-
_$_mptr __attribute__ ((__cleanup__(_$_cleanup))) $_mptr_temp; IDENT_MPTR_INITIALIZE_RAW (&$_mptr_temp,
89-
xstr($_mptr_temp));
88+
_$_mptr __attribute__ ((__cleanup__(_$_cleanup))) $_mptr_temp;
89+
IDENT_MPTR_INITIALIZE_RAW (&$_mptr_temp, xstr($_mptr_temp));
9090
IDENT_MPTR_RAW * s_ = String_$_String_$_(&$_mptr_temp);
9191
String * s = s_->obj;
9292
String * left = left_->obj;

rsl/rsl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct {
4444

4545
typedef void *UNKNOWNTYPE;
4646
UNKNOWNTYPE UNKNOWNOBJECT;
47-
typedef char Char;
47+
//typedef char Char;
4848
typedef enum { lt = -1, eq = 0, gt = 1 } Ternary;
4949
typedef void *System;
5050
typedef void *Generic_$$;

0 commit comments

Comments
 (0)