enables writing program semantics (lifting) in Primus Lisp #1277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
It is now possible to specify program semantics, including
semantics of instructions (aka lifters) and even semantics of the
whole programs in Primus Lisp.
Essentially Primus Lisp programs could be compiled into program
values, i.e., core theory terms. The main motivation for this work was
writing lifters and stubs in Primus Lisp, which significantly reduces
the effort wrt writing a lifter directly in OCaml. For example, it
took me less than a day to write a RISCV lifter in Primus Lisp (the PR
is upcoming).
The feature is seamlessly integrated with the knowledge base that
makes it available not only for the new architectures but for
extending the lifters for existing architectures. Whenever a semantics
of a basic instruction is requested, a corresponding Lisp definition
(which has name that matches the opcode name prefixed with the opcode
encoding and the corresponding number of arguments) is sought and if
found its is reified into a Core Theory term.
The Primus Lisp language itself underwent a few deep changes and is now a
meta language for writing programs that write programs. Its Lisp
nature makes it an ideal choice for writing lifters thanks to
mono-iconic representation of the host and target languages. The
Primus Lisp meta compiler is an interpreter that partially evaluates
Primus Lisp programs until no further refinements are possible. This
results in a very-specialized minimal code. To illustrate this, let's
consider the following example (assuming that it is stored in the
demo.lisp
file that is located in the current folder),Since the value of
(/= 1 2 3)
is statically known we reify it intoan efficient representation,
We still produce an assignment because the target is
armv5+le
, whichtells us that
R0
is a register. Let's consider an example where wecan't compute the input statically,
which is refied into,
The meta-compiler supports partial computations for all forms, so it
is possible to use
let
forms (with lexical and dynamic scoping) anddefine helper functions and macros, e.g.,
will be reified to
Such mono-iconic representation is possible because the value of a
Primus Lisp expression is no longer a word, but a program term, which
is represented as the knowledge base value of class
Theory.Effect.cls
. This value is also known inBap.Std
asInsn.t
, coincidentally the type of a value that is expected to beprovided by lifters.