Skip to content

Commit 353d0c2

Browse files
committed
RBR development
1 parent 8b7b190 commit 353d0c2

File tree

11 files changed

+232
-196
lines changed

11 files changed

+232
-196
lines changed

dist/easycoder-min.js

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easycoder.js

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,18 +2035,12 @@ const EasyCoder_Core = {
20352035
Test: {
20362036

20372037
compile: compiler => {
2038-
const lino = compiler.getLino();
20392038
compiler.next();
2040-
compiler.addCommand({
2041-
domain: `core`,
2042-
keyword: `test`,
2043-
lino
2044-
});
20452039
return true;
20462040
},
20472041

20482042
run: program => {
2049-
ecTest(); // Calls a test JS module
2043+
console.log(`Test`);
20502044
return program[program.pc].pc + 1;
20512045
}
20522046
},
@@ -2279,10 +2273,10 @@ const EasyCoder_Core = {
22792273
case `stop`:
22802274
return EasyCoder_Core.Stop;
22812275
case `subtract`:
2282-
case `take`:
2276+
case `take`:
22832277
return EasyCoder_Core.Take;
22842278
case `test`:
2285-
return EasyCoder_Core.Test;
2279+
return EasyCoder-Core.Test;
22862280
case `toggle`:
22872281
return EasyCoder_Core.Toggle;
22882282
case `variable`:
@@ -2662,8 +2656,9 @@ const EasyCoder_Core = {
26622656
case `hour`:
26632657
case `minute`:
26642658
case `second`:
2659+
compiler.next();
26652660
var timestamp = null;
2666-
if (compiler.peek() == `of`) {
2661+
if (compiler.tokenIs() == `of`) {
26672662
compiler.next();
26682663
timestamp = compiler.getNextValue();
26692664
}
@@ -2675,8 +2670,9 @@ const EasyCoder_Core = {
26752670
case `day`:
26762671
case `month`:
26772672
if (compiler.nextTokenIs(`number`)) {
2673+
compiler.next();
26782674
var timestamp = null;
2679-
if (compiler.peek() == `of`) {
2675+
if (compiler.tokenIs() == `of`) {
26802676
compiler.next();
26812677
timestamp = compiler.getNextValue();
26822678
}
@@ -2814,11 +2810,11 @@ const EasyCoder_Core = {
28142810
return {
28152811
type: `constant`,
28162812
numeric: true,
2817-
content: new Date(fmtValue).toLocaleTimeString(spec.locale, spec.options)
2813+
content: new Date.UTC(fmtValue).toLocaleTimeString(spec.locale, spec.options)
28182814
};
28192815
case `date`:
28202816
default:
2821-
const date = new Date(fmtValue);
2817+
const date = new Date.UTC(fmtValue);
28222818
const content = (spec.format === `iso`)
28232819
? `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`
28242820
: date.toLocaleDateString(spec.locale, spec.options);
@@ -2851,16 +2847,16 @@ const EasyCoder_Core = {
28512847
content: Math.floor(Date.now())
28522848
};
28532849
case `time`:
2854-
let date = new Date();
2855-
let date2 = new Date();
2850+
let date = new Date()
2851+
let date2 = new Date()
28562852
date2.setHours(0, 0, 0, 0);
28572853
return {
28582854
type: `constant`,
28592855
numeric: true,
28602856
content: Math.floor((date.getTime() - date2.getTime())/1000)
28612857
};
28622858
case `today`:
2863-
date = new Date();
2859+
date = new Date()
28642860
date.setHours(0, 0, 0, 0);
28652861
return {
28662862
type: `constant`,
@@ -3033,47 +3029,47 @@ const EasyCoder_Core = {
30333029
content: string[index]
30343030
};
30353031
case `year`:
3036-
var year = new Date().getFullYear();
3032+
var year = new Date.UTC().getFullYear();
30373033
if (value.timestamp) {
3038-
year = new Date(program.getValue(value.timestamp) * 1000).getFullYear();
3034+
year = new Date.UTC(program.getValue(value.timestamp) * 1000).getFullYear();
30393035
}
30403036
return {
30413037
type: `constant`,
30423038
numeric: true,
30433039
content: year
30443040
};
30453041
case `hour`:
3046-
var hour = new Date().getHours();
3042+
var hour = new Date.UTC().getHours();
30473043
if (value.timestamp) {
3048-
hour = new Date(program.getValue(value.timestamp) * 1000).getHours();
3044+
hour = new Date.UTC(program.getValue(value.timestamp) * 1000).getHours();
30493045
}
30503046
return {
30513047
type: `constant`,
30523048
numeric: true,
30533049
content: hour
30543050
};
30553051
case `minute`:
3056-
var minute = new Date().getMinutes();
3052+
var minute = new Date.UTC().getMinutes();
30573053
if (value.timestamp) {
3058-
minute = new Date(program.getValue(value.timestamp) * 1000).getMinutes();
3054+
minute = new Date.UTC(program.getValue(value.timestamp) * 1000).getMinutes();
30593055
}
30603056
return {
30613057
type: `constant`,
30623058
numeric: true,
30633059
content: minute
30643060
};
30653061
case `second`:
3066-
var second = new Date().getSeconds();
3062+
var second = new Date.UTC().getSeconds();
30673063
if (value.timestamp) {
3068-
second = new Date(program.getValue(value.timestamp) * 1000).getSeconds();
3064+
second = new Date.UTC(program.getValue(value.timestamp) * 1000).getSeconds();
30693065
}
30703066
return {
30713067
type: `constant`,
30723068
numeric: true,
30733069
content: second
30743070
};
30753071
case `monthnumber`:
3076-
var monthNumber = new Date().getMonth();
3072+
var monthNumber = new Date.UTC().getMonth();
30773073
if (value.timestamp) {
30783074
monthNumber = new Date(program.getValue(value.timestamp) * 1000).getMonth();
30793075
}
@@ -3083,9 +3079,9 @@ const EasyCoder_Core = {
30833079
content: monthNumber
30843080
};
30853081
case `daynumber`:
3086-
var dayNumber = new Date().getDate();
3082+
var dayNumber = new Date.UTC().getDate();
30873083
if (value.timestamp) {
3088-
dayNumber = new Date(program.getValue(value.timestamp) * 1000).getDate();
3084+
dayNumber = new Date.UTC(program.getValue(value.timestamp) * 1000).getDate();
30893085
}
30903086
return {
30913087
type: `constant`,
@@ -7695,14 +7691,14 @@ const EasyCoder_Value = {
76957691
}
76967692

76977693
// See if any of the domains can handle it
7698-
const index = compiler.getIndex();
7694+
compiler.mark();
76997695
for (const name of Object.keys(compiler.domain)) {
7700-
compiler.rewindTo(index);
77017696
const handler = compiler.domain[name];
77027697
const code = handler.value.compile(compiler);
77037698
if (code) {
77047699
return code;
77057700
}
7701+
compiler.rewind();
77067702
}
77077703
return null;
77087704
},
@@ -8214,10 +8210,6 @@ const EasyCoder_Compiler = {
82148210
this.index = this.savedMark;
82158211
},
82168212

8217-
rewindTo: function(index) {
8218-
this.index = index;
8219-
},
8220-
82218213
completeHandler: function() {
82228214
const lino = this.getLino();
82238215
// Add a 'goto' to skip the action

js/easycoder/Compile.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ const EasyCoder_Compiler = {
175175
this.index = this.savedMark;
176176
},
177177

178-
rewindTo: function(index) {
179-
this.index = index;
180-
},
181-
182178
completeHandler: function() {
183179
const lino = this.getLino();
184180
// Add a 'goto' to skip the action

js/easycoder/Value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ const EasyCoder_Value = {
5353
}
5454

5555
// See if any of the domains can handle it
56-
const index = compiler.getIndex();
56+
compiler.mark();
5757
for (const name of Object.keys(compiler.domain)) {
58-
compiler.rewindTo(index);
5958
const handler = compiler.domain[name];
6059
const code = handler.value.compile(compiler);
6160
if (code) {
6261
return code;
6362
}
63+
compiler.rewind();
6464
}
6565
return null;
6666
},

py/easycoder.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

py/ec_classes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import sys
2+
13
class FatalError():
24
def __init__(self, compiler, message):
5+
compiler.showWarnings()
36
lino = compiler.tokens[compiler.index].lino + 1
4-
print(f'Line {lino}: {message}')
7+
sys.exit(f'Line {lino}: {message}')
58

69
class RuntimeError:
710
def __init__(self, message):
811
print(f'Runtime Error: {message}')
9-
quit()
1012

1113
class Script:
1214
def __init__(self, source):
@@ -16,4 +18,4 @@ def __init__(self, source):
1618
class Token:
1719
def __init__(self, lino, token):
1820
self.lino = lino
19-
self.token = token
21+
self.token = token

py/ec_compiler.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ec_classes import FatalError
1+
from ec_classes import Token, FatalError
22
from ec_value import Value
33
from ec_condition import Condition
44

@@ -56,6 +56,7 @@ def nextValue(self):
5656

5757
# Get a constant
5858
def getConstant(self, token):
59+
self.index += 1
5960
return self.value.compileConstant(token)
6061

6162
# Get a condition
@@ -116,17 +117,16 @@ def getSymbolRecord(self):
116117
return None
117118

118119
def compileLabel(self, command):
119-
return self.compileSymbol(command, 'label', self.getToken(), False)
120+
return self.compileSymbol(command, self.getToken(), False)
120121

121-
def compileVariable(self, command, type, valueHolder):
122-
return self.compileSymbol(command, type, self.nextToken(), valueHolder)
122+
def compileVariable(self, command, valueHolder):
123+
return self.compileSymbol(command, self.nextToken(), valueHolder)
123124

124-
def compileSymbol(self, command, type, name, valueHolder):
125+
def compileSymbol(self, command, name, valueHolder):
125126
if hasattr(self.symbols, name):
126127
FatalError(self, f'{self.code[self.pc].lino}: Duplicate symbol name "{name}"')
127128
return False
128129
self.symbols[name] = self.getPC()
129-
command['type'] = type
130130
command['isSymbol'] = True
131131
command['used'] = False
132132
command['valueHolder'] = valueHolder
@@ -141,7 +141,7 @@ def compileSymbol(self, command, type, name, valueHolder):
141141
# Compile the current token
142142
def compileToken(self):
143143
token = self.getToken()
144-
#print(token)
144+
# print(token)
145145
if not token:
146146
return False
147147
self.mark()
@@ -156,6 +156,7 @@ def compileToken(self):
156156
result = handler(command)
157157
if result:
158158
return result
159+
else:
159160
self.rewind()
160161
FatalError(self, f'No handler found for "{token}"')
161162
return False
@@ -180,15 +181,17 @@ def compileFrom(self, index, stopOn):
180181
while True:
181182
token = self.tokens[self.index]
182183
keyword = token.token
183-
if keyword != 'else':
184-
if self.compileOne() == True:
185-
if self.index == len(self.tokens) - 1:
186-
return True
187-
token = self.nextToken()
188-
if token in stopOn:
189-
return True
190-
else:
191-
return False
184+
# line = self.script.lines[token.lino]
185+
# print(f'{keyword} - {line}')
186+
# if keyword != 'else':
187+
if self.compileOne() == True:
188+
if self.index == len(self.tokens) - 1:
189+
return True
190+
token = self.nextToken()
191+
if token in stopOn:
192+
return True
193+
else:
194+
return False
192195

193196
def compileFromHere(self, stopOn):
194197
return self.compileFrom(self.getIndex(), stopOn)

0 commit comments

Comments
 (0)