Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5f77fb6
Rename README to README.md
thewarpaint Jun 1, 2015
4726c4a
Fugly hack to make the tests pass for non-64-bit platforms
e8johan Jun 2, 2015
b3a33ed
fix build on windows
mattn Jun 3, 2015
d119e7a
Create 69_shebang_script.c
sburford Jun 3, 2015
821de33
Create 69_shebang_script.expect
sburford Jun 3, 2015
34b0f2d
Update Makefile
sburford Jun 3, 2015
39d07e0
Update Makefile
sburford Jun 3, 2015
f172a6e
Update 69_shebang_script.expect
sburford Jun 3, 2015
ebfdaf6
Fix up test file content.
sburford Jun 3, 2015
b1755e8
Update platform_unix.c
sburford Jun 3, 2015
5f2f714
Merge branch 'fewer-crashes' of https://github.com/sburford/picoc int…
sburford Jun 3, 2015
0a0b35c
Fix all the type cast warnings by adding explicit casts.
galacticstudios Aug 11, 2015
fb8ce01
Add some documentation from the old Google Code site
galacticstudios Aug 11, 2015
1d857d2
Add run_tests, an executable that runs all the PicoC unit tests
galacticstudios Aug 11, 2015
5a67fa4
Fix string functions under Windows. index() is the same as strchr() a…
galacticstudios Aug 11, 2015
0d1f88e
Execute scripts in their own directory. Have the unit tester dump the…
galacticstudios Aug 11, 2015
fc0dee6
Fix errors in the 65_typeless unit test
galacticstudios Aug 11, 2015
2bb0833
Compile as a 64 bit executable in Windows
galacticstudios Aug 11, 2015
25f1eac
More type casts to eliminate warnings. Compiling as 64 bits caused ne…
galacticstudios Aug 11, 2015
a5537ac
Use intptr_t to make 'long' the same size as a pointer on all platforms.
galacticstudios Aug 12, 2015
ab602f3
Switch longs from intptr_t to int64_t, so it's now 64 bits on all pla…
galacticstudios Aug 12, 2015
60b74e2
Remove need for LONG_PTR
galacticstudios Aug 12, 2015
45c99a7
Fix Linux warnings
galacticstudios Aug 12, 2015
abd7473
Fix more Linux warnings
galacticstudios Aug 12, 2015
8018ff8
Fix some problems with 64 bit ints. Also fix unsigned right shifts (m…
galacticstudios Aug 13, 2015
0e2d5f0
Change the names of the ExpressionCoerce functions to indicate that t…
galacticstudios Aug 14, 2015
ba4c0e9
Fix incorrect conditions
galacticstudios Aug 14, 2015
ca6ec4e
Be more frugal in allocating memory for the token when lexing. This f…
galacticstudios Aug 14, 2015
3f499c8
Remove Google Code's decorations; add info about type promotion.
galacticstudios Aug 14, 2015
03842bd
Fix Issue 130 from Google Code (https://code.google.com/p/picoc/issue…
galacticstudios Aug 15, 2015
0e2c492
Fix bug 190 at https://code.google.com/p/picoc/issues/detail?id=190, …
galacticstudios Aug 17, 2015
192e7bc
Create initial .travis.yml file for basic configurations.
GregAujay Aug 17, 2015
cc39109
Merge 'GregAujay/feature/enable-travis-ci'.
mpontillo Mar 1, 2017
c965174
Merge 'sburford/fewer-crashes'.
mpontillo Mar 1, 2017
e09ca4b
Merge 'mattn/windows'.
mpontillo Mar 1, 2017
1cceaa4
Merge 'e8johan/types-64bit'.
mpontillo Mar 1, 2017
08dac96
Merge 'thewarpaint/rename-readme'.
mpontillo Mar 1, 2017
5a8cfd0
Add .gitignore.
mpontillo Mar 1, 2017
8e8b0ac
Mention libreadline requirement in the README.
mpontillo Mar 1, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
picoc
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: c
compiler:
- gcc
- clang
env:
- CFLAGS="-Wall -pedantic -g -DUNIX_HOST"
- CFLAGS="-m32 -Wall -pedantic -g -DUNIX_HOST"
install:
- sudo apt-get update -qq
- sudo apt-get install -qq gcc-multilib lib32readline6-dev
script: make && make test
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
CC?=gcc
VERSION+=$(shell git log --oneline -n 1 | sed 's/\ .*//')$(shell git status --porcelain | grep -q '^\ M' && echo -n M)
CC=gcc
CFLAGS=-Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"
CFLAGS=-Wall -pedantic -g -DUNIX_HOST -DVER=\"${VERSION}\"
LIBS=-lm -lreadline

TARGET = picoc
Expand Down
2 changes: 2 additions & 0 deletions README → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ picoc can be compiled for a UNIX/Linux/POSIX host by typing "make".

The test suite can be run by typing "make test".

The `readline` library is necessary in order to compile picoc.


Porting picoc
-------------
Expand Down
17 changes: 10 additions & 7 deletions clibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ void LibraryAdd(Picoc *pc, struct Table *GlobalTable, const char *LibraryName, s
struct Value *NewValue;
void *Tokens;
char *IntrinsicName = TableStrRegister(pc, "c library");
UNUSED(GlobalTable); UNUSED(LibraryName);

/* read all the library definitions */
for (Count = 0; FuncList[Count].Prototype != NULL; Count++)
{
Tokens = LexAnalyse(pc, IntrinsicName, FuncList[Count].Prototype, strlen((char *)FuncList[Count].Prototype), NULL);
Tokens = LexAnalyse(pc, IntrinsicName, FuncList[Count].Prototype, (int) strlen((char *)FuncList[Count].Prototype), NULL);
LexInitParser(&Parser, pc, FuncList[Count].Prototype, Tokens, IntrinsicName, TRUE, FALSE);
TypeParse(&Parser, &ReturnType, &Identifier, NULL);
NewValue = ParseFunctionDefinition(&Parser, ReturnType, Identifier);
NewValue->Val->FuncDef.Intrinsic = FuncList[Count].Func;
NewValue->Val->FuncDef.Intrinsic = (void (*)()) FuncList[Count].Func;
HeapFreeMem(pc, Tokens);
}
}
Expand Down Expand Up @@ -304,11 +305,11 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
PrintStr(Str, Stream);
break;
}
case 'd': PrintInt(ExpressionCoerceInteger(NextArg), FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'u': PrintUnsigned(ExpressionCoerceUnsignedInteger(NextArg), 10, FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'x': PrintUnsigned(ExpressionCoerceUnsignedInteger(NextArg), 16, FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'b': PrintUnsigned(ExpressionCoerceUnsignedInteger(NextArg), 2, FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'c': PrintCh(ExpressionCoerceUnsignedInteger(NextArg), Stream); break;
case 'd': PrintInt(ExpressionCoerceLong(NextArg), FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'u': PrintUnsigned(ExpressionCoerceUnsignedLong(NextArg), 10, FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'x': PrintUnsigned(ExpressionCoerceUnsignedLong(NextArg), 16, FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'b': PrintUnsigned(ExpressionCoerceUnsignedLong(NextArg), 2, FieldWidth, ZeroPad, LeftJustify, Stream); break;
case 'c': PrintCh(ExpressionCoerceUnsignedLong(NextArg), Stream); break;
#ifndef NO_FP
case 'f': PrintFP(ExpressionCoerceFP(NextArg), Stream); break;
#endif
Expand Down Expand Up @@ -664,7 +665,9 @@ struct LibraryFunction CLibrary[] =
{ LibStrncmp, "int strncmp(char *,char *,int);" },
{ LibStrcat, "void strcat(char *,char *);" },
{ LibIndex, "char *index(char *,int);" },
{ LibIndex, "char *strchr(char *,int);" },
{ LibRindex, "char *rindex(char *,int);" },
{ LibRindex, "char *strrchr(char *,int);" },
{ LibStrlen, "int strlen(char *);" },
{ LibMemset, "void memset(void *,int,int);" },
{ LibMemcpy, "void memcpy(void *,void *,int);" },
Expand Down
16 changes: 16 additions & 0 deletions cstdlib/ctype.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,82 +6,98 @@

void StdIsalnum(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isalnum(Param[0]->Val->Integer);
}

void StdIsalpha(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isalpha(Param[0]->Val->Integer);
}

void StdIsblank(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
int ch = Param[0]->Val->Integer;
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = (ch == ' ') | (ch == '\t');
}

void StdIscntrl(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = iscntrl(Param[0]->Val->Integer);
}

void StdIsdigit(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isdigit(Param[0]->Val->Integer);
}

void StdIsgraph(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isgraph(Param[0]->Val->Integer);
}

void StdIslower(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = islower(Param[0]->Val->Integer);
}

void StdIsprint(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isprint(Param[0]->Val->Integer);
}

void StdIspunct(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = ispunct(Param[0]->Val->Integer);
}

void StdIsspace(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isspace(Param[0]->Val->Integer);
}

void StdIsupper(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isupper(Param[0]->Val->Integer);
}

void StdIsxdigit(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isxdigit(Param[0]->Val->Integer);
}

void StdTolower(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = tolower(Param[0]->Val->Integer);
}

void StdToupper(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = toupper(Param[0]->Val->Integer);
}

void StdIsascii(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = isascii(Param[0]->Val->Integer);
}

void StdToascii(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->Integer = toascii(Param[0]->Val->Integer);
}

Expand Down
27 changes: 25 additions & 2 deletions cstdlib/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,118 +21,141 @@ static double M_SQRT1_2Value = 0.70710678118654752440; /* 1/sqrt(2) */

void MathSin(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = sin(Param[0]->Val->FP);
}

void MathCos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = cos(Param[0]->Val->FP);
}

void MathTan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = tan(Param[0]->Val->FP);
}

void MathAsin(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = asin(Param[0]->Val->FP);
}

void MathAcos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = acos(Param[0]->Val->FP);
}

void MathAtan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = atan(Param[0]->Val->FP);
}

void MathAtan2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = atan2(Param[0]->Val->FP, Param[1]->Val->FP);
}

void MathSinh(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = sinh(Param[0]->Val->FP);
}

void MathCosh(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = cosh(Param[0]->Val->FP);
}

void MathTanh(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = tanh(Param[0]->Val->FP);
}

void MathExp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = exp(Param[0]->Val->FP);
}

void MathFabs(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = fabs(Param[0]->Val->FP);
}

void MathFmod(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = fmod(Param[0]->Val->FP, Param[1]->Val->FP);
}

void MathFrexp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = frexp(Param[0]->Val->FP, Param[1]->Val->Pointer);
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = frexp(Param[0]->Val->FP, (int *) Param[1]->Val->Pointer);
}

void MathLdexp(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = ldexp(Param[0]->Val->FP, Param[1]->Val->Integer);
}

void MathLog(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = log(Param[0]->Val->FP);
}

void MathLog10(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = log10(Param[0]->Val->FP);
}

void MathModf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = modf(Param[0]->Val->FP, Param[0]->Val->Pointer);
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = modf(Param[0]->Val->FP, (double *) Param[0]->Val->Pointer);
}

void MathPow(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = pow(Param[0]->Val->FP, Param[1]->Val->FP);
}

void MathSqrt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = sqrt(Param[0]->Val->FP);
}

void MathRound(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
/* this awkward definition of "round()" due to it being inconsistently
* declared in math.h */
ReturnValue->Val->FP = ceil(Param[0]->Val->FP - 0.5);
}

void MathCeil(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = ceil(Param[0]->Val->FP);
}

void MathFloor(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
UNUSED(Parser); UNUSED(NumArgs);
ReturnValue->Val->FP = floor(Param[0]->Val->FP);
}

Expand Down
Loading