C.impl is a small portable C interpreter integrated with a line text editor

Related tags

Miscellaneous C.impl
Overview

C.impl

C.impl is a small portable C interpreter integrated with a line text editor, originally developed for the ELLO 1A computer: http://ello.cc

The aim of this code is to achieve a close C90 specification functional implementation
of an interpreter for the C language with minimum required system resources and without
references to specific external layers such as OS.

Data types:

'bool' - defined as 1-bit integer
'char' - defined as 8-bit integer
'short' or 'short int' - defined as 16-bit integer
'int' - defined as per the 'typedef int_t' statement
'long' or 'long int' - defined as 32-bit integer
'long long' or 'long long int' - defined as 64-bit integer
'float' - single precision floating point number (32-bit)
'double' - double precision floating point number (64-bit)
'long double' - quadruple precision floating point number (80-bit or more)

In addition to the basic types above, several other data types are also supported:

'size_t' - natively represented as 'unsigned int'
'enum' - standard C-type enum list
'struct' - standard C-type data structure
'union' - standard C-type data union
'va_list' - used in conjunction with the library for variable argument lists
'FILE' - used with file functions in the library

'signed' or 'unsigned' optionally preceding the integer types, except 'bool'
All integer types are signed by default (i.e. as if preceded by a 'signed' declaration)

Constant data types:

'char' - single 8-bit character
"string" - string of zero-terminated 8-bit characters
up to 64-bit decimal integer numbers (optionally preceded by '0d' or '0D')
up to 64-bit hexadecimal unsigned numbers; preceded by '0x' or '0X'
up to 64-bit binary unsigned numbers; preceded by '0b' or '0B'
up to 64-bit octal unsigned numbers; preceded by '0'
floating point numbers (always decimal) in format:
[sign] [ iii [ .fff ['E/e' [sign] [ eee [ .xxx ] ] ] ] ]

Decimal numbers optionally support suffix specifiers for sign and/or size:
'u' or 'U' for unsigned
'l' or 'L' for long integer or long double
'll' or 'LL' for long long integer
'f' or 'F' for float
'd' or 'D' for double

The default type of all integer constants, unless explicitly specified, is 'signed int'
The default type of floating point number constants, unless explicitly specified, is 'float'

Pre-defined character literals:

