Compare commits

..

No commits in common. "b336f2f8473f31f4594d540d723f9fa571850717" and "2b7d974851f763431a70fe7b59728c94cfabddf7" have entirely different histories.

4 changed files with 46 additions and 69 deletions

View file

@ -8,7 +8,7 @@ pub enum LTIRToken {
// DoubleQuote(String),
// TripleQuote(String),
Lambda,
MapsTo,
LambdaBody,
AssignType(String),
AssignValue,
@ -115,11 +115,11 @@ where
region.end += 1;
return Some((region, Ok(LTIRToken::Lambda)));
}
'↦' => {
'.' | '↦' => {
self.chars.next();
self.position += 1;
region.end += 1;
return Some((region, Ok(LTIRToken::MapsTo)));
return Some((region, Ok(LTIRToken::LambdaBody)));
}
'(' => {
self.chars.next();
@ -219,7 +219,7 @@ where
}
LexerState::TypeTerm(s) => {
if *c == '=' || *c == '↦' || *c == ';' {
if *c == '=' || *c == '.' || *c == '↦' || *c == ';' {
if let Some(token) = state.clone().into_token() {
return Some((region, Ok(token)));
}
@ -241,6 +241,7 @@ where
|| *c == ';'
|| *c == '='
|| *c == ':'
|| *c == '.'
|| *c == '↦'
{
// finish the current token

View file

@ -33,17 +33,6 @@ fn compile(
.into_asm(&name.into())
}
/* TODO:
* - Parse Comments
* - write to address resulting from expression
* - `::` -> '.' and allow only
* - Parser error reporting
* - Compiler error reporting
* - Typecheck for LTExpr::Application
* - typecheck & inference for rest
*/
fn main() {
// create virtual machine with 4096 words of memory
let mut vm = tisc::VM::new(0x1000);
@ -62,87 +51,74 @@ fn main() {
"main",
"{
let print-nullterm =
λ{} : < Seq Char ~Ascii ~ machine.Word >
~ < NullTerminatedArray machine.Word >
λ{} : < Seq Char~Ascii~machine::Word >
~ < NullTerminatedArray machine::Word >
{
while(dup) { emit; }
drop;
emit;
};
print-nullterm 'H' 'a' 'l' 'l' 'o' ' ' 'W' 'e' 'l' 't' '!' '\n' '\0';
let fmt-uint =
λx : ~ _2^64 ~ machine.UInt64
let print-uint =
λx : ~ _2^64 ~ machine::UInt64
{
if( x ) {
while( x ) {
i+ '0' (i% x 10);
! x (i/ x 10);
}
print-nullterm {
'\0';
while( x ) {
i+ '0' (i% x 10);
! x (i/ x 10);
}
};
} else {
'0';
emit '0';
};
};
let print-uint = λx: print-nullterm (fmt-uint x) '\0';
let int-neg = λx : ~machine::Int64~machine::Word i+ (bit-neg x) 1;
let int-sign = λx : ~machine::Int64~machine::Word bit-and (bit-shr x 63) 1;
let int-neg = λx : ~ machine.Int64 ~ machine.Word i+ (bit-neg x) 1;
let int-sign = λx : ~ machine.Int64 ~ machine.Word bit-and (bit-shr x 63) 1;
let int-lt = λ{
a : ~ machine.Int64;
b : ~ machine.Int64;
let int-lte = λ{
a : ~machine::Int64~machine::Word;
b : ~machine::Int64~machine::Word;
} int-sign (i- a b);
let int-gt = λ{
a : ~ machine.Int64;
b : ~ machine.Int64;
} int-sign (i- b a);
let int-eq = λ{
a : ~ machine.Int64;
b : ~ machine.Int64;
} if (i- a b) { 0; } else { 1; };
let int-lte = λa: λb: bit-or (int-lt a b) (int-eq a b);
let int-gte = λa: λb: bit-or (int-gt a b) (int-eq a b);
let int-min = λ{
a : ~ machine.Int64;
b : ~ machine.Int64;
} if( int-lt a b ) { a; } else { b; };
let int-max = λ{
a : ~ machine.Int64;
b : ~ machine.Int64;
} if( int-gt a b ) { a; } else { b; };
a : ~machine::Int64~machine::Word;
b : ~machine::Int64~machine::Word;
} if( int-lte b a ) { a; } else { b; };
let vec3i-add = λ{
{ ax:_2^64; ay:_2^64; az:_2^64; } : <Vec3 _2^64~machine.UInt64>;
{ bx:_2^64; by:_2^64; bz:_2^64; } : <Vec3 _2^64~machine.UInt64>;
{ ax:_2^64; ay:_2^64; az:_2^64; } : <Vec3 _2^64~machine::UInt64>;
{ bx:_2^64; by:_2^64; bz:_2^64; } : <Vec3 _2^64~machine::UInt64>;
} {
i+ az bz;
i+ ay by;
i+ ax bx;
};
let fmt-vec3i =
λ{ x:_2^64; y:_2^64; z:_2^64; } : <Vec3 _2^64~machine.UInt64>
let print-vec3i =
λ{ x:_2^64; y:_2^64; z:_2^64; } : <Vec3 _2^64~machine::UInt64>
{
'}';
fmt-uint z; '='; 'z'; ' '; ';';
fmt-uint y; '='; 'y'; ' '; ';';
fmt-uint x; '='; 'x'; '{';
print-nullterm '{' 'x' '=' '\0';
print-uint x;
print-nullterm ';' ' ' 'y' '=' '\0';
print-uint y;
print-nullterm ';' ' ' 'z' '=' '\0';
print-uint z;
print-nullterm '}' '\0';
};
let red-u8rgb
: <Fn <> Color ~ RGB ~ <Vec3 _0,1 ~ _256 ~ machine.UInt64>>
let red-u8
: <Fn <> Color ~ RGB ~ <Vec3 _0,1 ~ _256 ~ machine::UInt64>>
= λ{} { 0; 0; 255; };
let green-u8rgb = λ{} { 0; 255; 0; };
let blue-u8rgb = λ{} { 255; 0; 0; };
let yellow-u8rgb = λ{} { 0; 220; 220; };
let green-u8 = λ{} { 0; 255; 0; };
let blue-u8 = λ{} { 255; 0; 0; };
let yellow-u8 = λ{} { 0; 220; 220; };
print-nullterm (fmt-vec3i (vec3i-add green-u8rgb blue-u8rgb)) '\n' '\0';
print-vec3i (vec3i-add green-u8 blue-u8);
emit '\n';
}"
),
);

View file

@ -309,7 +309,7 @@ where
tokens.next();
let mut variable_bindings = parse_binding_expr(typectx, tokens)?;
let _ = parse_expect(tokens, LTIRToken::MapsTo);
let _ = parse_expect(tokens, LTIRToken::LambdaBody);
let body = parse_expr(typectx, tokens)?;
return Ok(LTExpr::Abstraction {

View file

@ -42,7 +42,7 @@ pub fn init_runtime(linker: &mut Linker) -> Arc<RwLock<Scope>> {
);
linker.add_procedure("dup", tisc::Assembler::new().inst(tisc::VM_Instruction::Dup).build());
linker.add_procedure("drop", tisc::Assembler::new().inst(tisc::VM_Instruction::Drop).build());
linker.add_procedure("drop", tisc::Assembler::new().inst(tisc::VM_Instruction::Accept).build());
linker.add_procedure("emit", tisc::Assembler::new().inst(tisc::VM_Instruction::Emit).build());
linker.add_procedure("accept", tisc::Assembler::new().inst(tisc::VM_Instruction::Accept).build());