Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Typesharp is a typesafe compiled language written in rustlang aiming to memory safe and fast! <br />
You can view the [documentation here](https://github.com/TypeSharp/Documentation).

**NOTICE:** This is a rewrite of the original compiler, and therefore is public. I will not explain how to use, or interact with this source code until I am comfortable releasing the CLI.
**NOTICE:** This is a rewrite of the original compiler, and therefore is public.

## Why Typesharp?

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- This file was auto generated by Typesharp. -->
# Compiler - The TypeSharp Compiler.
- **[typesharp_ast](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_ast)** - Package that contains abstract syntax tree tokens for typesharp.
- **[typesharp_lexer](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_lexer)** - Lexing utilities, help parse tokens in to AST.
- **[typesharp_parser](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_parser)** - The typesharp parser is responsible for "parsing" or identifying tokens after `tokenization`.
- **[typesharp_ast](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_ast)** - Package that contains abstract syntax tree tokens for typesharp.
- **[typesharp_lexer](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_lexer)** - Lexing utilities, help parse tokens in to AST.
- **[typesharp_parser](https://github.com/TypeSharp/Typesharp/tree/master/src/compiler/typesharp_parser)** - The typesharp parser is responsible for "parsing" or identifying tokens after `tokenization`.
2 changes: 1 addition & 1 deletion src/compiler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod typesharp_ast;
pub mod typesharp_lexer;
pub mod typesharp_parser;
pub mod typesharp_parser;
2 changes: 1 addition & 1 deletion src/compiler/typesharp_ast/Readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# typesharp_ast
Package that contains abstract syntax tree tokens for typesharp.
Package that contains abstract syntax tree tokens for typesharp.
146 changes: 39 additions & 107 deletions src/compiler/typesharp_ast/ast.rs
Original file line number Diff line number Diff line change
@@ -1,125 +1,57 @@
// Typesharp ast
// use crate::{ typesharp_parser::Module };
use super::position::{ Position };
use super::op::*;
use super::types;
use crate::{ compiler::typesharp_lexer::token::Token };
use super::util::position;
use super::node::NodeId;
use crate::{ compiler::typesharp_parser as parser };
use crate::compiler::typesharp_lexer::token::Token;

pub struct AST {
name: String,
typ: ProgramType,
body: Vec<ASTStatement>
pub struct Identifier {
pub loc: position::Span,
pub tokens: Option<Vec<Token>>
}

#[derive(Clone, PartialEq, Debug)]
pub struct IContextResource {
pub name: String,
pub contents: Vec<char>
pub enum StatementKind {
Constant(Constant),
Item,
Expression,
Label,
Scope,
TypeDeclaration(types::Type),
Class(Constant)
}

pub trait IContext {
/// Initializes a new context
fn new(&self) -> Self;

// Gets the current resource to be parsed.
fn getCurrentResource(&self) -> Option<IContextResource>;

/// Gets the current AST scope
fn getCurrentScope(&self) -> Option<&ASTStatement>;

/// Gets all AST scopes
fn getScopes(&self) -> Vec<ASTStatement>;

fn nextResource(&self) -> bool;
}

#[derive(Clone, PartialEq, Debug)]
pub struct AnyContext;

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

fn getLine() -> u8 {
0
}
pub enum ExpressionKind {
/// An array of any expression
Array(Vec<Expression>),
/// Private context
Scope,
/// A call to a function or reference to a signature
Function,
/// A method call eg: `foo.bar(a, b)`
///
/// The `Identifier` here represents the Name of the method being called
/// `Vec<Expression>` represents the arguments given to the expression
Method(Identifier, Vec<Expression>, position::Span)
}

pub enum ProgramType {
/// Production
PRO,
/// Library
LIB,
/// External Foreign Function Interface
FFI,
/// Systematic compile, (NOT COMPILED FOR ANY OS, REQUIRES AN OBJMP)
SYS,
/// A driver
INTERNAL
pub struct Constant {
pub id: NodeId,
pub typ: types::Type
}

pub struct Library;

#[derive(Clone, PartialEq, Debug)]
pub struct ASTStatement<Context = IContextResource> {
pub body: ASTStateBody,
pub context: Context,
pub pos: Position
pub struct Statement {
pub id: NodeId,
pub kind: StatementKind,
pub loc: position::Span
}

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

// 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>>
pub id: NodeId,
pub kind: ExpressionKind,
}
91 changes: 0 additions & 91 deletions src/compiler/typesharp_ast/cursor.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::compiler::typesharp_lexer::token::TokenValue;
use std::{error, fmt};

/// These keywords are reserved.
Expand Down Expand Up @@ -318,6 +319,12 @@ impl KeyWord {
}
}

impl TokenValue<String> for KeyWord {
fn get(&self) -> String {
String::from(self.as_str())
}
}

impl From<&'static str> for KeyWord {
fn from(m: &'static str) -> KeyWord {
return KeyWord::from_str(m);
Expand Down Expand Up @@ -345,4 +352,4 @@ impl fmt::Display for KeyWord {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
return fmt::Display::fmt(self.as_str(), f);
}
}
}
13 changes: 6 additions & 7 deletions src/compiler/typesharp_ast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
pub mod ast;
pub mod position;
pub mod keyword;
pub mod cursor;
pub mod op;
pub mod types;
pub mod util;
pub mod node;

pub use self::{
position::{ Position, Span },
keyword::{ KeyWord, KeyWordError },
cursor::{ Cursor }
};
keyword::{KeyWord, KeyWordError},
util::cursor::Cursor,
util::position::{Position, Span},
};
7 changes: 7 additions & 0 deletions src/compiler/typesharp_ast/node/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub struct NodeId {
id: u16
}

pub struct Node {

}
Loading