summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-07 21:38:46 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-07 21:38:46 -0500
commit0bd0b45ae59e559d88bdc908b8bab8401eb41a30 (patch)
treefef49167817b808d277d632c50d3a95e1d0b75cf
parente874576da9ff59d2234635a1e9b3f47d47c470db (diff)
fixed bug with multiline comments
-rw-r--r--binfile.c12
-rw-r--r--point.toc6
-rw-r--r--tokenizer.c11
3 files changed, 22 insertions, 7 deletions
diff --git a/binfile.c b/binfile.c
index e794e53..8dffb1b 100644
--- a/binfile.c
+++ b/binfile.c
@@ -134,7 +134,8 @@ static inline I64 read_i64(FILE *fp) {
static void write_f32(FILE *fp, F32 f32) {
#if BINFILE_PORTABLE
- /* writes as IEEE 754 32-bit floating-point number, little endian */
+ /* writes as IEEE 754 32-bit floating-point number, the byte order is little endian */
+ /* https://en.wikipedia.org/wiki/Single_precision_floating-point_format */
/* TODO: infinity, NaN */
U32 fraction = 0;
U32 fraction_bit = ((U32)1) << 22;
@@ -173,6 +174,15 @@ static void write_f32(FILE *fp, F32 f32) {
#endif
}
+static F32 read_f32(FILE *fp) {
+ /* TODO: infinity, NaN */
+ U32 u32 = read_u32(fp);
+ U32 sign = (u32 & 0x8000000);
+ U32 exponent = (u32 & 0x7f80000) >> 23;
+ U32 fraction = (u32 & 0x007ffff);
+
+}
+
static void write_f64(FILE *fp, F64 f64) {
#if BINFILE_PORTABLE
U64 fraction = 0;
diff --git a/point.toc b/point.toc
index 27f58f0..b64dde0 100644
--- a/point.toc
+++ b/point.toc
@@ -1,5 +1,9 @@
pkg "point";
+#export f ::= 3.123343234;
+#export g ::= -3.14938244 as f64;
+
+
#export Point ::= struct {
x, y: int;
};
@@ -11,4 +15,4 @@ pkg "point";
mk_point2 ::= fn(x, y:int) p: Point {
p = mk_point(x*x, y*y);
-}; \ No newline at end of file
+};
diff --git a/tokenizer.c b/tokenizer.c
index 901c2ee..97c856f 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -244,7 +244,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
case '*': { /* multi line comment */
tokr_nextchar(t);
int comment_level = 1; /* allow nested multi-line comments */
- while (*t->s) {
+ while (1) {
if (t->s[0] == '*' && t->s[1] == '/') {
t->s += 2;
--comment_level;
@@ -255,13 +255,14 @@ static bool tokenize_string(Tokenizer *t, char *str) {
t->s += 2;
++comment_level;
} else {
+ if (*t->s == 0) {
+ tokenization_err(t, "End of file reached inside multi-line comment.");
+ return false;
+ }
+
tokr_nextchar(t);
}
}
- if (*t->s == 0) {
- tokenization_err(t, "End of file reached inside multi-line comment.");
- abort(); /* there won't be any further errors, of course */
- }
} break;
default:
is_comment = 0;