Giter VIP home page Giter VIP logo

picoc's Introduction

picoc
-----

PicoC is a very small C interpreter for scripting. It was originally written 
as a script language for a UAV's on-board flight system. It's also very 
suitable for other robotic, embedded and non-embedded applications.

The core C source code is around 3500 lines of code. It's not intended to be 
a complete implementation of ISO C but it has all the essentials. When 
compiled it only takes a few k of code space and is also very sparing of 
data space. This means it can work well in small embedded devices. It's also 
a fun example of how to create a very small language implementation while 
still keeping the code readable.

picoc is now feature frozen. Since it's important that it remain small it's 
intended that no more major features will be added from now on. It's been 
tested on x86-32, x86-64, powerpc, arm, ultrasparc, HP-PA and blackfin 
processors and is easy to port to new targets. 


Compiling picoc
---------------

picoc can be compiled for a UNIX/Linux/POSIX host by typing "make".

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


Porting picoc
-------------

platform.h is where you select your platform type and specify the includes 
etc. for your platform.

platform_XXX.c contains support functions so the compiler can work on 
your platform, such as how to write characters to the console etc..

platform_library.c contains your library of functions you want to make 
available to user programs.

There's also a clibrary.c which contains user library functions like 
printf() which are platform-independent.

Porting the system will involve setting up suitable includes and defines 
in platform.h, writing some I/O routines in platform_XXX.c, putting 
whatever user functions you want in platform_library.c and then changing 
the main program in picoc.c to whatever you need to do to get programs 
into the system.

platform.h is set to UNIX_HOST by default so tests can be easily run on
a UNIX system. You'll need to specify your own host setup dependent on 
your target platform.


Copyright
---------

picoc is published under the "New BSD License".
http://www.opensource.org/licenses/bsd-license.php


Copyright (c) 2009-2011, Zik Saleeba
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are 
met:

    * Redistributions of source code must retain the above copyright 
      notice, this list of conditions and the following disclaimer.
      
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in 
      the documentation and/or other materials provided with the 
      distribution.
      
    * Neither the name of the Zik Saleeba nor the names of its 
      contributors may be used to endorse or promote products derived 
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

picoc's People

Watchers

 avatar

picoc's Issues

*dest++ = *src++; doesn't work

Test case 21_char_array.c results in:

zik@initech:~/work/picoc$ ./picoc tests/21_char_array.c 
hello
h: 104
e: 101
l: 108
l: 108
o: 111
tests/21_char_array.c:22: invalid operation

Line 22 is:
*dest++ = *src++;

Original issue reported on code.google.com by [email protected] on 3 Jun 2009 at 1:25

Crash in interactive mode

Example program:

int fred()
{
    printf("yo\n");
    return 0;
}

fred();

zik@initech:~/work/picoc$ ./picoc -i <tester.c
starting picoc
picoc>      >      >      >      > picoc>      > Segmentation fault

Original issue reported on code.google.com by [email protected] on 4 Oct 2009 at 4:31

"int a = *;" doesn't report an error

In ExpressionParse, I added a flag "RequireValue" in order to signal an
error in the following case: "int a = *;", which did not report an error
before.

Original issue reported on code.google.com by [email protected] on 2 Jun 2009 at 12:41

Local scopes are not created when defining functions

local scopes are not created when defining functions, so that any defined
variable ends up in the previous scope (such as the global scope). I simply
added the creation of a scope in ParseFunctionDefinition and it seems to
have fixed the problem, as expected.

Original issue reported on code.google.com by [email protected] on 2 Jun 2009 at 12:40

Better reporting of invalid type definitions

In TypeParseIdentPart, I added TokenEOF, TokenComma, TokenCloseBracket, and
TokenSemicolon as loop terminations (like the present default case does).
The new default case now reports an error saying it's an invalid type
definition

Original issue reported on code.google.com by [email protected] on 2 Jun 2009 at 12:49

Initialisation problem on SRV-1

