Skip to content

Commit c656893

Browse files
committed
Implement Hello World compilation support
Example programs which can be compiled can be found in the doc/example folder. A contemporary version of libbsa is required for this program (bscc) to succeed at compilation, as well as to run the compiled Hello World application. Important short term TODOs are improved validation, and a test suite.
0 parents  commit c656893

40 files changed

+3406
-0
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright © 2012 Iain Nicol
2+
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU Affero General Public License as published by
5+
# the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU Affero General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Affero General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
# Build system generated.
17+
dist/
18+
*.hi
19+
*.o
20+
21+
# Outputted by bscc, or required by its output
22+
*.exe
23+
# Nor do we output dlls, but libbsa is a DLL
24+
libbsa*.dll

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Iain Nicol

Bscc/Ast/Plain.ag

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
-- -*- auto-fill-mode: nil; indent-tabs-mode: nil; -*-
2+
3+
PRAGMA datarecords
4+
PRAGMA genlinepragmas
5+
6+
optpragmas
7+
{
8+
-- Copyright © 2012 Iain Nicol
9+
10+
-- This program is free software: you can redistribute it and/or modify
11+
-- it under the terms of the GNU Affero General Public License as published by
12+
-- the Free Software Foundation, either version 3 of the License, or
13+
-- (at your option) any later version.
14+
--
15+
-- This program is distributed in the hope that it will be useful,
16+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
-- GNU Affero General Public License for more details.
19+
--
20+
-- You should have received a copy of the GNU Affero General Public License
21+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
23+
24+
-- (Just below is the module-level documentation. However, we cannot
25+
-- make it a Haddock comment because that would cause compile failures
26+
-- when we are INCLUDEd from another .ag file with its own doc comment.)
27+
28+
-- A plain Abstract syntax tree, such as a parse result.
29+
-- cf. "Bscc.Ast.WithSem".
30+
--
31+
-- Most of the AST datatypes should hopefully be self explanatory.
32+
}
33+
34+
MODULE {Bscc.Ast.Plain}
35+
-- Exports
36+
{
37+
38+
Project (..), -- $Project
39+
Modules, Module (..), -- $Module
40+
Procs, Proc (..), -- $Proc
41+
ArgDefs, ArgDef (..), -- $ArgDef
42+
Type (..), -- $Type
43+
InProcStmts, InProcStmt (..), -- $InProcStmt
44+
Exprs, Expr (..) -- $Expr
45+
}
46+
-- Imports
47+
{
48+
import Bscc.Symbol.Name
49+
}
50+
51+
52+
DERIVING *: Show
53+
54+
{
55+
-- $Project
56+
-- A project is a collection of source files which compile into a single
57+
-- executable. For each program to be compiled, this is the type of
58+
-- the root node.
59+
}
60+
DATA Project
61+
| Project modules: Modules name: SymbolName
62+
63+
TYPE Modules = [Module]
64+
65+
{
66+
-- $Module
67+
-- A module, or a (parsed) source file.
68+
--
69+
-- `BasModule': a \".bas\" file module.
70+
}
71+
DATA Module
72+
| BasModule path: FilePath procs: Procs
73+
74+
TYPE Procs = [Proc]
75+
76+
{
77+
-- $Proc
78+
-- A procedure.
79+
--
80+
-- `Sub': A Sub has no return type.
81+
}
82+
-- We refuse to derive Eq for Proc here; two procedures can have the
83+
-- same name and yet be different procedures in different modules.
84+
DATA Proc
85+
| Sub name: SymbolName argDefs: ArgDefs body: InProcStmts
86+
87+
TYPE ArgDefs = [ArgDef]
88+
89+
{
90+
-- $ArgDef
91+
-- Defines an argument accepted by a `Proc'.
92+
}
93+
DATA ArgDef
94+
| ArgDef name: SymbolName ty: Type
95+
96+
{
97+
-- $Type
98+
-- Represents a data type. Remember, the type represented is a BASIC
99+
-- type, not a Haskell type.
100+
}
101+
DATA Type
102+
| String
103+
104+
TYPE InProcStmts = [InProcStmt]
105+
106+
{
107+
-- $InProcStmt
108+
-- A statement inside a `Proc'.
109+
110+
-- `Call': a Call statement
111+
}
112+
DATA InProcStmt
113+
| Call fn: SymbolName args: Exprs
114+
115+
TYPE Exprs = [Expr]
116+
117+
{
118+
-- $Expr
119+
-- An expression.
120+
}
121+
DATA Expr
122+
| StringLit val: String

Bscc/Ast/WithSem.ag

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
-- -*- auto-fill-mode: nil; indent-tabs-mode: nil; -*-
2+
3+
PRAGMA datarecords
4+
PRAGMA genlinepragmas
5+
6+
optpragmas
7+
{
8+
-- Copyright © 2012 Iain Nicol
9+
10+
-- This program is free software: you can redistribute it and/or modify
11+
-- it under the terms of the GNU Affero General Public License as published by
12+
-- the Free Software Foundation, either version 3 of the License, or
13+
-- (at your option) any later version.
14+
--
15+
-- This program is distributed in the hope that it will be useful,
16+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
-- GNU Affero General Public License for more details.
19+
--
20+
-- You should have received a copy of the GNU Affero General Public License
21+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
23+
24+
-- (Just below is the module-level documentation. However, we cannot
25+
-- make it a Haddock comment because that would cause compile failures
26+
-- when we are INCLUDEd from another .ag file with its own doc comment.)
27+
28+
-- Abstract syntax tree with information from semantic analysis
29+
-- ("Bscc.Sem"), such as type information.
30+
--
31+
-- Most data types and constructors here correspond to those in
32+
-- "Bscc.Ast.Plain", except that this module prefixes such with \"S\"
33+
-- for \"Semantics\".
34+
}
35+
36+
MODULE {Bscc.Ast.WithSem}
37+
-- Exports
38+
{
39+
SProject (..),
40+
SModules, SModule (..),
41+
SProcs, SProc (..),
42+
SProcPrototype (..), -- $SProcPrototype
43+
SArgDefs, SArgDef (..),
44+
SType (..),
45+
SProcRetType, -- $SProcRetType
46+
SInProcStmts, SInProcStmt (..),
47+
SExprs, SExpr (..)
48+
}
49+
-- Imports
50+
{
51+
import Bscc.Symbol.Name (SymbolName)
52+
}
53+
54+
55+
DERIVING *: Show
56+
57+
DATA SProject
58+
| SProject modules: SModules name: SymbolName
59+
60+
TYPE SModules = [SModule]
61+
62+
DATA SModule
63+
| SBasModule path: FilePath procs: SProcs name: SymbolName
64+
65+
TYPE SProcs = [SProc]
66+
67+
DATA SProc
68+
| SProc proto: SProcPrototype body: SInProcStmts
69+
70+
{
71+
-- $SProcPrototype
72+
-- Although the language we compile has no prototypes for functions or
73+
-- other procedures, pretend that it does. Essentially, this structure
74+
-- contains the non-body information about a procedure.
75+
}
76+
DATA SProcPrototype
77+
| SProcPrototype name: SymbolName argDefs: SArgDefs retType: SProcRetType
78+
-- Project and Module where the implementation of
79+
-- the procedure resides.
80+
implProject: SymbolName implModule: SymbolName
81+
82+
-- This lets use {Data.Set.Set SProcPrototype}.
83+
DERIVING SProcPrototype SArgDefs SArgDef SType: Eq, Ord
84+
85+
TYPE SArgDefs = [SArgDef]
86+
87+
DATA SArgDef
88+
| SArgDef name: SymbolName ty: SType
89+
90+
DATA SType
91+
| SString
92+
93+
{
94+
-- $SProcRetType
95+
-- Return type of a procedure. A `Bscc.Ast.Plain.Sub' has `Nothing'; a
96+
-- Function would have the the appropriate @`Just' foo@.
97+
}
98+
TYPE SProcRetType = MAYBE SType
99+
100+
TYPE SInProcStmts = [SInProcStmt]
101+
102+
DATA SInProcStmt
103+
| SCall proc: SProcPrototype args: SExprs
104+
105+
TYPE SExprs = [SExpr]
106+
107+
DATA SExpr
108+
| SStringLit val: String ty: SType

0 commit comments

Comments
 (0)