summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2010-04-22 23:46:26 +0000
committerAdrian Thurston <thurston@complang.org>2010-04-22 23:46:26 +0000
commitb11ca9c5dc06080085cbffa55ba6be06004fd13b (patch)
tree5a678e8ce2da7bef4b6b114d3a8385085948f525
parent827822251edf0d360589dc314b40619f958c95e1 (diff)
downloadcolm-b11ca9c5dc06080085cbffa55ba6be06004fd13b.tar.gz
C porting, did whole string directory.
-rw-r--r--colm/Makefile.in4
-rw-r--r--colm/bytecode.h2
-rw-r--r--colm/bytecode2.h3
-rw-r--r--colm/string.c (renamed from colm/string.cpp)13
4 files changed, 13 insertions, 9 deletions
diff --git a/colm/Makefile.in b/colm/Makefile.in
index aa54c718..c775bd9f 100644
--- a/colm/Makefile.in
+++ b/colm/Makefile.in
@@ -61,8 +61,8 @@ COLM_SRC = \
pcheck.cpp \
ctinput.cpp
-RUNTIME_SRC = pdarun.cpp bytecode.cpp string.cpp tree.cpp
-RUNTIME_SRC_C = map.c fsmrun.c list.c input.c debug.c codevect.c pool.c
+RUNTIME_SRC = pdarun.cpp bytecode.cpp tree.cpp
+RUNTIME_SRC_C = map.c fsmrun.c list.c input.c debug.c codevect.c pool.c string.c
ALL_SRC = $(COLM_SRC) $(RUNTIME_SRC)
diff --git a/colm/bytecode.h b/colm/bytecode.h
index c2bd6ad9..349853c2 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -70,7 +70,6 @@ struct TreePair
};
bool testFalse( Program *prg, Tree *tree );
-Head *intToStr( Program *prg, Word i );
void rcodeDownref( Program *prg, Tree **sp, Code *instr );
void rcodeDownrefAll( Program *prg, Tree **sp, RtCodeVect *cv );
@@ -78,7 +77,6 @@ void commitFull( Tree **sp, PdaRun *parser, long commitReduce );
Tree *getParsedRoot( PdaRun *pdaRun, bool stop );
bool matchPattern( Tree **bindings, Program *prg, long pat, Kid *kid, bool checkNext );
-Head *makeLiteral( Program *prg, long litoffset );
Tree *constructInteger( Program *prg, long i );
Tree *constructPointer( Program *prg, Tree *tree );
Tree *constructTerm( Program *prg, Word id, Head *tokdata );
diff --git a/colm/bytecode2.h b/colm/bytecode2.h
index c06eff99..f61a8a01 100644
--- a/colm/bytecode2.h
+++ b/colm/bytecode2.h
@@ -412,6 +412,9 @@ Head *stringToUpper( Head *s );
Head *stringToLower( Head *s );
Head *stringSprintf( Program *prg, Str *format, Int *integer );
+Head *makeLiteral( Program *prg, long litoffset );
+Head *intToStr( Program *prg, Word i );
+
Tree *constructString( Program *prg, Head *s );
void initExecution( Execution *exec, Program *prg, RtCodeVect *reverseCode,
diff --git a/colm/string.cpp b/colm/string.c
index 0a89e45b..c9a41b6d 100644
--- a/colm/string.cpp
+++ b/colm/string.c
@@ -21,11 +21,12 @@
#include "pool.h"
#include "pdarun.h"
-#include "bytecode.h"
+#include "bytecode2.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <ctype.h>
/*
* In this system strings are not null terminated. Often strings come from a
@@ -87,8 +88,8 @@ Head *initStrSpace( long length )
{
/* Find the length and allocate the space for the shared string. */
Head *head = (Head*) malloc( sizeof(Head) + length );
- if ( head == 0 )
- throw std::bad_alloc();
+ //if ( head == 0 )
+ // throw std::bad_alloc();
/* Init the header. */
head->data = (char*)(head+1);
@@ -148,7 +149,8 @@ Head *stringToUpper( Head *s )
/* Copy in the data. */
const char *src = s->data;
char *dst = (char*)(head+1);
- for ( int i = 0; i < len; i++ )
+ int i;
+ for ( i = 0; i < len; i++ )
*dst++ = toupper( *src++ );
return head;
@@ -163,7 +165,8 @@ Head *stringToLower( Head *s )
/* Copy in the data. */
const char *src = s->data;
char *dst = (char*)(head+1);
- for ( int i = 0; i < len; i++ )
+ int i;
+ for ( i = 0; i < len; i++ )
*dst++ = tolower( *src++ );
return head;