Howard reports:

I think I told you that I had to roll back from 0.92 to 0.91 because of
stability issues, but we still have an issue in 0.91, and I'm hoping you
might have some suggestions.  Sometimes, but not always, after starting the
Blackfin, if I go directly into the interpreter in interactive mode or if I
load a program, the system crashes with this output -

   c library:4: too many parameters

It seems to be happening out of Initialise().  If I reboot the Blackfin,
the problem generally clears, so I assume it is some kind of static
variable in L1 that isn't getting cleared properly at startup.  Do you have
any idea of what might need to be initialized ?  Maybe this is something
you fixed between 0.91 and 0.92.

Original issue reported on code.google.com by [email protected] on 4 Oct 2009 at 3:21

Problem with error exit under cygwin

bash-3.2$ ./picoc -i
starting picoc
picoc> int a;
picoc> void fred()
     > {
     > for (a=0; a<10; a++)
     >     printf("%d\n", a);
     > exit();
     > printf("yo\n");
     > }
picoc> fred();

Original issue reported on code.google.com by [email protected] on 15 Jun 2009 at 2:20

implement something to point a memory mapped device

I'd like to use picoC on an embedded board (mc68000) without any OS

so if picoC is part of the "firmware" then it should be nice to directly
point a "memory mapped device"


if the "memory-mapped device" is located at 0x8000, you can access it using
 something like the following


#define device_addr 0x8000
#define pdevice_bytetype volatile unsigned char
pdevice_bytetype xdata *pdevice_byte = (char xdata *) device_addr;


u-mmm may be it could be simplified without any CASTING

pdevice_bytetype xdata *pdevice_byte = device_addr;


device_addr is a "native pointer" that access directly the address pointed!


could you implement this feature ?

Original issue reported on code.google.com by [email protected] on 14 Sep 2009 at 8:41

Software floating point support

Architectures with no floating point support could benefit from a software
floating point library. Also, architectures with no math library could
benefit from a math library.

Original issue reported on code.google.com by [email protected] on 28 May 2009 at 4:05

Floating point is broken

What steps will reproduce the problem?
1. int a = 12.34;
2. printf("%f\n", a);

Results in an infinite loop printing "0"s.

Original issue reported on code.google.com by [email protected] on 26 May 2009 at 10:03

sizeof doen't work

What steps will reproduce the problem?
1. sizeof operator does not work.
2. It will be good to have
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 10 Jul 2009 at 4:26

Short identifier is not working

What steps will reproduce the problem?
1.Give short int i; or give short i;
2.It gives short is undefined.
3. Even inside structure short identifier is not working.

What is the expected output? What do you see instead?
Should take short, and assign 16 bit


What version of the product are you using? On what operating system?
Latest

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 8 Jul 2009 at 8:38

test/21_char_array fails on host=ppc

What steps will reproduce the problem?

test/21_char_array.c

What is the expected output? What do you see instead?

___test________________________
hello
h: 104
e: 101
l: 108
l: 108
o: 111
copied string is 
___expected____________________
hello
h: 104
e: 101
l: 108
l: 108
o: 111
copied string is hello
___diff________________________
7c7
< copied string is 

---
> copied string is hello

What version of the product are you using? On what operating system?
gcc version 4.1.2/linux/ppc/bigendian


Original issue reported on code.google.com by [email protected] on 11 Sep 2009 at 9:38

HeapAlloc() is reserved in win32

HeapAlloc is reserved in a Win32 program. I changed it to HeapAllocMem (and
also changed HeapFree to HeapFeeMem to keep symmetry).

Original issue reported on code.google.com by [email protected] on 2 Jun 2009 at 12:51

Structure padding is not taken care.

What steps will reproduce the problem?
1. Parsing structure of this kind,
2. struct str
{
    int a;
    char b;
    long c;
    char d;
} STRUCT_VAL;
 is creating problem. 
3. Structure padding is not taken care

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 8 Jul 2009 at 10:08

