HOME

TheInfoList



OR:

Charm is a computer
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming l ...
devised in the early 1990s with similarities to the
RTL/2 RTL/2 (Real-Time Language) is a discontinued high-level programming language for use in real-time computing, developed at Imperial Chemical Industries, Ltd. (ICI), by J.G.P. Barnes. It was originally used internally in ICI but was distribute ...
,
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Frenc ...
and C languages in addition to containing some unique features of its own. The Charm language is defined by a
context-free grammar In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form :A\ \to\ \alpha with A a ''single'' nonterminal symbol, and \alpha a string of terminals and/or nonterminals (\alpha can be ...
amenable to being processed by
recursive descent parser In computer science, a recursive descent parser is a kind of top-down parser built from a set of mutually recursive procedures (or a non-recursive equivalent) where each such procedure implements one of the nonterminals of the grammar. Thus the ...
as described in seminal books on
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
design. A set of Charm tools including a compiler, assembler and linker was made available for Acorn's
RISC OS RISC OS is a computer operating system originally designed by Acorn Computers Ltd in Cambridge, England. First released in 1987, it was designed to run on the ARM chipset, which Acorn had designed concurrently for use in its new line of Archi ...
platform. Charm reworked for
RISC OS RISC OS is a computer operating system originally designed by Acorn Computers Ltd in Cambridge, England. First released in 1987, it was designed to run on the ARM chipset, which Acorn had designed concurrently for use in its new line of Archi ...
platforms has subsequently been reviewed in Archive magazine. Charm is further described in the e-book ''Programming in Charm on the Raspberry Pi''.


Grammar

The definition of the Charm grammar in
Backus–Naur form In computer science, Backus–Naur form () or Backus normal form (BNF) is a metasyntax notation for context-free grammars, often used to describe the syntax of languages used in computing, such as computer programming languages, document format ...
along with descriptive examples of Charm constructs is defined on the Char
language page
The language is block structured, with each block being introduced by a language keyword that is descriptive of the operation being performed in the block e.g. , , (''iteration''), , (''selection''). Each block is enclosed by delimiters. Additionally language lines within a block are normally indented for clarity, though this not required as white space is ignored. Each grammatically conforming text represents a collection of executable code and associated data which can be used by a Charm tool set as a component when assembling a program that can be run under an operating system utilising the services it provides to do useful work such as data processing or interacting with users through a
graphical user interface The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows User (computing), users to Human–computer interaction, interact with electronic devices through graphical icon (comp ...
(GUI).


Data types

Charm is a strongly typed language, but does allow some implicit conversions between numeric and floating point types. The following basic variable types are supported: :* – integers :* – characters :* – boolean values ( or ) :* – floating point numbers Data aggregates of the same type may be declared and statically initialised using the keyword, and these may be multidimensional. Aggregates of different types may be declared using the keyword, and it is allowable for such a declaration to define a of record fields that overlay each other in terms of storage allocation. Modules may also aggregate a mixture of static and dynamic data members. Instances of both records and modules (dynamic content only) can be instantiated on the stack, or on the heap via the operator. Modules may also define a constructor procedure to initialise dynamic data and corresponding deconstructor procedure to release resources in a similar manner to the C++ language.


Referencing

Data or procedures within the scope of a module may be made global to the final application by using the keyword. If a module wishes to reference a procedure or data from another Charm module, it does so using the keyword. Modules may contain instance based member variables which are accessible through procedures declared with the keyword through the implicit first parameter pointer. References to data constructs and procedures may be made using the keyword. These can be dereferenced using the keyword. When using reference variables, comparison operators are available to check whether two reference variables refer to the same item of data ( :=: ) or whether the data they point to is the same ( = ).


Example

The original classic
Hello world program ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
written in Charm is: ext proc write_string (ref array char); module hello; ent proc start (); write_string ("Hello world"); end_proc; end_module; and the equivalent latest version following evolutionary syntactic language changes is: import lib.Out; module Hello


Tool set

Tool set implementations are expected to provide a compiler and an assembler to generate object files from Charm source code and assembler source code, which can then be linked together along with library and run time support files to generate an executable program. At the time of writing only one Charm tool set installation is available (free of charge) for download. The tools are themselves written in the Charm language, and the source code is available under the terms of the
GNU General Public License The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end user In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ulti ...
. They run on
RISC OS RISC OS is a computer operating system originally designed by Acorn Computers Ltd in Cambridge, England. First released in 1987, it was designed to run on the ARM chipset, which Acorn had designed concurrently for use in its new line of Archi ...
PCs and platforms with ARM CPUs (such as the
Raspberry Pi Raspberry Pi () is a series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in association with Broadcom. The Raspberry Pi project originally leaned towards the promotion of teaching basic ...
) and on emulators for RISC OS which are hosted on Windows or Linux platforms (such as RPCEmu). Code generation for hardware assisted double precision floating point operations is supported for platforms based on ARM chips that support the VFP version 2 coprocessor architecture.


Compiler

The Charm compiler is a recursive descent single pass compiler which parses Charm source code to generate quadruples of the form ''result := lhs op rhs'' in an intermediate language that supports arithmetic, logical and flow of control operations. Data is stored in temporaries which are assigned to registers and memory locations in the back end of the compiler. Two back ends are currently in existence, one generating
Motorola 68000 The Motorola 68000 (sometimes shortened to Motorola 68k or m68k and usually pronounced "sixty-eight-thousand") is a 16/32-bit complex instruction set computer (CISC) microprocessor, introduced in 1979 by Motorola Semiconductor Products Sect ...
assembly language, and the other generating
ARM architecture ARM (stylised in lowercase as arm, formerly an acronym for Advanced RISC Machines and originally Acorn RISC Machine) is a family of reduced instruction set computer (RISC) instruction set architectures for computer processors, configure ...
. The quadruple output from the hello world example is: param l1$ call write_string roc (ref array char) void and the assembler output is: string "hello" xdef _start align _start xref _write_string stmfd sp!, adr r0,_l1$ bl _write_string ldmfd sp!, address align _l1$ string "Hello world" direct end In more recent releases of Charm, the I/O procedures have been split into their own modules In and Out. Other standard library procedures are organised into a set of records with procedure references as fields. As part of this reorganisation, the write_string method is now invoked through the run time library module Out via static member reference .vdu as procedure str i.e. in the hello world example above write_string ("Hello world") becomes Out.vdu.str ("Hello world").


Assembler

The assembler accepts instruction mnemonics, data declarations and directives and constructs an object file containing information readily understandable by the CPU of the target processor, in particular code instructions coded in binary.


Linker

One and only one of the Charm modules linked to form an executable program must contain a procedure matching one of the signatures: export proc ~start () export proc ~start (int argc, ref array ref array char argv) This is analogous to the main function in the C and
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
languages. Here argc contains the number of parameters passed on the command line and argv contains a reference to an array of argc + 1 strings (one string per positional parameter in order and a terminating nil). In addition, modules may optional contain static startup and shutdown procedures invoked during program startup and shutdown that match the signatures: export proc ~startup () export proc ~shutdown () The linker adds any necessary header information required by the operating system in order to execute the program, and ensures the run time library assembler support code is run which sets up the run time environment (data and stack pointers) and passes control to the start procedure of the application. A map file showing the names of all modules linked to form the program along with global data and code references is optionally produced which can be used by debuggers and profilers.


References

{{Reflist, refs= June 2013 Kindle e-book ''Charm Programming on the Raspberry Pi''
/ref> ISBN D-201-10073-8 Aho, Ullman ''Principles of Compiler Design'' ISBN D-201-10194-7 Aho, Sethi, Ullman ''Compilers Principles, Techniques and Tools'' {{ISBN, 0-9512579-0-0 Peter Cockerell ''ARM Assembly Language Programming''


External links


Charm for RISC OS

Risc PC Emulator

ARM Information Center
Programming languages RISC OS programming tools Articles with example code