mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
No commits in common. "1a517da5a11729a795b32ff9447dc4776b63c34a" and "47fbb70b8da4a724aded3d72b75cbd0fa88608a4" have entirely different histories.
1a517da5a1
...
47fbb70b8d
|
@ -73,11 +73,9 @@ impl Codegen {
|
||||||
|
|
||||||
"get" => { format!("{}[{}]", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) },
|
"get" => { format!("{}[{}]", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) },
|
||||||
"len" => { format!("{}.length", self.gen_ir(&args[0], false)) },
|
"len" => { format!("{}.length", self.gen_ir(&args[0], false)) },
|
||||||
"insert" => { format!("{}.push({})", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) },
|
|
||||||
"concat" => { format!("{}.concat({})", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) },
|
|
||||||
|
|
||||||
"throw" => { format!("throw new Error({}){}", self.gen_ir(&args[0], false), semicolon!()) },
|
"throw" => { format!("throw new Error({}){}", self.gen_ir(&args[0], false), semicolon!()) },
|
||||||
_ => unreachable!("{}", format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
|
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -88,7 +86,7 @@ impl Codegen {
|
||||||
.collect::<Vec<_>>().
|
.collect::<Vec<_>>().
|
||||||
join(", ");
|
join(", ");
|
||||||
format!(
|
format!(
|
||||||
"{} const _{} = ({}): {} => {{{}}};\n",
|
"{} const _{} = ({}): {} => {};\n",
|
||||||
if *public { "export" } else { "" },
|
if *public { "export" } else { "" },
|
||||||
name,
|
name,
|
||||||
args,
|
args,
|
||||||
|
@ -158,16 +156,6 @@ impl Codegen {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
IRKind::Tuple { values } => {
|
|
||||||
format!(
|
|
||||||
"[{}]",
|
|
||||||
values
|
|
||||||
.iter()
|
|
||||||
.map(|value| self.gen_ir(value, false))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
},
|
|
||||||
IRKind::Vector { values } => {
|
IRKind::Vector { values } => {
|
||||||
format!(
|
format!(
|
||||||
"[{}]",
|
"[{}]",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use parser::types::{Expr, Typehint};
|
use parser::types::{Expr, Typehint};
|
||||||
|
|
||||||
const INTRINSICS: [&str; 10] = [
|
const INTRINSICS: [&str; 8] = [
|
||||||
"write",
|
"write",
|
||||||
"read",
|
"read",
|
||||||
"write_file",
|
"write_file",
|
||||||
|
@ -9,8 +9,6 @@ const INTRINSICS: [&str; 10] = [
|
||||||
"emit",
|
"emit",
|
||||||
"get",
|
"get",
|
||||||
"len",
|
"len",
|
||||||
"insert",
|
|
||||||
"concat",
|
|
||||||
"throw",
|
"throw",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -452,7 +450,6 @@ pub fn expr_to_ir(expr: &Expr) -> (Option<IRKind>, Option<LoweringError>) {
|
||||||
fn gen_type_hint(type_hint: &Typehint) -> String {
|
fn gen_type_hint(type_hint: &Typehint) -> String {
|
||||||
match type_hint {
|
match type_hint {
|
||||||
Typehint::Single(t) => match t.as_str() {
|
Typehint::Single(t) => match t.as_str() {
|
||||||
"any" => "any".to_string(),
|
|
||||||
"int" => "number".to_string(),
|
"int" => "number".to_string(),
|
||||||
"bool" => "boolean".to_string(),
|
"bool" => "boolean".to_string(),
|
||||||
_ => t.to_string()
|
_ => t.to_string()
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
fun map_ (vec: [int]) (fn: |int| -> int) (current: int): [int] = do
|
fun map_ (vec: [int]) (fn: |int| -> int) (current: int): void = do
|
||||||
if current == @len(vec) then
|
if current == @len(vec) then
|
||||||
return []
|
do end
|
||||||
else
|
else
|
||||||
do
|
do
|
||||||
let new : [int] = []
|
@get(vec, current)
|
||||||
let x : int = @get(vec, current) |> fn(_)
|
|> fn(_)
|
||||||
@insert(new, x)
|
|> @write(_)
|
||||||
|
@write("\n")
|
||||||
|
|
||||||
let y : [int] = map_(vec, fn, current + 1)
|
map_(vec, fn, current + 1)
|
||||||
return @concat(new, y)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun map (vec: [int]) (fn: |int| -> int): [int] = return map_(vec, fn, 0)
|
fun map (vec: [int]) (fn: |int| -> int): void = map_(vec, fn, 0)
|
||||||
|
|
||||||
fun mul10 (x: int): int = return x * 10
|
fun mul10 (x: int): int = x * 10
|
||||||
|
|
||||||
fun main: void = do
|
fun main: void = do
|
||||||
let foo: [int] = [69, 420, 727, 1337, 42069, 69420]
|
let foo: [int] = [69, 420, 727, 1337, 42069, 69420]
|
||||||
map(foo, mul10) |> @write(_)
|
map(foo, mul10)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
-- This is a rewrite of runtime/tuples.ts in itself
|
|
||||||
fun every_ (a : [any]) (b : [any]) (current : int) : bool = do
|
|
||||||
if @len(a) == current
|
|
||||||
then return true
|
|
||||||
else
|
|
||||||
do
|
|
||||||
let aa : any = @get(a, current)
|
|
||||||
let bb : any = @get(b, current)
|
|
||||||
if aa == bb
|
|
||||||
then return every_(a, b, current + 1)
|
|
||||||
else return false end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
fun every (a : [any]) (b : [any]): bool = return every_(a, b, 0)
|
|
||||||
|
|
||||||
fun eqTuples (a : [any]) (b : [any]) : bool =
|
|
||||||
match @len(a) == @len(b) with
|
|
||||||
| true -> return every(a, b)
|
|
||||||
| else return false
|
|
||||||
end
|
|
||||||
|
|
||||||
fun main : void = do
|
|
||||||
let foo : (int, int) = (1, 3)
|
|
||||||
let bar : (int, int) = (2, 1)
|
|
||||||
let baz : (int, int, int) = (1, 3, 1)
|
|
||||||
eqT(foo, bar) |> @write(_)
|
|
||||||
@write("\n")
|
|
||||||
eqT(foo, baz) |> @write(_)
|
|
||||||
@write("\n")
|
|
||||||
eqT(foo, (1, 3)) |> @write(_)
|
|
||||||
end
|
|
|
@ -1,4 +0,0 @@
|
||||||
export function eqTuples(a: any[], b: any[]) {
|
|
||||||
if (a.length !== b.length) return false;
|
|
||||||
return a.every((elem, i) => b[i] === elem);
|
|
||||||
}
|
|
Loading…
Reference in a new issue