Doesn't compile under VC.net

All right, I got the code from the CVS repository (as of today, around 9h00
local Montreal time).

I rebuilt the Win32 projects using your code and I mostly discarded mine --
the only think I kept for now is the api.c file which exposes the API
through the PicoC DLL.

I had to make a few changes to make things compile on .NET 2008, and I also
have a couple of observations:
clibrarry.c:
    - LibraryInit: I don't know why you don't simply use a struct
LibraryFunction pointer instead of the convoluted array declaration. It
makes it impossible to compile a call to
      LibraryInit unless the full definition of the array is known,
something which won't happen through an API. Making it a pointer removes
nothing and even makes the code clearer.
    - LibraryInit: you hard-code the library name to "c library" instead of
using the name provided on input.
    - CLibraryInit(): this is where the call to LibraryInit() should be
made for the CLibrary. It makes more sense than asking the global
initialization code to perform both CLibraryInit() and LibraryInit() for
the C library.
    - PrintFP(): 
        - some casts are required: when assigning a value to Exponent
        - you should call math_fabs() instead of abs() to work with Num --
the function is there and is platform-ized
    - LibSPrintf(): I get an uninitialized variable warning on
StrStream.i.Str.Parser. I initialized it with the struct Parser pointer on
input, but I don't know if that's the right thing to do.
    - LibAsynh, LibAcosh, LibAtanh: the functions are not defined on
Windows -- I had to #ifdef them out. For me that's not a big deal.
- expression.c:
    - Some casts are required. .NET is pricky about comparisons between
ints and non-ints. I converted to unsigned int when the code is dealing
with parser offsets, and to ints where it's not so clear.
    - ExpressionParse(): I have to add an explicit cast to assign TypeVoid
to VariableValue->Typ: (struct ValueType*)TypeVoid. It works.
- heap.c:
    - two casts to solve warnings for comparisons between ints and unsigned
ints. Thanks for HeapAllocMem!
- lex.c:
    - LexValue is not initialized with sufficient parameters: you are
missing at least two.
    - I had to cast TypeVoid as above
    - LexGetNumber(): I don't know why you cast Base to double in the loop
that picks up the exponent value -- it's unnecessary (and causes a warning!)
- picoc.h:
    - My compiler does not accept the PlatformVPrintf declaration: I
substituted "..." for "va_list Args". I haven't tested anything (yet), but
it compiles.
- platform.c:
    - int -> unsigned int comparison in PrintSourceTextErrorLine (the last
for()).
- variable.c:
    - int -> unsigned int comparison in VariableDereferencePointer() -- the
third "if".

So, lots of details, but mostly very small things.

- - -

I next tried using the interpreter. I am using it mostly in interactive
mode, where my main program opens a pipe to the interpreter and sends it
commands to execute -- the interpreter runs in a separate thread. For now,
I am only testing PicoC using the command line mode as I can't integrate
the new version in my stuff yet -- it's not ready.

I didn't keep a list of bugs I found -- I just fixed them as I went. I
guess it would have been useful to keep an "acid test" file... However, if
I try this:...

line1:    int fn( int a )
line2:    {
line3:    int b;
line4:    b=2;
line5:    return a+b;
line6:    }
line7:    printf( "%d\n", 1+fn(2) );

...it crashes in LexGetToken at line 613 because InteractiveCurrentLine is
NULL. I tried just invoking fn() and it crashes at the same place. I wonder
if you have the same problem, of if it's caused by something I changed?

However, if I squeeze the whole function declaration onto a single line,
there are no problems.

Original issue reported on code.google.com by [email protected] on 5 Jun 2009 at 11:05

Fix array assignment

Example program:

int a[4];

a[0] = 12;
a[1] = 23;
a[2] = 34;
a[3] = 45;

printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);

int b[4];

b = a;

printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]);


zik@initech:~/work/picoc$ ./picoc tester.c
12 23 34 45
12 0 0 0

