toctave

t(iny)octave
git clone https://0xff.ir/g/toctave.git
Log | Files | Refs | README

README.md (2574B)


      1 
      2 # `t(iny)octave`
      3 
      4 This is a very simple demo octave-like calculator which uses a Jittery virtual
      5 machine (VM). 
      6 
      7 For simplicity, there's no matrix!
      8 
      9 Operators: `^`, `*`, `/`, `+`, `-`.
     10 You can assign variables: `x = 2^3`.
     11 Everything is a double number (there's string literals which are only used for
     12 `eval`).
     13 
     14 **NOTE** For simplicity, this implementation assumes the code is running on
     15 a x86_64 platform (actually platforms with the following properties:
     16 `sizeof(double) == sizeof(void*)` and pointers not wider than 54 bits (because
     17 of nan-boxing)).
     18 
     19 ## `GNU Jitter`
     20 
     21 This is a demonstration of using `GNU Jitter` to generate a VM (Virtual
     22 Machine).
     23 
     24 The `Makefile` assumes Jitter is installed on `$HOME/usr`. By assigning
     25 `JITTER_PRFIX` environment variable, you can change the path to
     26 `$JITTER_PREFIX/usr`.
     27 
     28 Jitter can support different dispatches (VM implementation strategies),
     29 by default it uses `switch` dispatch (which generates a `switch` statement).
     30 You can change the dispatch by assigning a value to `JITTER_DISPATCH`
     31 environment variable. To see a valid list of dispatches on your platform
     32 you can invoke `$JITTER_PREFIX/jitter-config --dispatches` command.
     33 
     34 **NOTE** You need to apply `jitter.path` in master branch of `Jitter`
     35 (as of `v0.9.286`). The reason is `Jitter` generates C code and the C compiler
     36 is not as strict as C++ compiler.
     37 
     38 **Recommendation** Use `gcc` and `g++`.
     39 
     40 ## Unfinished items
     41 
     42 - Function call
     43 - `eval`
     44 
     45 ## Structure of the code
     46 
     47 - `ast.hpp`, `ast.cpp`: Types and functions related to creating AST (Abstract
     48   Syntax Tree).  This implementation uses
     49   [`stlab::forest`](https://stlab.cc/libraries/forest.hpp/) to encode the AST.
     50   For an introduction to them,
     51   [read this](https://stlab.cc/2020/12/01/forest-introduction.html).
     52   And also, [this](https://stlab.cc/forest/2016/05/28/forest.html)
     53 - `ast.test.cpp`: Test cases for AST manipulation.
     54 - `cgen.hpp`, `cgen.cpp`: Types and functions related to code generation.
     55   `cgen::sexpr` function generates S-expressions. `cgen::jitter` generates
     56   code for the VM generated by Jitter (specified by `toctave.jitter` file).
     57 - `cgen.test.cpp`: Test cases for code generation verification.
     58 - `env.hpp`, `env.cpp`: Run-time environment.
     59 - `toctave.jitter`: Specification of Jittery VM.
     60 - `stlab/`: [stlab libraries](librar://stlab.cc/).
     61 
     62 I'd recommend to start from `ast.test.cpp` and `cgen.test.cpp`.
     63 
     64 **NOTE** Don't compile these files with `-DNDEBUG`, becase of `assert`.
     65 
     66 ## Copyright
     67 
     68 ```text
     69 Copyright (C) 2022, Mohammad-Reza Nabipoor
     70 SPDX-License-Identifier: GPL-3.0-or-later
     71 ```