Radicalc  Check-in [cb3c0872e3]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:switching to antlr and c#
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:cb3c0872e327d1af2548ffa993bac6b7cbf70e9bdec9895c42be5fe8be1fd904
User & Date: athaudia 2017-08-23 17:05:17
Context
2017-08-25
03:30
ParseStep done'ish check-in: ed4ffd2b88 user: athaudia tags: trunk
2017-08-23
17:05
switching to antlr and c# check-in: cb3c0872e3 user: athaudia tags: trunk
2017-08-06
17:02
changed to stack allocated temporaries... getting really messy, time for rewrite? check-in: bfe305a909 user: athaudia tags: trunk
Changes

Added src/Program.cs.



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using Antlr4.Runtime;
[assembly: CLSCompliant(false)]

class Listener : RadicalcBaseListener {
	
}

class Program {
	static void Main(String[] args) {
		Console.WriteLine("Yay!");
		var input  = CharStreams.fromPath("test.rcs");
		var lexer  = new RadicalcLexer(input);
		var tokens = new CommonTokenStream(lexer);
		var parser = new RadicalcParser(tokens);
	}
}

Added src/Radicalc.g4.













































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
grammar Radicalc;

NL:          [\n\r]+;
WS:          [ \t] -> skip;
CLASS:       'class';
ELSE:        'else';
ELSIF:       'elsif';
END:         'end';
FUN:         'fun';
IF:          'if';
IS:          'is';
RETURN:      'return';
STRUCT:      'struct';
VAR:         'var';
WHILE:       'while';
COLON:       ':';
COMMA:       ',';
DOT:         '.';
EQUALS:      '=';
PAREN_OPEN:  '(';
PAREN_CLOSE: ')';
BRACK_OPEN:  '[';
BRACK_CLOSE: ']';

MUL:         '*';
DIV:         '/';
PLUS:        '+';
MINUS:       '-';

CMP_LT:      '<';
CMP_LEQ:     '<=';
CMP_GT:      '>';
CMP_GEQ:     '>=';
CMP_EQ:      '==';
CMP_NEQ:     '!=';

AND:         'and';
OR:          'or';
NOT:         'not';

IDENT:       [a-zA-Z][a-zA-Z0-9_]*;
INT_LITERAL: [0-9]+;


top: NL* ((structdef | classdef | fundef | statement) NL)* EOF;

structdef:
    STRUCT IDENT NL (IDENT COLON type NL)* END;

classdef:
    CLASS IDENT (IS IDENT)? NL (IDENT COLON type NL)* END;

fundef:
    FUN IDENT PAREN_OPEN fundef_params? PAREN_CLOSE COLON type? NL
    block END;

fundef_params:
    IDENT COLON type (COMMA IDENT COLON type)*;

block:
    (statement NL)*;

statement: assign_stmt | if_stmt | while_stmt| return_stmt | vardef | expr;

assign_stmt:
    (IDENT | expr DOT IDENT) EQUALS expr; //todo: hmms repeating the . stuff :(

if_stmt:
    IF expr NL block (ELSIF expr NL block)* (ELSE NL block)? END;

while_stmt:
    WHILE expr NL block END;

return_stmt:
    RETURN expr;

vardef:
    VAR IDENT COLON type
|   VAR IDENT EQUALS expr;

expr:
    expr DOT IDENT
|   expr (MUL | DIV) expr
|   expr (PLUS | MINUS) expr
|   expr (CMP_LT | CMP_LEQ | CMP_GT | CMP_GEQ) expr
|   expr (CMP_EQ | CMP_NEQ) expr
|   expr AND expr
|   expr OR expr
|   PAREN_OPEN expr PAREN_CLOSE
|   IDENT PAREN_OPEN funcall_params? PAREN_CLOSE
|   IDENT BRACK_OPEN expr BRACK_CLOSE
|   IDENT
|   INT_LITERAL;

funcall_params:
    expr (COMMA expr)*;


type:
    IDENT
|   BRACK_OPEN type BRACK_CLOSE
|   PAREN_OPEN type (COMMA type)* PAREN_CLOSE; //always atleast one type in there... the return type

Changes to src/build.bat.

1





nearleyc radicalc.ne -o parser.js





|
>
>
>
>
>
1
2
3
4
5
6
REM nearleyc radicalc.ne -o parser.js
REM clang++ main.cpp -fuse-ld=lld -lucrt.lib -o radicalc.exe && radicalc.exe
REM call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
REM cd "c:\dev\radicalc\src"
REM cl main.cpp && main.exe
java -jar \apps\antlr-4.7-complete.jar -o gen -Dlanguage=CSharp Radicalc.g4

Added src/goals.txt.







>
>
>
1
2
3
2 lines of code to draw a circle on screen
download installer/zip, run IDE, write code, press run (no save needed)
make it easy to have compiled plugins that get dynamically loaded

Added src/radicalc.csproj.























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Antlr4.Runtime.Standard" Version="4.7.1" />
  </ItemGroup>

</Project>

Changes to src/radicalc.js.

