another example plus memory work
This commit is contained in:
parent
907fe17b43
commit
74b06d60c5
106
Cargo.lock
generated
106
Cargo.lock
generated
|
@ -2,18 +2,68 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||
|
||||
[[package]]
|
||||
name = "beef"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"allocator-api2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "logos"
|
||||
version = "0.13.0"
|
||||
|
@ -46,6 +96,18 @@ dependencies = [
|
|||
"logos-codegen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
|
@ -64,6 +126,36 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
|
@ -74,7 +166,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
|||
name = "rhea"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"logos",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -93,3 +187,15 @@ name = "unicode-ident"
|
|||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
|
|
@ -7,3 +7,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
logos = "*"
|
||||
hashbrown = "*"
|
||||
rand = "*"
|
||||
|
|
10
assets/examples/inline.rhea
Normal file
10
assets/examples/inline.rhea
Normal file
|
@ -0,0 +1,10 @@
|
|||
func main() {
|
||||
asm {
|
||||
jmp r0, start
|
||||
start:
|
||||
jmp r0, start
|
||||
}
|
||||
opcode {
|
||||
01
|
||||
}
|
||||
}
|
16
src/main.rs
16
src/main.rs
|
@ -1,6 +1,9 @@
|
|||
// Rhea
|
||||
|
||||
use logos::Logos;
|
||||
use memory::{Variable, VariableHashmap, VariableType};
|
||||
|
||||
mod memory;
|
||||
|
||||
#[derive(Logos, Debug, PartialEq)]
|
||||
#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens
|
||||
|
@ -38,8 +41,21 @@ enum Token {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let mut memmap = Vec::new();
|
||||
let mut varmap: VariableHashmap = hashbrown::HashMap::new();
|
||||
|
||||
let variable_name = "abcd".to_string();
|
||||
let variable_type = Some(memory::VariableType::Signed);
|
||||
let constant = false;
|
||||
let length = 8;
|
||||
let abc = Variable::new(&mut memmap, variable_type, constant, length);
|
||||
|
||||
varmap.insert(variable_name, abc);
|
||||
|
||||
let mut lex = Token::lexer(include_str!("../assets/examples/library.rhea"));
|
||||
for x in lex {
|
||||
println!("{:?}", x);
|
||||
}
|
||||
|
||||
//todo compile to hb
|
||||
}
|
||||
|
|
53
src/memory.rs
Normal file
53
src/memory.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use std::ops::Range;
|
||||
|
||||
// I do not like std
|
||||
use hashbrown::HashMap;
|
||||
|
||||
pub type MemoryMap = Vec<(u64, u64)>;
|
||||
|
||||
pub type VariableHashmap = HashMap<String, Variable>;
|
||||
|
||||
pub enum VariableType {
|
||||
Unsigned,
|
||||
Signed,
|
||||
String,
|
||||
}
|
||||
|
||||
pub struct Variable {
|
||||
vtype: VariableType,
|
||||
constant: bool,
|
||||
memory_addr: u64,
|
||||
length: u64,
|
||||
}
|
||||
impl Variable {
|
||||
pub fn new(
|
||||
memmap: &mut MemoryMap,
|
||||
variable_type: Option<VariableType>,
|
||||
constant: bool,
|
||||
length: u64,
|
||||
) -> Self {
|
||||
let addr = get_random_addr_and_validate(memmap, length);
|
||||
//todo type guessing
|
||||
let vtype = VariableType::String;
|
||||
Self {
|
||||
vtype,
|
||||
constant,
|
||||
memory_addr: addr,
|
||||
length,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use rand::prelude::*;
|
||||
|
||||
pub fn get_random_addr_and_validate(memmap: &mut MemoryMap, length: u64) -> u64 {
|
||||
let raddr: u64 = rand::random();
|
||||
// TODO: validate fr later
|
||||
// for (x, _) in memmap.iter() {
|
||||
// if *x == raddr {
|
||||
// }
|
||||
// }
|
||||
|
||||
memmap.push((raddr, raddr + length));
|
||||
raddr
|
||||
}
|
Loading…
Reference in a new issue