Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target
*-h.*
*_h.*
src/error/*
src/error/*
keywords.yaml
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[package]
name = "Typesharp"
name = "typesharp"
version = "0.1.0"
authors = ["John Bergman <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


#[lib]
#name = "typesharp"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88 changes: 73 additions & 15 deletions src/compiler/typesharp_ast/ast.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
// Typesharp ast
// use crate::{ typesharp_parser::Module };
use super::position::{ Position };
use super::op::*;
use super::types;
use crate::{ compiler::typesharp_lexer::token::Token };

pub struct AST {
// name
n: String,
// // program type
// t: ProgramType,
// // Stack constants
// s: Vec<ASTExpr>,
// // Body
// b: Vec<ASTNode>
name: String,
typ: ProgramType,
body: Vec<ASTStatement>
}

pub trait AnyContext {
fn new(&self) -> Self;
fn getLine() -> u8;
#[derive(Clone, PartialEq, Debug)]
pub struct AnyContext;

impl AnyContext {
fn new(&self) -> AnyContext {
return Self;
}

fn getLine() -> u8 {
0
}
}

pub enum ProgramType {
Expand All @@ -33,13 +39,65 @@ pub enum ProgramType {

pub struct Library;

pub struct Statement<Context> {
pub body: StmtBody,
pub context: Context,
#[derive(Clone, PartialEq, Debug)]
pub struct ASTStatement {
pub body: ASTStateBody,
pub context: AnyContext,
pub pos: Position
}

#[derive(Clone, PartialEq, Debug)]
pub enum StmtBody {
pub enum ASTStateBody {
// expressions, function calls, returns etc should be here.
FuncCall(Signature),
Expression(Expression),
StackVar(Var),
Constant(HeapVar),
AnyConstant(AnyVar),
If(Conditional)
}

// Context and definitions
/// A variable, const, class, etc.
#[derive(Clone, PartialEq, Debug)]
pub struct Var {
pub op: Option<AnyOp>,
pub typ: Option<types::Type>,
pub val: Token,
pub pos: Position,
pub dies: bool,
// pub typ: Type
}

/// Dynamic variable, extends var, which is static.
#[derive(Clone, PartialEq, Debug)]
pub struct HeapVar {
pub var: Var,
pub mangled: bool
}

#[derive(Clone, PartialEq, Debug)]
pub enum AnyVar {
Static(Var),
Heap(HeapVar)
}

/// Functions
#[derive(Clone, PartialEq, Debug)]
pub struct Signature {
pub name: Var,
pub dynamic: bool
}

#[derive(Clone, PartialEq, Debug)]
pub struct Expression {
pub ops: Vec<AnyOp>,
pub v: Vec<AnyVar>
}

#[derive(Clone, PartialEq, Debug)]
pub struct Conditional {
pub condition: Expression,
pub body: Vec<ASTStatement>,
pub fin: Option<Vec<ASTStatement>>
}
2 changes: 1 addition & 1 deletion src/compiler/typesharp_ast/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{error, fmt};

/// These keywords are reserved.
/// If you use these as identifiers you will be yelled at.
#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum KeyWord {
/// Keywords available in all versions of typesharp.
/// Asm, allows use for inline assembly
Expand Down
1 change: 1 addition & 0 deletions src/compiler/typesharp_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod position;
pub mod keyword;
pub mod cursor;
pub mod op;
pub mod types;

pub use self::{
position::{ Position, Span },
Expand Down
19 changes: 14 additions & 5 deletions src/compiler/typesharp_ast/op.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#[derive(Clone, PartialEq, Debug)]
pub enum AnyOp {
BinOp(BinOp),
UnaryOp(UnaryOp),
LogicalOp(LogicalOp),
ComparisonOp(ComparisonOp),
AssignmentOp(AssignmentOp)
}

// Binary Operators
#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum BinOp {
// +
Plus,
Expand Down Expand Up @@ -35,7 +44,7 @@ pub enum BinOp {
UShr,
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum UnaryOp {
// ++x
IncP,
Expand Down Expand Up @@ -65,7 +74,7 @@ pub enum UnaryOp {
Object,
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum LogicalOp {
// x && y
And,
Expand All @@ -77,7 +86,7 @@ pub enum LogicalOp {
Coalasce,
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum ComparisonOp {
Eq,

Expand All @@ -98,7 +107,7 @@ pub enum ComparisonOp {
InstanceOf,
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum AssignmentOp {
// x += y
Add,
Expand Down
1 change: 1 addition & 0 deletions src/compiler/typesharp_ast/types/builtin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// this is used by the parser
1 change: 1 addition & 0 deletions src/compiler/typesharp_ast/types/compiler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// this is used by the parser
23 changes: 22 additions & 1 deletion src/compiler/typesharp_ast/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
/// Types module
// This is a module that handles internal classes and types.
pub mod builtin;
pub mod compiler;
use super::{ ast };

#[derive(Clone, PartialEq, Debug)]
pub struct Type {
pub name: String,
pub statement: TypeDefinition
}

#[derive(Clone, PartialEq, Debug)]
pub struct TypeDefinition {
/// Used for linting and more descriptive errors
pub calculated_defs: Option<Vec<ast::Conditional>>,
pub defs: Option<Vec<ast::AnyVar>>
}

pub use self::{
builtin::*,
compiler::*
};
10 changes: 5 additions & 5 deletions src/compiler/typesharp_lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::{
};


#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub struct Token {
pub kind: TokenKind,
pub span: Span,
pub position: Position
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum Numeric {
/// @reference https://doc.rust-lang.org/beta/reference/types/numeric.html
/// Floating number
Expand Down Expand Up @@ -38,7 +38,7 @@ pub enum Numeric {
Hexadecimal,
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum Comment {
/// Line of the comment
Line(Span),
Expand All @@ -47,7 +47,7 @@ pub enum Comment {
Block(String),
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum Delimiter {
/// Parenthesis, either "(" or ")"
Paren,
Expand All @@ -62,7 +62,7 @@ pub enum Delimiter {
NoDelim,
}

#[derive(Debug)]
#[derive(Clone, PartialEq, Debug)]
pub enum TokenKind {
// Quite literally an accessor,
// EG: "."
Expand Down
1 change: 1 addition & 0 deletions src/compiler/typesharp_parser/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod parser;
File renamed without changes.