'\0' - ASCII code 0 (character NUL)
'\a' - ASCII code 7 (alarm)
'\b' - ASCII code 8 (backspace)
'\e' - ASCII code 27 (escape)
'\f' - ASCII code 12 (form feed)
'\n' - ASCII code 10 (new line)
'\r' - ASCII code 13 (carriage return)
'\t' - ASCII code 9 (horizontal tabulation)
'\' - the character 'backslash'
''' - the character 'single quote'
'"' - the character 'double quote'
'?' - the character 'question mark'

Other notes and features:

  1. True execution in place. The source code is not compiled or modified and can run directly from ROM
  2. Fully dynamic memory model with no limitation on the number of functions or variables, or their size
  3. Arrays and pointers are fully supported
  4. Inline local variable definitions are allowed, eg. for(int t=0; .....
  5. String literals can be split on to multiple lines
  6. Pointer to constant (eg. const char *) and constant pointer (eg. char const *), are both supported
  7. Standard C and C++ style commentaries are both supported

Built-in libraries:

< stdlib.h > // extra: unsigned long BIT(unsigned char n)
< stdio.h > // extra: void run(const char *filename)
< stdint.h >
< stdbool.h >
< stdarg.h >
< string.h >
< math.h >
< limits.h >
< ctype.h >
< time.h >
< assert.h > // can be used also to assert the existence of library functions, eg. assert(printf())
< conio.h > // console functions
< fatfs.h > // wrapper functions for most of the FatFs library
< graphics.h > // hardware-independent higher-level graphical primitives
< platform.h > // support library for specific hardware platform implementations

Known issues and limitations:

1. Function pointers and function address dereferencing are not supported (no feasible way in an interpreter!)
2. Support for preprocessor directives is reduced only to #include
3. In for(), while(), and do...while() loops, 'break' and 'continue' can only work from within a {} block
4. The 'goto' instruction only allows jumping to a location at the same or upper {} depth level
5. A goto label must have unique name among all labels globally.
6. The 'extern' keyword is not supported since the source can be only a single file
7. In the ternary operator ?: there must be a space before the colon ':' so it is not mistaken for a label
8. The main() function must not have parameters or a return value
9. In composite data types (enum, struct, union), the name of the type must be before the {} block, but can't be after
10. Structures, unions, and enums are all supported but have high runtime memory cost and should be used with care
11. Keywords 'struct', 'union', and 'enum' must be used only for the initial type declaration, but not for instances
12. Casting to structure or union pointer will not work. The cost of its implementation in an interpreter
is massive in terms of both runtime memory and execution speed
13. Indexing by pointers (eg. int a[10]; int b = *(a+1); ) will not work. Indexing needs to be done in the brackets way

Other notes:

The entire code is deeply recursive so it requires sufficient stack for its operation. With the
default settings, at least 4kB stack size is recommended.

Issues
  • Error compiling

    Error compiling

    Windows 10, Dev C++ v6.3:

    Tried with the new files (thanks for the quick response!), and now I get:

    In file included from ../../../ride/ride.h:35, from ../../../ride/fos.h:8, from ../diskio.c:15: ../../../ride/graphics.h:37:1: error: C++ style comments are not allowed in ISO C90 37 | // font definition header | ^ compilation terminated due to -Wfatal-errors.

    I changed the compiler option to use ISO C99 instead, and now I get:

    ../diskio.c: In function 'disk_initialize': ../diskio.c:109:37: error: macro "x_malloc" passed 2 arguments, but takes just 1 109 | x_malloc((byte **) &buff, 1024); | ^ compilation terminated due to -Wfatal-errors.

    opened by eddavis2 3
  • Error compiling C.impl

    Error compiling C.impl

    Windows 10:

    I tried to compile this, but I get:

    cimpl.c:5:10: fatal error: ../xmem.h: No such file or directory 5 | #include "../xmem.h" | ^~~~~~~~~~~ compilation terminated. opr.c:9:10: fatal error: ../xmem.h: No such file or directory 9 | #include "../xmem.h" | ^~~~~~~~~~~ compilation terminated.

    And when I look, indeed, the file xmem.h does not exist.

    I tried this from the command line, and also from the DevC++ environment.

    opened by eddavis2 1
Owner
KnivD
KnivD
OpenVi is an enhanced and portable implementation of the Berkeley vi / ex text editor, originally developed by Bill Joy.

OpenVi is an enhanced and portable implementation of the Berkeley vi / ex text editor, originally developed by Bill Joy.

Jeffrey H. Johnson 91 Aug 9, 2022
Freeze OS is a cross-platform operating system emulator that runs on top of an interpreter called the Freeze interpreter.

Freeze OS is a cross-platform operating system emulator that runs on top of an interpreter called the Freeze interpreter. The operating system code is basically written in the Freeze programming language that is passed to the Freeze interpreter. The idea is to skip instances where the operating system needs to handle low level operators and focus on higher level stuff, like malware analysis, AI, and others.

null 24 May 2, 2022
te is a small text editor with emacs keybindings.

te - a tiny emacs te is a small text editor with emacs keybindings. Here are söme Ümlautß! Oh no. Come, you spirits That tend on mortal thoughts, unse

Leah Neukirchen 21 Jun 8, 2022
Typewriter Effect with Rich Text + *Correct* Text Wrapping

Typewriter Effect with Rich Text + Correct Text Wrapping I've spent way too long getting this right. This is meant as a base class for a UMG dialogue

Sam Bloomberg 26 Jul 17, 2022
Text - A spicy text library for C++ that has the explicit goal of enabling the entire ecosystem to share in proper forward progress towards a bright Unicode future.

ztd.text Because if text works well in two of the most popular systems programming languages, the entire world over can start to benefit properly. Thi

Shepherd's Oasis 204 Jul 25, 2022
Jittey - A public domain text editor written in C and Win32

Jittey (Jacob's Terrific Text Editor) is a single-file basic text editor written in pure C and Win32, there is no real reason to use it, but it

Jakub Šebek 24 Aug 7, 2022
A very minimal & simple text editor written in C with only Standard C Library.

Texterm Text Editor A very minimal & simple text editor written in C with only Standard Library. Syntax highlighting supported for C JavaScript Python

Biraj 38 Jul 13, 2022
MINCE is an Emacs-like text editor from Mark of the Unicorn, Inc.

MINCE Is Not Complete[ly] EMACS Overview MINCE is an Emacs-like text editor from Mark of the Unicorn, Inc. Versions were available for many oper

Jeffrey H. Johnson 20 Jul 18, 2022
Let's make a text editor like in the 70's

baracle Let's make a text editor like in the 70's Installation Arch Linux and derivatives (AUR) Stable package: baracle Use an AUR helper or git clone

Mirko Rovere 3 Feb 27, 2022
This repository is for my coding practice, making a text editor from scratch in C.

text-editor-practice This repository will contain my coding practice, making a text editor from scratch. I based this practice from this wonderful res

null 2 Dec 13, 2021
yedit - A text editor made with ncurses and C++

yedit A text editor made with ncurses and C++ dependencies ∙ ncurses in Debian you can install dependencies with this command: # apt install libncurse

MESYETI 15 Jun 8, 2022
Programmer's text editor

README file for JED. For installation instructions on Unix: read INSTALL.unx VMS: read INSTALL.vms Windows:

John E. Davis 8 May 2, 2022
QsciScintilla based text editor

Sqriptor QScintilla based text editor "Every man should plant a tree, have a son and write a TextEditor"                          --- Proverb "The bes

null 10 Apr 27, 2022
Second project for 42 : Reading text available on the file descriptor one line at a time.

get_next_line Initial commit This project will not only allow you to add a very convenient function to your collection, but it will also allow you to

Dieau 1 Mar 28, 2022
A laser cut Dreamcast Pop'n Music controller and integrated memory card using the Raspberry Pi Pico's Programmable IO

Dreamcast Pop'n Music Controller Using Raspbery Pi Pico (RP2040) Intro This is a homebrew controller for playing the Pop'n Music games on the Sega Dre

null 36 Aug 3, 2022
C library designed for the TI MSP432P401R microprocessor and the TI Educational Booster Pack, to easily play and control songs with the integrated Piezo Buzzer.

MusicLib C library designed for the TI MSP432P401R microprocessor and the TI Educational Booster Pack, to easily play and control songs with the integ

Matteo Merler 1 Nov 24, 2021
Lee Thomason 293 Aug 8, 2022
Optimization-Based GNSS/INS Integrated Navigation System

OB_GINS Optimization-Based GNSS/INS Integrated Navigation System We open-source OB_GINS, an optimization-based GNSS/INS integrated navigation system.

i2Nav-WHU 211 Aug 8, 2022
The Gecko SDK (GSDK) combines all Silicon Labs 32-bit IoT product software development kits (SDKs) based on Gecko Platform into a single, integrated SDK.

Silicon Labs Gecko SDK (GSDK) The Gecko SDK (GSDK) combines Silicon Labs wireless software development kits (SDKs) and Gecko Platform into a single, i

Silicon Labs 108 Aug 13, 2022