Original issue reported on code.google.com by [email protected] on 4 Oct 2009 at 4:40

Problem with HEX literals

What steps will reproduce the problem?
1. see additional info: C Source and Execution Results
2.
3.

What is the expected output? What do you see instead?
incorrect conversion of HEX literals

What version of the product are you using? On what operating system?


Please provide any additional information below.

C Source:

void PDQ(int d, int h)
{
    printf("%d, %d\r\n", d, h);
}

printf("\r");

int p;
int m;

p=0x7FFFFFFF;
m=p+1;
printf("%d, %d\r\n", p, m);

p=1;
for (m=1; m<=32; m++)
{
  printf("%d, %d, %d\r\n", m, p, p-1);
  p=p*2;
}

printf("%d, %d\r\n",    0,    0x00);
printf("%d, %d\r\n",    1,    0x01);
printf("%d, %d\r\n",    9,    0x09);
printf("%d, %d\r\n",   10,    0x0A);
printf("%d, %d\r\n",   15,    0x0F);
printf("%d, %d\r\n",   16,    0x10);
printf("%d, %d\r\n",   17,    0x11);
printf("%d, %d\r\n",  255,    0xFF);
printf("%d, %d\r\n",32767,  0x7FFF);
printf("%d, %d\r\n",32768,  0x8000);
printf("%d, %d\r\n",65535,  0xFFFF);
printf("%d, %d\r\n",65536, 0x10000);

PDQ(    0,    0x00);
PDQ(    1,    0x01);
PDQ(    9,    0x09);
PDQ(   10,    0x0A);
PDQ(   15,    0x0F);
PDQ(   16,    0x10);
PDQ(   17,    0x11);
PDQ(  255,    0xFF);
PDQ(32767,  0x7FFF);
PDQ(32768,  0x8000);
PDQ(65535,  0xFFFF);
PDQ(65536, 0x10000);

exit();


Execution Results:
##Version - SRV-1 Blackfin w/picoC 0.92 07:57:59 - Aug  2 2009

2621439, 2621440  *** ERROR
1, 1, 0
2, 2, 1
3, 4, 3
4, 8, 7
5, 16, 15
6, 32, 31
7, 64, 63
8, 128, 127
9, 256, 255
10, 512, 511
11, 1024, 1023
12, 2048, 2047
13, 4096, 4095
14, 8192, 8191
15, 16384, 16383
16, 32768, 32767
17, 65536, 65535
18, 131072, 131071
19, 262144, 262143
20, 524288, 524287
21, 1048576, 1048575
22, 2097152, 2097151
23, 4194304, 4194303
24, 8388608, 8388607
25, 16777216, 16777215
26, 33554432, 33554431
27, 67108864, 67108863
28, 134217728, 134217727
29, 268435456, 268435455
30, 536870912, 536870911
31, 1073741824, 1073741823
32, -2147483648, 2147483647
0, 0
1, 1
9, 9
10, 10
15, 15
16, 16
17, 17
255, 255
2588671, 2588671  *** ERROR
2588672, 2588672  *** ERROR
2621439, 2621439  *** ERROR
2555904, 2555904  *** ERROR
0, 0
1, 1
9, 9
10, 10
15, 15
16, 16
17, 17
255, 255
2588671, 2588671  *** ERROR
2588672, 2588672  *** ERROR
2621439, 2621439  *** ERROR
2555904, 2555904  *** ERROR
leaving picoC

Original issue reported on code.google.com by [email protected] on 4 Oct 2009 at 9:05

Returning from a void function doesn't work

zik@initech:~/work/picoc$ ./picoc -i
starting picoc
picoc> void joe()
     > {
     > return;
     > }
picoc> joe();
picoc: heap.c:89: HeapPopStack: Assertion `HeapStackTop == Addr' failed.
Aborted

Original issue reported on code.google.com by [email protected] on 3 Jun 2009 at 12:24

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.