From 56608dfd2b6a3e30429e58a4db6e8f87c2d72949 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 28 Jun 2019 17:07:03 +0200 Subject: [PATCH] remove #ifdef, #ifndef, etc --- builtin/builtin.v | 3 +++ compiler/parser.v | 36 +++--------------------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/builtin/builtin.v b/builtin/builtin.v index 5107d178c3..6f65c71858 100644 --- a/builtin/builtin.v +++ b/builtin/builtin.v @@ -62,6 +62,8 @@ pub fn malloc(n int) byteptr { if n < 0 { panic('malloc(<0)') } +/* +TODO #ifdef VPLAY if n > 10000 { panic('allocating more than 10 KB is not allowed in the playground') @@ -72,6 +74,7 @@ pub fn malloc(n int) byteptr { println('\n\n\nmalloc($n) total=$total_m') print_backtrace() #endif +*/ ptr := C.malloc(n) if isnil(ptr) { panic('malloc($n) failed') diff --git a/compiler/parser.v b/compiler/parser.v index a0c28a7425..bdab9b4308 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -2627,48 +2627,18 @@ fn (p mut Parser) chash() { p.genln('#include $file') } } - else if is_c_pre(hash) { - // Skip not current OS hack - if hash.starts_with('ifdef') { - os := hash.right(6).trim_space() - // println('ifdef "$os" $p.scanner.line_nr') - if os == 'linux' && p.os != LINUX { - // println('linux ifdef skip') - for p.tok != EOF { - if p.tok == HASH && p.lit.contains('else') || p.lit.contains('endif') { - break - } - // println('skipping') - p.next() - } - } - } - // Move defines on top (like old gdefine) - if hash.contains('define') { - p.cgen.includes << '#$hash' - } - else { - p.genln('#$hash') - } + else if hash.contains('define') { + // Move defines on top + p.cgen.includes << '#$hash' } else { if !p.can_chash { p.error('bad token `#` (embedding C code is no longer supported)') } - //println('HASH!!! $p.file_name $p.scanner.line_nr') - if p.cur_fn.name == '' { - // p.error('# outside of fn') - } p.genln(hash) } } -fn is_c_pre(hash string) bool { - return hash.contains('ifdef') || hash.contains('define') || - hash.contains('endif') || hash.contains('elif') || - hash.contains('ifndef') || (hash.contains('else') && !hash.contains('{')) -} - fn (p mut Parser) if_st(is_expr bool) string { if is_expr { if p.fileis('if_expr') {