228
229
230
231
232
233
234























   - temporaries... when?
     - end of current statement, or...
     - as soon as it's not needed anymore
 - difference between variables, llvm-temporaries and radicalc-temporaries?
 - copy before returning?
 - strings?
*/






























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
   - temporaries... when?
     - end of current statement, or...
     - as soon as it's not needed anymore
 - difference between variables, llvm-temporaries and radicalc-temporaries?
 - copy before returning?
 - strings?
*/

/*
	pass-by-value, pass-by-reference, pass reference by value?
	
	structs... some sort of reference semantic is needed,

	could be explicit pointers (allowing value semantics where needed)

	could be every-instance-is-a-reference, not allowing value semantics
	but removing any need for explicit pointer types and dereferencing

	every-instance-is-a-reference, would allow either stack or heap based
	allocation, hidden from user
	might need a copy operator? shallow or deep?

	__chkstk_ms... stack-probe function thingie in llvm ir? no-op function?

	lib.exe can make import libraries from .def (vs studio cmd.exe)
		do myself... ar archive, coff?

	struct == value semantics and class == reference semantics?
	reference counting for class...
*/

Added src/standard-library.txt.























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2d (depends on framebuffer or opengl[compile time switch])
	-draws primitives, sprites, possible blending, etc
3d (depends on opengl)
	-model loading, camera code, possibly scenegraph
audio (hmm... dunno how to handle audio thread...)
	-
file
	-file I/O, buffered, unbuffered, full file at once, etc
fontrender (depends on what?)
	-either draws text straight to a context, or returns pre rendered glyphs...
framebuffer (depends on window)
	-presents a 2d array of pixels
gui (depends on 2d and window)
	-gui toolkit, rendered and drawn from scratch
http (depends on socket, might need ssl...? :( )
	-http server?
	-http client?
	-scgi?
opengl (depends on window)
	-opengl bindings
random
	-PCG? http://www.pcg-random.org/
socket
	-lowlevel network I/O, still platform independent though
window
	-creates windows, handles window and input events
	

Added src/stuff.txt.

































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
semantic versioning of libraries
	-import statement: "import cool_library 2.4"
	only x and y of x.y.z needed
	matching any z, any y >= 4 and only x == 2

coding style
	-compiler has builtin formatter
	-80 columns
	-spaces only (inferior, but, less arguments, less confusion to beginners)

super basic "oop"
	-struct is a value type on stack
	-class is a reference type on heap(reference counted)
	-single-parent inheritance, class only
	  -fields only, as radicalc doesn't have methods or dynamic dispath
	-class has runtime type information, allowing type erasure
	-dynamic casts that use runtime type information to revert type erasure
	-dynamic cast that errors aborts the program; check type beforehand
	-static dispatch only, dynamic dispatch can be done with function pointers
	-NO NULL REFERENCES

rtti/reflection(maybe..., probably not though)
	-type(stuff):Type intrinsic
	-if stuff is class instance, then dynamic type, otherwise static type
	-object(stuff):Object intrinsic
	-Object has an array of members(which is Object as well)
	-Type has an array of members(which is Type as well)
	-Object and Type both are structured the same
	-Object has a Type reference
	-i32(bla:Object) to convert from Object to i32, aborts program if wrong type
	-works with custom types too

arrays
	-value semantics, but backed by heap
	-dynamic
	-type being something like :[i32]

strings
	-value semantics, but backed by heap
	-hmm... mutable or immutable?
	-mutable would make them more like arrays, so less confusion happens

function pointer
	-needed because of keeping oop very simplistic
	-as radicalc doesn't have lambdas or similar, function pointers can
	 only point to statically defined functions
	-type of bla(a:i32,b:i32):string would be :(i32,i32,string)
	-type of bla(a:i32) would be :(i32,void)
	-type of bla() would be :(void)
	-type of bla():[i32] would be :([i32])
	-type of bla(f:(i32,void)) would be :((i32,void), void)

threads
	-a way to create tasks, that then get consumed by a thread pool
	-no data sharing between task threads or between task and main thread
	-thread(task_data, static_data, function)
	-no references(classes) for task_data or static_data allowed
	  -(not even nested inside)
	-task_data is an array of something(struct or POD for example)
	-static_data is a something(struct or POD for example)
	-there might be lots more task_data than threads
	-function has to be pure(compiler will ensure that?)
	-function is of type :(A,B,C) where
	  -A is the type of an element of the task_data array
	  -B is the type of static_data
	  -C can be whatever
	  -thread's return type will be :[C]
	-process:
	  -min(hardware_thread_count, length(task_data)) threads get started
	  -an empty array(results) of length(task_data) and type :[C] gets created
	  -each thread gets a copy of static_data, which is read only
	  -each thread grabs itself an element of the task_data
	    -index that is atomically incremented and read, as sync primitive
	  -each thread calls function with static_data and task_data[idx]
	  -the return of the function gets written into results[idx]
	  -goto grab element of task_data, and repeat until idx >= length(task_data)
	  -when all threads are done, return results

nopes
	-no for loops(for now), extra syntax that is just shorthand in the end